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"> <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!
Could be too late, I've experienced this issue. In my case, I fixed following this instructions I found in a comment (Thanks Thomas!) in this post
In the 'Developer IT' comment talks about do the same in the app.config. Actually must be in other place. Follow the instructions behind.
An even better solution is to "fix" Microsoft's sgen distribution. First find sgen (for example, on my system for .Net 4.0 it is in "C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools".) Next, create the file sgen.exe.config with the contents:
<configuration> <runtime> <loadFromRemoteSources enabled="true" /> </runtime> </configuration>
The point is, adding loadFromRemoteResources set to true in the sgen app config file allows sgen to properly load files from ClearCase volumes. I know. I've run into the same problem and this is how I fixed it.
Note that at some point Microsoft may create the app config file, so if you do this, first check that the file doesn't already exist, and if it does, check if it still needs the setting.
I realise this is a slightly late reply, but I've just experienced and fixed the exact same issue with Elmah in release mode (and as with the OP, debug mode was working fine).
I fixed my issue by modifying the properties for Elmah.dll in Windows Explorer - from the general tab, I had to click Unblock to convince explorer that the file was indeed safe. After that, release mode publishes worked fine.
Problem may have multiple causes.
Appears to be exposed when loading mixed-mode assemblies (compiled in "ANY_CPU" and "X86" mode.)
I revised the compile option for my main program to "X86" to match the assumed mode of the component DLLs. The problem went away.
It may have something to do with the order in which the dll files are loaded.
User contributions licensed under CC BY-SA 3.0