It seems that you're encountering a System.BadImageFormatException
with HRESULT 0x80131192
when profiling a 32-bit .NET Core application hosted in IIS. This error typically means there's a mismatch between the architecture of the process and the DLL being loaded — for example, trying to load a 64-bit DLL into a 32-bit process or vice versa.
In your case, the crash occurs during classic-style instrumentation via SetILFunctionBody
, which is sensitive to both the architecture and the validity of the IL being injected. Let's do a recap:
- The error typically occurs when a 32-bit process tries to load a 64-bit DLL. Please ensure that both
ClrProfiler32.dll
andHelperAssembly.dll
are explicitly compiled for x86. Even thoughHelperAssembly.dll
is built as AnyCPU, it may still fail in a 32-bit process if it contains native code or platform-specific dependencies. - The crash in your profiler code at:
suggests that the IL being injected might be malformed or incompatible with the method’s metadata. This API is sensitive to both the correctness of the IL and the runtime environment.IfFailRet(m_pICorProfilerInfo->SetILFunctionBody(m_moduleId, m_tkMethod, pBody));
- Your profiler DLLs may rely on specific versions of the Visual C++ Redistributable. If these are missing on the server, the profiler might fail to load properly due to missing dependencies.
You can try:
- In Visual Studio, ensure both
ClrProfiler32.dll
andHelperAssembly.dll
are compiled for x86:
-
Project Properties
→Build
→Platform target
→x86
Guide: https://learn.microsoft.com/en-us/visualstudio/ide/how-to-configure-projects-to-target-platforms
- Install Visual C++ Redistributable (x86)
Download: https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170
- If you're comfortable with deeper diagnostics, you can use tools like:
-
CorFlags
to inspect DLL architecture - Fusion Log Viewer (Fuslogvw.exe) to trace assembly binding issues
These are optional and not required for most setups.
For more information, you can check out these documents below when you have the time:
- BadImageFormatException: https://learn.microsoft.com/en-us/dotnet/api/system.badimageformatexception
- SetILFunctionBody API: https://learn.microsoft.com/en-us/dotnet/framework/unmanaged-api/profiling/icorprofilerinfo-setilfunctionbody-method
- https://stackoverflow.com/questions/62085297/asp-net-core-web-api-load-32bit-library-in-iis-leads-to-badimageformatexception