Search code examples
c#asp.net.netclr-profiling-api

IL Rewrite fails to load .Net DLL


I have built the IL Rewriter for some custom requirement. All it does is

  1. Creates method references for another .Net DLL (newly built custom DLL)
  2. Inject epilogue & prologue for few required methods, they internally call above method references.

Everything works fine with sample Windows form application. However, for the web application, epilogue & prologue are getting injected properly. But, when it gets called, it throws below error -

System.IO.FileLoadException: Loading this assembly would produce a different grant set from other instances. (Exception from HRESULT: 0x80131401)

Somehow, the newly built .Net DLL is not getting loaded for WebApp, while the same is working fine for Windows App.

If I disable IL Rewrite, everything works fine as expected. That means IL Rewrite is causing the error.

Any solution would be much appreciated


Solution

  • I could resolve the issue by setting environment variable

    COMPLUS_LoaderOptimization 
    

    to

    1