Loading This Assembly Would Produce a Different Grant Set from Other Instances
When working with SharePoint, it can happen that, after upgrading to .NET 4.7.1 or higher, an error is thrown stating 'Loading this assembly would produce a different grant set from other instances'.
Explanation
This error is thrown when any 3th party component, running in SharePoint, depends on the legacy Cas (Code Access Security) model. This is easily resolved by updating a registry setting on the SharePoint server(s). You can also resolve this by setting full trust and disabling the Cas legacy model in the web.config files of your applications, but we don't recommend this.
Solution
In the registry of the SharePoint server(s) you have to add/update a key to resolve the issue.
- Start the Windows Registry Editor
- Navigate to the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft.NETFramework
- Add or update the REG_DWORD named LoaderOptimization and set its value to 1
- Do the same for this location: HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft.NETFramework
- Do an IISReset