m4rs-mt / ILGPU

ILGPU JIT Compiler for high-performance .Net GPU programs
http://www.ilgpu.net
Other
1.38k stars 117 forks source link

System.BadImageFormatException in System.Reflection.Metadata.dll #1155

Closed DorloBorlo closed 8 months ago

DorloBorlo commented 9 months ago

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.

MoFtZ commented 9 months ago

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.

DorloBorlo commented 9 months ago

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".

MoFtZ commented 9 months ago

@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 commented 8 months ago

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.