3

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

valiano
  • 16,433
  • 7
  • 64
  • 79
Hitesh
  • 1,067
  • 1
  • 10
  • 27
  • Did you try to google for error itself? E.g. [here](https://stackoverflow.com/q/18168465/1997232) is a question. – Sinatr Nov 15 '17 at 13:30
  • Yes, I have done, but no luck. That is the reason, I have explained my scenario here. – Hitesh Nov 16 '17 at 07:53

1 Answers1

1

I could resolve the issue by setting environment variable

COMPLUS_LoaderOptimization 

to

1
Hitesh
  • 1,067
  • 1
  • 10
  • 27
  • I didn't understand the reason. I have tried multiple times, removing the above environment variable and adding back. It works only if the environment variable is present. – Hitesh Nov 28 '17 at 09:37
  • Are you using this in production code? Having the flag turned on can cause severe slow-down and increase in memory usage. – WooHoo Nov 28 '17 at 13:52
  • Yes, I read the documentation. But, I think, it will have a bad impact in case of multi-AppDomain within a process (w3wp). Otherwise, do you suggest any other better solution? – Hitesh Nov 28 '17 at 16:28