Error loading assembly VS2010

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

I checked that the dll really exists and is correctly copied to the bin folder. I also tried deleting and adding the project link again.

Build failure occurs only when the solution configuration is switched to "Release". It does not crash if the solution configuration is set to Debug.

The only difference between the two configurations (which I know) is shown in the following conversion of Web.config, 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 tried using the Fusion Log Viewer to track assembly binding issues, 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 that for my part there is a fundamental lack of understanding of what exactly is happening here. Any explanation / help is much appreciated!

+4
visual-studio-2010
Jun 08 '10 at 16:23
source share
4 answers

Maybe too late, I ran into this problem. In my case, I fixed the following instructions that I found in the comment (thanks Thomas!) In this post

The Developer IT comment says the same in app.config. In fact, it should be in a different place. Follow the instructions.




An even better solution is to β€œfix” the Microsoft sgen distribution. First, find sgen (for example, on my system for .Net 4.0, it is located in "C: \ Program Files \ Microsoft SDKs \ Windows \ v7.0A \ bin \ NETFX 4.0 Tools".) Then create the sgen.exe file. config with contents:

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

The point is that adding loadFromRemoteResources set to true in the sgen application configuration file allows sgen to load files from ClearCase volumes correctly. I know. I ran into the same problem and that is how I fixed it.

Please note that at some point Microsoft may create an application configuration file, so if you do, first check that the file does not exist yet, and if so, check if it needs to be configured.




+3
Jul 11 2018-12-12T00:
source share

According to the blogs here and here , the reason may be due to an unreliable build. If that were the case, I can’t imagine why this will work in one configuration and not in another, but this is at least something to look at.

+1
Jun 08 '10 at 16:33
source share

I understand this is a bit late answer, but I just tested and fixed the same issue with Elmah in release mode (and, like in OP, debug mode worked fine).

I fixed my problem by changing the properties for Elmah.dll in Windows Explorer. On the General tab, I had to click "Unblock" to convince Explorer that the file is really safe. After that, the release mode publishes perfectly.

+1
Aug 31 2018-11-21T00:
source share

The problem can have several reasons.

Appears to be exposed when loading mixed-mode collections (compiled in "ANY_CPU" and "X86" modes.)

I revised the compilation option for my main β€œX86” program to match the intended mode of the DLL components. The problem is gone.

Perhaps something is related to the order in which the dll files are loaded.

0
May 19 '17 at 20:27
source share



All Articles