VSTS 2010 SGEN : error : Could not load file or assembly (Exception from HRESULT: 0x80131515)

106

I am experiencing a strange issue with VS2010. We use TFS to build our API dlls and we used to reference them in our projects usign a mapped network drive that was fully trusted. We have been working like that for at least two years and everything worked perfectly.

Today, I converted a webapp to vs2010 and when I compile it in Release, it's giving me:

SGEN : error : Could not load file or assembly 'file:///L:\Api\Release API_20100521.1\Release\CS.API.Exceptions.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)

The strange thing is that it's working when it's under the Debug profile...

I tried adding the

<runtime>
   <loadFromRemoteSources enabled="true" />
</runtime>

into app.config and still no luck (See http://social.msdn.microsoft.com/Forums/en/msbuild/thread/d12f6301-85bf-4b9e-8e34-a06398a60df0 and http://msdn.microsoft.com/en-us/library/dd409252(VS.100).aspx)

I am pretty sure that this issue is from visual studio or msbuild, as our code won't run from a network share when in prod because all the referenced dll's are copied into the bin folder.

If anyone has an solution (or just an idea for a search path) please let me know !

Edit : It turns out that it was working in Debug mode because generation of serialisation assemblies was turned Off. As the title say, it's really a SGEN problem since it is this utility that says that the path is not trusted...

visual-studio-2010
msbuild
.net-4.0
tfsbuild
sgen
asked on Stack Overflow Jun 9, 2010 by Developer IT • edited Dec 29, 2016 by jessehouwing

13 Answers

215

I was able to fix this error by finding the assembly DLL in Windows Explorer, right clicking, choosing Properties, and then pressing the "unblock" button. The DLL has a stream that is marking it as an external file - and by clicking unblock you remove that designation.

answered on Stack Overflow Nov 16, 2010 by Slaggg
59

I just had the same/similar issue on a TFS build server where a build was referencing dll's from a network share.

The problems is that the CLR v4 security policy model has changed since previous versions and are not sandboxing assemblies as before.

To fix your issue just find the location of sgen.exe and create a sgen.exe.config in the same folder with following contents:

<configuration>
  <runtime>
    <loadFromRemoteSources enabled="true" />
  </runtime>
</configuration>

sgen.exe is usually at

"C:\Program Files\Microsoft SDKs\Windows\v[current version]\bin\NETFX 4.0 Tools"

You can read about some of the changes around CAS policies in .NET 4.0 in this blogpost: Link

answered on Stack Overflow Aug 4, 2010 by Martin Hyldahl • edited Sep 2, 2014 by Alex Fairchild
23

Had the same problem and the config change didnt work. Only when i set Generate Serialization Assembly to off in the project properties did it work.

answered on Stack Overflow Nov 22, 2010 by Rob • edited Jun 7, 2018 by Rob
6

I had the same error and found my DLL was "blocked". Open up the DLL in explorer, right click -> properties -> press 'Unblock'.

http://cantgrokwontgrok.blogspot.com/2009/10/visual-studio-unknown-build-error.html

answered on Stack Overflow Jun 22, 2011 by Nate Zaugg
3

I had this exact same problem and fixed it by adding the sgen.exe.config under C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools

with this simple config as others have said

<?xml version ="1.0"?>
<configuration>
  <runtime>
    <loadFromRemoteSources enabled="true" />
  </runtime>
</configuration>
answered on Stack Overflow Aug 8, 2011 by Matt Watson
2

For those of you running a 64bit version of the TFS build service, I had to create the config file in the following path:

 C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\x64

And the file contents:

<?xml version ="1.0"?>
<configuration>
<runtime>
    <loadFromRemoteSources enabled="true" />
</runtime>
</configuration>
answered on Stack Overflow Feb 21, 2014 by gmasselli
1

I had the same issue, loaded the assembly in the GAC and worked

answered on Stack Overflow Jul 22, 2010 by gabouy
1

Adding the snippet below to the app.config file worked in my case. I'm Running Windows XP, with VS2010 service pack 1.

<configuration>
  <runtime>
    <loadFromRemoteSources enabled="true" />
  </runtime>
</configuration>
answered on Stack Overflow Apr 19, 2011 by venetia
1

In my case bunch of dlls were blocked.

To unblock all files in folder I used power shell with following command

dir -Path [directory path] -Recurse | Unblock-File
answered on Stack Overflow May 12, 2020 by Daniil Grankin
0

Just as an FYI if you are running Windows 7 the sgen.exe file can be found at:

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools

I had to create a sgen.exe.config and place it there and then this problem went away.

answered on Stack Overflow Jun 28, 2011 by ewahner
0

Neither the unblock nor the config worked for me. What did the trick for me was this tip about caspol. I ran

 %windir%\Microsoft.NET\Framework\v2.0.50727\CasPol.exe -m -ag 1.2 -url file://UncPathName/UncSubPath/* FullTrust

And I was ready to go, not even a VisualStudio restart required.

answered on Stack Overflow Mar 1, 2012 by Yahoo Serious
0

I got a similar problem and I finally got over with it by removing the licenses.licx file in the Properties folder of the solution.

answered on Stack Overflow Aug 11, 2015 by clemchen
0

Just in case like me, Unblock was not a solution, as Unblock does not appear on my dll file properties. Kept looking and ended up closing my solution file and re-opening using the local C: copy instead of network UNC path to project sln file. Was able to publish after going this route.

answered on Stack Overflow Dec 19, 2016 by Taersious

User contributions licensed under CC BY-SA 3.0