.NET Core Profiler Crashing on 32 bit Application Environment

Duraikannu Jeyamani 6 Reputation points
2022-03-24T13:18:47.167+00:00

Hi Team.

I have developed my own .NET core profiler using VS 2019. To load my profiler, I have set the environment entry in the web.config file.
<environmentVariable name="CORECLR_ENABLE_PROFILING" value="1" />
<environmentVariable name="CORECLR_PROFILER" value="{cf0d821e-299b-5307-a3d8-b283c03916dd}" />
<environmentVariable name="CORECLR_PROFILER_PATH_64" value="C:\apps\Publish_3.0\Publish_3.0\ClrProfiler.dll" />
<environmentVariable name="CORECLR_PROFILER_PATH_32" value="C:\apps\Publish_3.0\Publish_3.0\ClrProfiler32.dll" />

I am able to profile a 64 bit .NET core application that is hosted in IIS.
But, When I try to run 32 bit .NET core application got the below exception due to my profiler.
[aspnetcorev2_inprocess.dll] Event Log: 'Application '/LM/W3SVC/5/ROOT' with physical root 'E:\netcoreapp\bin\Release\netcoreapp3.1\publish\' hit unexpected managed exception, exception code = '0xe0434352'. First 30KB characters of captured stdout and stderr logs:
Unhandled exception. System.BadImageFormatException: Bad binary signature. (0x80131192)
at net core azure.Program.Main(String[] args)
End Event Log Message.

Then I have enabled the debug logs in my .NET core profiler. The below line of code has the problem. (il_writer.cpp, 636)

Please help me why this line of code gives the problem.
![186417-capture.jpg][2]
NOTE: My Helperassembly.dll builds in AnyCPU architecture. [2]: /api/attachments/186417-capture.jpg?platform=QnA

Windows development | Internet Information Services
Developer technologies | .NET | .NET Runtime
{count} votes

1 answer

Sort by: Most helpful
  1. Tom Tran (WICLOUD CORPORATION) 260 Reputation points Microsoft External Staff
    2025-06-24T04:26:45.1866667+00:00

    Hi Duraikannu Jeyamani,

    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 and HelperAssembly.dll are explicitly compiled for x86. Even though HelperAssembly.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:
        IfFailRet(m_pICorProfilerInfo->SetILFunctionBody(m_moduleId, m_tkMethod, pBody));
      
      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.
    • 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:

    1. In Visual Studio, ensure both ClrProfiler32.dll and HelperAssembly.dll are compiled for x86:
    • Project PropertiesBuildPlatform targetx86

    Guide: https://learn.microsoft.com/en-us/visualstudio/ide/how-to-configure-projects-to-target-platforms

    1. Install Visual C++ Redistributable (x86)

    Download: https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170

    1. 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:


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.