ILGPU icon indicating copy to clipboard operation
ILGPU copied to clipboard

System.BadImageFormatException in System.Reflection.Metadata.dll

Open DorloBorlo opened this issue 1 year ago • 3 comments

Whenever I run a kernel with ILGPU, these exceptions are thrown:

System.BadImageFormatException HResult=0x8007000B Message=Metadata header too small. Source=System.Reflection.Metadata StackTrace: at System.Reflection.Metadata.MetadataReader.ReadMetadataHeader(BlobReader& memReader, String& versionString) in System.Reflection.Metadata\MetadataReader.cs:line 428

System.BadImageFormatException HResult=0x8007000B Message=Invalid COR20 header signature. Source=System.Reflection.Metadata StackTrace: at System.Reflection.Metadata.MetadataReader.ReadMetadataHeader(BlobReader& memReader, String& versionString) in System.Reflection.Metadata\MetadataReader.cs:line 433

Everything was working fine previously, with the removal of new code added since this issue has occurred not having any effect. The methods still execute as intended, but this exception fills the output. I have checked that all projects are running on x64, as I read that this is the usual cause of a BadImageFormatException.

DorloBorlo avatar Jan 25 '24 02:01 DorloBorlo

hi @DorloBorlo. This is likely a first chance exception that is caught and handled by ILGPU.

ILGPU is trying to load debug symbols, and the call to a standard .NET function is throwing that exception. Shortly afterwords, ILGPU will catch the exception, and continue without issue.

You can turn off loading symbols using DebugSymbolsMode.Disabled.

MoFtZ avatar Jan 25 '24 11:01 MoFtZ

Is DebugSymbolsMode.Disabled set using the context builder? I did the following: Context context = Context.Create( builder => builder.DebugSymbolsMode(DebugSymbolsMode.Disabled)); The exceptions were still thrown, and when checking the context properties, it had DebugSymbolsMode set to "basic". I tried changing the mode to any of the other settings with the same method, but it always ended up as "basic".

DorloBorlo avatar Jan 25 '24 21:01 DorloBorlo

@DorloBorlo Looks like there is a defect with ILGPU v1.5.1 that does not allow disabling the debug symbols. ILGPU is automatically setting the mode to DebugSymbols.Basic when a debugger is attached.

In either case, it is safe to ignore this exception since ILGPU will catch it. In addition, in Release mode, the debug symbols will not be loaded.

In the next release (ILGPU v2.x) this has been fixed with a new DebugConfig() option on Context Builder.

MoFtZ avatar Jan 26 '24 10:01 MoFtZ

Closing this ticket. This is a first-chance exception that is caught internally by ILGPU. It is currently unavoidable in v1.5.1, and v2.x has a fix that will prevent ILGPU from attempting to load the symbols.

MoFtZ avatar Mar 01 '24 10:03 MoFtZ