30

We have SharePoint 2013 Servers that were patched with windows updates and since then we are receiving the following error. We have restarted the servers, removed the windows updates manually and then restarted the servers, restored to a copy of windows server before the windows update but the error is persisting. We have also removed the temporary files from Windows directory and nothing is helping.

I have attached a screenshot of the Windows Updates that were applied to our servers overnightenter image description here

 Loading this assembly would produce a different grant set from other     instances. (Exception from HRESULT: 0x80131401) 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

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

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 


[FileLoadException: Loading this assembly would produce a different grant set from other instances. (Exception from HRESULT: 0x80131401)]
System.Linq.Enumerable.Any(IEnumerable`1 source) +0
       System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromAssemblyCollection(IEnumerable`1 assemblies, Boolean buildingFromCache) +210
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +98
System.Web.Compilation.BuildManager.ExecutePreAppStart() +139
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +1005

[HttpException (0x80004005): Loading this assembly would produce a different grant set from other instances. (Exception from HRESULT: 0x80131401)]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +646
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +779


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET    Version:4.0.30319.36366 
Baahubali
  • 4,604
  • 6
  • 33
  • 72

4 Answers4

62

I ran into the same exception when developing on Sitecore, and an iisreset cleared the issue.

nickwesselman
  • 6,845
  • 2
  • 27
  • 46
  • 15
    We just recycled the app pool, problem fixed. Not even using sharepoint, just a boring asp.net app. – Rocklan Mar 27 '19 at 04:00
  • Issue on SP2010 was fixed by iisreset – Gary Henshall Apr 17 '19 at 08:48
  • For me this has effect, but does not solve the issue. I've got 2 APIs. When either 1 of them is approached first, they work. When then the other API is used, this exception is thrown. So they both work, but not simultaneously. – Mike de Klerk Dec 11 '19 at 07:09
  • 3
    iisreset worked for me. Does anybody know what would cause this issue? – amassani Feb 02 '20 at 19:27
  • I had to restart IIS Express to resolve this, no clue why it started occurring though! – Ben D Mar 09 '21 at 15:57
  • Thank you for the tip. I had this problem after updating lots of NuGet packages for an ASP.Net MVC project and uploading it to the server. I opened IIS manager and clicked Restart under "Manage Server" to solve it. "Restart" under "Manage Website" did not work. – Hong Aug 20 '21 at 18:22
6

The solution appears to be:

Create a new registry DWORD value called LoaderOptimization and give it the value 1 within the key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework”.

Further reading:

http://blog.bugrapostaci.com/2017/02/08/loading-this-assembly-would-produce-a-different-grant-set-from-other-instances-exception-from-hresult-0x80131401/

https://social.technet.microsoft.com/Forums/en-US/5db05238-3c12-4e7e-af95-ca56545f0721/loading-this-assembly-would-produce-a-different-grant-set-from-other-instances?forum=sharepointgeneral

Soleil
  • 6,404
  • 5
  • 41
  • 61
MarkPflug
  • 28,292
  • 8
  • 46
  • 54
  • This worked for me. Out of interest did you use a 32 or 64 bit DWORD? – Michael Hancock Apr 06 '18 at 12:57
  • 5
    I didn't use this. I merely resurrected an answer that was buried by some overzealous stackoverflow moderators (at a certain rep level you can see the deleted answers). I forwarded the deleted answer to someone in my org who was having the problem. – MarkPflug Apr 06 '18 at 20:15
  • 3
    FYI the linked article actually says *not* to do this. – nickwesselman Jul 09 '18 at 16:35
  • @nickwesselman the first article says not to for that particular product (SCOM). The second technet forum link says to for a different scenario to the first. So it may still be applicable to your particular situation. – Shiv Feb 01 '21 at 22:37
  • Solved it (VS2022, WPF app, .net7). Why on earth this problem appeared ? I was developing the app for years without any problem. I was not using SharePoint. – Soleil Apr 23 '23 at 01:01
1

I was able to solve this issue by going into Bindings -> Edit, then removing "localhost" as the Host Name of the site. Worked after that.

Bilal
  • 81
  • 1
  • 3
-2

Try disable "Remote Desktop" if it is enabled (example)

After running the command isreset and changing registry,my problem solved.

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.4075.0

HAJJAJ
  • 3,667
  • 14
  • 42
  • 70
velixor
  • 1
  • 1