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] Project compiling failing with System.BadImageFormatException #1882

Closed
DjArt opened this issue Mar 22, 2022 · 2 comments
Closed

Comments

@DjArt
Copy link

DjArt commented Mar 22, 2022

ILCompiler 7.0.0-preview.2.22152.2 produced this error:

Generating compatible native code. To optimize for size or speed, visit https://aka.ms/OptimizeCoreRT
"C:\Users\user\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\tools\\ilc" @"obj\Release\net6.0-windows10.0.17763\win-x64\native\myprog.ilc.rsp"
myprog.Program.<>c.<Main>b__0_0(HostBuilderContext,IServiceCollection): Using member 'Microsoft.Extensions.Configuration.ConfigurationBinder.Get<SettingsModel>(IConfiguration)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. In case the type is non-primitive, the trimmer cannot statically analyze the object's type so its members may be trimmed.
Format of the executable (.exe) or library (.dll) is invalid.
System.BadImageFormatException: Format of the executable (.exe) or library (.dll) is invalid.
   at System.Reflection.Metadata.Ecma335.CustomAttributeDecoder`1.DecodeFixedArgumentType(BlobReader& signatureReader, Boolean isElementType)
   at System.Reflection.Metadata.Ecma335.CustomAttributeDecoder`1.DecodeFixedArguments(BlobReader& signatureReader, BlobReader& valueReader, Int32 count)
   at System.Reflection.Metadata.Ecma335.CustomAttributeDecoder`1.DecodeValue(EntityHandle constructor, BlobHandle value)
   at ILCompiler.DependencyAnalysis.CustomAttributeBasedDependencyAlgorithm.AddDependenciesDueToCustomAttributes(DependencyList& dependencies, NodeFactory factory, EcmaModule module, CustomAttributeHandleCollection attributeHandles)
   at ILCompiler.DependencyAnalysis.CustomAttributeBasedDependencyAlgorithm.AddDependenciesDueToCustomAttributes(DependencyList& dependencies, NodeFactory factory, EcmaMethod method)
   at ILCompiler.DependencyAnalysis.MethodMetadataNode.GetStaticDependencies(NodeFactory factory)
   at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.GetStaticDependenciesImpl(DependencyNodeCore`1 node)
   at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.GetStaticDependencies(DependencyNodeCore`1 node)
   at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ProcessMarkStack()
   at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ComputeMarkedNodes()
   at ILCompiler.ILScanner.ILCompiler.IILScanner.Scan()
   at ILCompiler.Program.Run(String[] args)
   at ILCompiler.Program.Main(String[] args)

ILCompiler 6.0.0-rc.1.21420.1 produced this:

Generating compatible native code. To optimize for size or speed, visit https://aka.ms/OptimizeCoreRT
"C:\Users\user\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\6.0.0-rc.1.21420.1\tools\ilc" @"obj\Release\net6.0-windows10.0.17763\win-x64\native\myprog.ilc.rsp"
Assembly 'Microsoft.Extensions.DependencyInjection.Abstractions' produced AOT analysis warnings.
Format of the executable (.exe) or library (.dll) is invalid.
System.BadImageFormatException: Format of the executable (.exe) or library (.dll) is invalid.
   at System.Reflection.Metadata.Ecma335.CustomAttributeDecoder`1.DecodeFixedArgumentType(BlobReader& signatureReader, Boolean isElementType) in System.Reflection.Metadata.dll:token 0x60009a4+0x169
   at System.Reflection.Metadata.Ecma335.CustomAttributeDecoder`1.DecodeFixedArguments(BlobReader& signatureReader, BlobReader& valueReader, Int32 count) in System.Reflection.Metadata.dll:token 0x60009a2+0x14
   at System.Reflection.Metadata.Ecma335.CustomAttributeDecoder`1.DecodeValue(EntityHandle constructor, BlobHandle value) in System.Reflection.Metadata.dll:token 0x60009a1+0xb5
   at ILCompiler.DependencyAnalysis.CustomAttributeBasedDependencyAlgorithm.AddDependenciesDueToCustomAttributes(DependencyList& dependencies, NodeFactory factory, EcmaModule module, CustomAttributeHandleCollection attributeHandles) in ILCompiler.Compiler.dll:token 0x6000729+0x0
   at ILCompiler.DependencyAnalysis.CustomAttributeBasedDependencyAlgorithm.AddDependenciesDueToCustomAttributes(DependencyList& dependencies, NodeFactory factory, EcmaMethod method) in ILCompiler.Compiler.dll:token 0x6000725+0x140
   at ILCompiler.DependencyAnalysis.MethodMetadataNode.GetStaticDependencies(NodeFactory factory) in ILCompiler.Compiler.dll:token 0x6000773+0x0
   at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.GetStaticDependenciesImpl(DependencyNodeCore`1 node) in ILCompiler.DependencyAnalysisFramework.dll:token 0x6000038+0x0
   at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.GetStaticDependencies(DependencyNodeCore`1 node) in ILCompiler.DependencyAnalysisFramework.dll:token 0x6000039+0x8
   at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ProcessMarkStack() in ILCompiler.DependencyAnalysisFramework.dll:token 0x600003a+0x2c
   at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ComputeMarkedNodes() in ILCompiler.DependencyAnalysisFramework.dll:token 0x600003b+0x19
   at ILCompiler.ILScanner.ILCompiler.IILScanner.Scan() in ILCompiler.Compiler.dll:token 0x60002ee+0x0
   at ILCompiler.Program.Run(String[] args) in ilc.dll:token 0x600010f+0xb3e
   at ILCompiler.Program.Main(String[] args) in ilc.dll:token 0x6000115+0x5
@MichalStrehovsky
Copy link
Member

Do you have a method with a generic attribute on it? They don't work with NativeAOT.

This sounds like dotnet/runtime#58073.

@MichalStrehovsky
Copy link
Member

Going to assume it's a generic attribute. System.Reflection.Metadata thinks the custom attribute blob is corrupt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants