Troubleshoot exceptions in ASP.NET applications

Troubleshooting steps when there is an exception while monitoring ASP .NET applications.

Use Case:

Sometimes, you may receive the exception "Loading this assembly would produce a different grant set from other instances.", while running the APM Insight .NET agent in your ASP .NET applications.
This is because, by design, the agent works by modifying the IL code at runtime. Hence, it is required to run the application in full trust environments and in single domain mode. 

Solution
Follow the below steps to resolve the exception:
  1. Add   <trust level =”Full”/>    under the block in the application web.config file. In most cases, this will resolve the issue. If the issue is not resolved with this step, proceed to the next step.
  2. Set loader optimization to single domain mode. [Note: This second step is not recommended for Share Point applications.]
    • For 64 bit applications:
      1. Open Registry Editor and navigate to the below path, "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework" 
      2. Create a new registry DWORD value called "LoaderOptimization" and set the value as 1.
    • For 32 bit applications:
      1. Open Registry Editor and navigate to the below path, "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework"
      2. Create a new registry DWORD value called "LoaderOptimization" and set the value as 1.
  3. Reset IIS and access your application.