views:

212

answers:

2

I am getting the following error when I try to build an ASP.NET 4 project in Visual Studio 2010: "Could not load file or assembly 'file:///C:\Dev\project\trunk\bin\Elmah.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)".

I have verified that the dll does, in fact, exist, and is getting copied to the bin folder correctly. I have also tried removing and then re-adding the reference to the project.

The build only fails when I switch the Solution Configuration to "Release". It does not fail when the Solution Configuration is set to "Debug".

The only difference between the two configurations (that I know of) is shown in the following Web.config transform, Web.Release.config:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"&gt;
    <connectionStrings>
      <add name="SqlServer" connectionString="" providerName="System.Data.SqlClient" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
    </connectionStrings>
    <system.web>
        <compilation xdt:Transform="RemoveAttributes(debug)" />
        <customErrors mode="On" xdt:Transform="Replace">
            <error statusCode="404" redirect="lost.htm" />
            <error statusCode="500" redirect="uhoh.htm" />
        </customErrors>
    </system.web>
</configuration>

I have tried using Fusion Log Viewer to track down the assembly binding issue, but it looks like it is finding and loading the assembly correctly. Here is the log:

*** Assembly Binder Log Entry  (6/8/2010 @ 10:01:54 AM) ***

The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\sgen.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = User
LOG: Where-ref bind. Location = C:\Dev\project\trunk\bin\Elmah.dll
LOG: Appbase = file:///c:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/bin/NETFX 4.0 Tools/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = sgen.exe
Calling assembly : (Unknown).
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: No application configuration file found.
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Attempting download of new URL file:///C:/Dev/project/trunk/bin/Elmah.dll.
LOG: Assembly download was successful. Attempting setup of file: C:\Dev\project\trunk\bin\Elmah.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: Elmah, Version=1.1.11517.0, Culture=neutral, PublicKeyToken=null
LOG: Re-apply policy for where-ref bind.
LOG: Where-ref bind Codebase does not match what is found in default context. Keep the result in LoadFrom context.
LOG: Binding succeeds. Returns assembly from C:\Dev\project\trunk\bin\Elmah.dll.
LOG: Assembly is loaded in LoadFrom load context.

I feel like there is a fundamental lack of understanding on my part as to what exactly is going on here. Any explanation/help is much appreciated!

+1  A: 

According to blogs here and here, the cause might be related to an untrusted assembly. If this were the case, I can't imagine why it would work in one configuration and not the other, but it's at least something to look at.

ladenedge
Yeah, I saw those posts, but that doesn't seem to be the problem. I've tried re-downloading the Elmah dlls and walking through the whole process, but they don't seem to be "blocked". Although one of the people who commented on the first blog (http://cantgrokwontgrok.blogspot.com/2009/10/visual-studio-unknown-build-error.html?showComment=1264721898924#c2352316767675997414) seemed to be experiencing the exact same problem.
Nate
+1  A: 

Hi !

I am experiencing the same 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, has our code won't run from a network share because all the referenced dll's are copied into the bin folder.

If anyone has an solution (or just an idea) please let us know !

Developer IT