Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NativeAOT] LINK : fatal error LNK1123 #1436

Closed
dellamonica opened this issue Aug 20, 2021 · 11 comments
Closed

[NativeAOT] LINK : fatal error LNK1123 #1436

dellamonica opened this issue Aug 20, 2021 · 11 comments
Labels
area-NativeAOT-coreclr .NET runtime optimized for ahead of time compilation

Comments

@dellamonica
Copy link

I'm getting the following error when trying to compile a project with the NativeAOT compiler.

  • This project used to compile normally before, and there doesn't seem to be any significant difference in the code.
  • I have installed VS 2022 preview and uninstalled 2019 - it might have something to do with the problem.
CVTRES : fatal error CVT1103: cannot read file [........csproj]
LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt [.......csproj]
....\.nuget\packages\microsoft.dotnet.ilcompiler\6.0.0-rc.1.21420.1\build\Microsoft.NETCore.Native.targets(352,5): error MSB3073: The command "link  @"obj\x64\Release\net6.0\win-x64\native\link.rsp"" exited with code 1123. [..........csproj]

Any suggestions?

@jkotas
Copy link
Member

jkotas commented Aug 20, 2021

Are you able to build hello world sample on your machine? https://github.com/dotnet/runtimelab/tree/feature/NativeAOT/samples/HelloWorld

@jkotas jkotas added the area-NativeAOT-coreclr .NET runtime optimized for ahead of time compilation label Aug 20, 2021
@dellamonica
Copy link
Author

dellamonica commented Aug 20, 2021 via email

@dellamonica
Copy link
Author

@jkotas, "Hello World" worked.
Interestingly I could compile my code on linux (however, I had to install additional packages following some older comment of yours dotnet/corert#5742 (comment)).

@jkotas
Copy link
Member

jkotas commented Aug 23, 2021

Do you see obj\Release\net5.0\win-x64\native\<your app name>.res file in your directory? There is something wrong with this file. Would you mind to share it here or over email? Also, it would help if you can share obj\Release\net5.0\win-x64\<your app name>.dll that this file is generate from.

If you would like to debug it yourself, I think that there is a problem DumpNativeResources task (https://github.com/dotnet/runtimelab/blob/feature/NativeAOT/src/coreclr/tools/aot/ILCompiler.Build.Tasks/DumpNativeResources.cs , called from https://github.com/dotnet/runtimelab/blob/feature/NativeAOT/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets#L307 ). The task is probably generating a resource file that the VS2022 linker fails to parse for some reason.

@dellamonica
Copy link
Author

Your question prompted me to look into the obj path and after not finding any .res file there I decided to delete everything in obj and bin and re-run the dotnet publish command. It worked! So I must assume that there was some garbage in there that confused the linker. Is there an ILC option to do a clean build every time?

It's still not clear why the garbage/bad files (if it was in fact that) were generated and if has to do with VS2022 replacing 2019. It could be some inconsistency between a previous run using the 2019 toolchain and a later run of the publish command with the 2022 tooling. It might not be worthy to investigate it further though. Thanks for your help.

(BTW, I had run Clean Solution from VS2022 before filing this issue, so I did not expect the obj/ bin/ folders to have any corruption.)

@jkotas
Copy link
Member

jkotas commented Aug 23, 2021

Is there an ILC option to do a clean build every time?

There is not one. It is a general .NET SDK problem, not specific for ILC. It is a good idea to delete obj and bin directories after major toolset update.

@kant2002
Copy link
Contributor

kant2002 commented Sep 8, 2021

@dellamonica anything actionable left on your issue here? It seems to be it can be closed.

@dellamonica
Copy link
Author

dellamonica commented Sep 8, 2021 via email

@jkotas jkotas closed this as completed Sep 8, 2021
@ductai230894
Copy link

I have some problem, I clear all in obj folder of project ,It working fine again

@VAllens
Copy link

VAllens commented Mar 1, 2023

I have some problem, I clear all in obj folder of project ,It working fine again

Me too...
I encountered this problem during Gitlab CI running.

.NET SDK 7.0.103

@dooann
Copy link

dooann commented Nov 4, 2023

I have some problem, I clear all in obj folder of project ,It working fine again

You saved my day :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-NativeAOT-coreclr .NET runtime optimized for ahead of time compilation
Projects
None yet
Development

No branches or pull requests

6 participants