Tuesday, November 05, 2013

Microsoft .NET Framework Issue

I came across a frustrating issue, the other day.

I needed to upgrade a .NET Framework 2.0 project to .NET 4.0 due to some component features.  That went fine, everything compiled, but found out there was some issues, so in order to prevent issues in production, I had to revert back to .NET Framework 2.0.

After publishing the assemblies to the shared network drive, I was getting the following error.

System.IO.FileLoadException: Could not load file or assembly xxxxxxxxx or one of its dependencies. Operation is not supported.
(Exception from HRESULT: 0x80131515) ---> System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly
to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this
load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See
http://go.microsoft.com/fwlink/?LinkId=155569 for more information.

Unfortunately, this led me down the wrong path.  The link states to add a "loadFromRemoteSources" in your app.config file.  This is wrong in my case, as I knew this was a .NET 4.0 feature, not a 2.0 feature.  So I didn't even bother with it.

Well after doing some tests, I found that when upgrading from .NET 2.0 to .NET 4.0 it created an app.config file for me - which I didn't want - and didn't remove it when reverting back.  So the Runtime Compiler must have saw the app.config for a .NET 4.0 project and assumed the wrong thing.  The solution was to delete the app.config file and everything was happy.

No comments: