VSTS2010SGEN: error: 无法加载文件或程序集(来自 HRESULT T: 0x80131515的异常)

我正在经历一个奇怪的问题与 VS2010。我们使用 TFS 来构建我们的 API dlls,并且在我们的项目中使用一个完全可信的映射网络驱动器来引用它们。我们已经这样工作了至少两年,一切都很完美。

今天,我把一个 webapp 转换成了 vs2010,当我在发布版中编译它的时候,它给了我:

错误: 无法加载文件或 汇编文件:///L: Api 发行版 API _ 20100521.1版本 CS.API.Exceptions.dll’或其依赖项之一 不支持。(例外 结果: 0x80131515)

奇怪的是,它在调试配置文件下工作..。

我试着加上

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

进入 app.config,仍然没有运气(见 http://social.msdn.microsoft.com/Forums/en/msbuild/thread/d12f6301-85bf-4b9e-8e34-a06398a60df0http://msdn.microsoft.com/en-us/library/dd409252(VS.100).aspx)

我非常肯定这个问题来自 Visual Studio 或 msbuild,因为我们的代码在 prod 时不会从网络共享运行,因为所有引用的 dll 都被复制到 bin 文件夹中。

如果任何人有一个解决方案(或只是一个搜索路径的想法) ,请让我知道!

编辑: 原来它是在调试模式下工作的,因为序列化程序集的生成被关闭了。正如标题所说,这确实是一个 SGEN 问题,因为正是这个实用程序说明路径是不可信的..。

65520 次浏览

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

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

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.

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.

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>

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

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.

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>

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.

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>

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.

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.

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