We encountered this error when running the OutDoc solution on OutSystems. Based on some research this is a common issue across multiple platforms e.g. SharePoint and not just on OutSystems.
To resolve do the following:
Create a new registry DWORD value called LoaderOptimization and give it the value 1 within the key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework”
After the change you should do an IISRESET but preferably a server restart