ASP.Net build error - assembly not referenced - asp.net

I am getting a build error when I attempt to build my asp.net application. The error is:
The type 'MediCare.Framework.Authentication.IUserAuthenticate' is defined in an assembly that is not referenced. You must add a reference to assembly 'MediCare.Framework, Version=1.0.1.95, Culture=neutral, PublicKeyToken=1999fa3c42b9'.
I can see the class in the library which is in the references folder. How do I debug this issue?
My intention is to point the references folder to the library source code's bin directory (since the pdb file is lcoated there and any updates to the library will reflect in the application). However, when I point the references folder to the bin directory of the source code, I get the error message above.
Update The application was originally developed in VS 2008 and I am modifying it in 2010. I think I am confused about where the GAC assemblies would be, if I am using VS 2010 (2.0 framework location or 4.0 framework location) ? .NET 4.0 has a new GAC, why?
Update (06-26-2012)
The file in the GAC ("C:\Windows\assembly\") has been deleted. But this error is still occuring.

This could possibly be caused by version inconsistencies. Meaning, in order to fix this, I would do a complete clean build of your assemblies (and also an assemblies that might be nested inside an assembly). Just go out cold and do a new build on all assemblies. That should work.

Go into windows explorer, right click on the DLL file that your project is using that contains this class, and look at the version tab. Make sure version number matches what you see in the error message. My guess is that it won't.
If it does match, then check the GAC and make sure there isn't a different version of the DLL there that it could be picking up. To do that, go to windows explorer, and navigate to c:\windows\assembly. See if that assembly is in there with a different version number. If it is, you may need to delete it from the GAC (use caution though because other apps may depend on it being there).

Related

Visual Studio 2017 won't compile my ASP.NET web project, saying "could not load file or assembly" for a library that is definitely being referenced

Current Situation:
I have an ASP.NET web project. (Framework Version: .NET Framework 4.5.2)
One developer here is able to compile it and run it fine in Visual Studio 2017.
I cannot, I get the "could not load file or assembly" error for a reference that is in my list of references.
Screenshots:
Error:
Bin Folder:
Web.config Potential Relevant Sections:
DevExpress Licenses File:
DevExpress Library File's Details:
Things I've Tried:
Clean Solution & Rebuild Solution
Deleted solution locally and clean get of solution from source control
Clearing out my temp directory
Opening the project in Visual Studio 2015
Having the developer zip up his local copy of the solution / project and sending it to me (When I ran his copy locally I continued to get the same error.)
Re-adding the existing library it's complaining about
Manually deleting and re-adding all the libraries in my BIN folder
Messing with the license file, web.config, and assembly references in code (including adjusting the version numbers because for some reason the version number is 17.2.5.0 anywhere it's referenced in the project, but the file's Details actually says it's 17.2.9.0?)
Smashing my face into my keyboard...
...Always the same error.
Additional Information
Other developers run into the same exact error under the same conditions as me, only my one developer who's been working in this project can build it fine
I just noticed that on a new copy of the work project, my references window is showing 2 of the same reference to the DevExpress.Data library (one in the GAC and one in the BIN) but when I try re-adding the reference to my project, the one in the BIN disappears from my references window:

System.Net.Http.Formatting missing in some machines(xml) but works in other (dll)

The best way to include System.Net.Http.Formatting might be through nuget. But when a developer sees it in the default Assemblies section in reference manager then they just add it, expecting all developers to have it installed by default. But to our surprise, some developer machines did not have this dll.
All developers have the correct folder where this dlls is found
"C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies\"
Some developers just have XML files and others have dlls in it, even though the file names are the same.
Why are dlls missing in some machines?
Sometimes it is really an issue while finding the missing dlls. Better approach is to clean the nuget cache and folder both and restoring nuget packages again would resolve this issue.
System.Net.Http.Formatting mystery resolved
System.Net.Http.Formatting won't be installed by default along with asp.net. If it appeared in one developer machine, then it could be because some other projects in the VS might have used a nuget to pull it in. This developer without knowing this gives a manual reference to this dll in a new/different project. To him/her everything works fine.
When another/new developer comes and tries to do the same in his/her machine, before reaching this particular project(which pulled in System.Net.Http.Formatting through nuget), the developer gets error(from the manually entered dll project by the previous developer mentioned above). That explains why the dll is missing in his/her machine.
But why is XML file present then?
Becuase the package folder was stored in tfs/git from the first developer machine(who successfully had the dll through nuget). And tfs/git ignored the dll when checked-in.

.Net picking wrong referenced assembly version

I just copied an existing project to a brand new machine to start developing on it and have run into a problem with the version of one of my referenced assemblies (a telerik DLL as it happens).
The project originally referenced an older version of the assembly (lets call it v1.0.0.0). My new machine has the latest version of the assembly installed, so I thought I'd updated it (lets call the new version v2.0.0.0).
Now here's the problem: If I copy the old v1.0.0.0 dll to the project folder and add it as a reference, the web site launches without a problem. If I delete that reference (and also delete the old DLL from my system) and add the new version (v2.0.0.0), the page shows the following exception:
Could not load file or assembly
'XXXXXX, Version=1.0.0.0,
Culture=neutral,
PublicKeyToken=121fae78165ba3d4' or
one of its dependencies. The located
assembly's manifest definition does
not match the assembly reference.
(Exception from HRESULT: 0x80131040)
Clearly, the code is looking for the out of date version and can't find it. But why?
I greped the solution folder for that version number and couldn't find a single reference. I double checked the text of the .csproj file and found the version correctly shows the latest version and the HintPath correctly shows the path to the new DLL. Furthermore, because I didn't install the old DLL on the system it doesn't show up in my GAC (though v2.0.0.0 does, as expected).
I then enabled the fusion log viewer to try to figure out why it's looking for that old version, but no luck:
Assembly Load Trace: The following information can be helpful to determine why the assembly 'XXXXXX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=121fae78165ba3d4' could not be loaded.
=== Pre-bind state information ===
LOG: User = MyComp\me
LOG: DisplayName = XXXXXX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=121fae78165ba3d4
(Fully-specified)
LOG: Appbase = file:///d:/My Documents/Visual Studio 2010/Projects/CoolProj/WebApp/
LOG: Initial PrivatePath = d:\My Documents\Visual Studio 2010\Projects\CoolProj\WebApp\bin
Calling assembly : WebApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: d:\My Documents\Visual Studio 2010\Projects\CoolProj\WebApp\web.config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: XXXXXX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=121fae78165ba3d4
LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/90233b18/10d54998/XXXXXX.DLL.
LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/90233b18/10d54998/XXXXXX/XXXXXX.DLL.
LOG: Attempting download of new URL file:///d:/My Documents/Visual Studio 2010/Projects/CoolProj/WebApp/bin/XXXXXX.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
All it says it that it starts by looking for that old assembly. I have tried to find a solution online and saw this similar SO question, but it seems to be the exact opposite of my problem. That questioner's program was finding the wrong DLL instead of the referenced one. Whereas my problem is that the program is mysteriously looking for the wrong DLL and unable to find it when the right one can be found locally in the bin folder and in the GAC.
Why is mine looking for the old version? Where else can I search to find this bad reference?
My guess is that another assembly you are using is referencing the old dll. Are you familiar with all of the other project references being used and do any of them have a reference to the Telerik dlls?
Can you put in a binding redirect in your web.config file like this?
<dependentAssembly>
<assemblyIdentity name="Telerik" publicKeyToken="121fae78165ba3d4"/>
<bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>
</dependentAssembly>
I tried most of the answers but still couldn't get it to work. This worked for me:
right click on reference -> properties -> change 'Specific Version' to false.
Hope this Helps.
I'm with Chris Conway on this one (upvoted him). The problem is that you are referencing one of the telerik assemblies in your project which references another one that isn't there.
First thing: I wouldn't install ANY vendor (ie: telerik) assemblies into the GAC. Telerik's stuff is compiled down to just two assemblies anyway (telerik.web.design and telerik.web.ui). Just deploy those with the application.
Second, in each of your .proj files (like .csproj) there is going to be a <reference include..> which points to the Telerik.Web.UI file. This normally contains a version number. Make sure the assembly you put in the bin folder matches that version.
Third, make sure ALL of your projects use the latest assembly. Also make sure they are grabbing the assembly from a local path instead of the GAC. (I really really don't like the GAC. It has caused no end of issues on some projects I've been on). We typically have an "Assemblies" folder that all projects use for external assembly references.
Fourth, visual studio automatically searches your gac everytime a web site project is loaded and retargets the assembly locations if it finds something in the gac. I can't remember if it ever does this for web application projects, but I haven't had the issue in a long time with those. This can cause similar issues during deployment.
Fifth, you can rebind version numbers for assemblies in the web.config. In the runtime/assemblybinding section you can use something like the following which takes every telerik assembly deployed in 2008 forward and points it to a very particular version:
<dependentAssembly>
<assemblyIdentity name="Telerik.Web.UI" publicKeyToken="121fae78165ba3d4" />
<bindingRedirect oldVersion="2008.0.0.0-2020.0.0.0" newVersion="2010.02.0713.35" />
</dependentAssembly>
Try:
cleaning temporary project files
cleaning build and obj files
cleaning old versions installed at
C:\Users\USERNAME\.nuget\packages\
That worked for me.
Go to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG
Find machine.config file
open in notepad
find conflict dll
Remove this and save.
compilation assemblies
addassembly=dllName,Version=1.0.0000.0000 Culture=neutral,PublicKeyToken="QWEWQERWETERY"
assemblies compilation
works for me.
This isn't a clear answer as to why, but we had this problem, here's our circumstances and what solved it:
Dev 1:
Solution contains Project A referencing a NuGet Package, and an MVC project referencing Project A. Enabled NuGet Package Restore, then updated the NuGet package. Got a runtime error complaining the NuGet lib can't be found - but the error is it looking for the older, non-updated version. Solution (and this is ridiculous): Set a breakpoint on the first line of code in the MVC project that calls Project A. Step in with F11. Solved - never had a problem again.
Dev 2:
Same solution and projects, but the magic set breakpoint and step in solution doesn't work. Looked everywhere for version redirects or other bad references to this Nuget package, removed package and reinstalled it, wiped bin, obj, Asp.Net Temp, nothing solved it. Finally, renamed Project A, ran the MVC project - fixed. Renamed it back to its original name, it stayed fixed.
I don't have any explanation for why that worked, but it did get us out of a serious lurch.
Do you have any other projects in that solution ?(may be another project was referencing an old version) Usually in VS, dll dependency spans all projects in the solution.
I had a similar issue and I had to delete everything from the bin and obj folders and rebuild to get past my issue. Hope this helps.
My problem was that the old assemblies were in the _bin_deployableAssemblies folder under the Web Application.
This meant the old assemblies were overwriting the GAC assemblies when building the project.
In case is saves someone else 3 hours... my case was a bit different. My code used DevExpress v11.1 v11.1.4.0. I had it all referenced correctly in my code. But .net memory profiler installed DevExpress v11.1 v11.1.12.0 in the GAC. In fact it wasn't the components I referenced but the ones they referenced internally that failed. Try as I might, the GAC is always checked first. It compiled and ran fine but I couldn't view the win forms designer and the stack trace was no help at all. Finally uninstalled .net memory profiler and all was restored.
This error was somewhat misleading - I was loading some DLLs that required x64 architecture to be specified. In the .csproj file:
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release-ABC|AnyCPU'">
<OutputPath>bin\Release-ABC</OutputPath>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
A missing PlatformTarget caused this error.
I was getting:
Could not load file or assembly 'XXX-new-3.3.0.0' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
It was because I changed the name of the assembly from XXX.dll to XXX-new-3.3.0.0.dll. Reverting name back to the original fixed the error.
If you are experiencing this problem when testing and/or debugging the application from the Visual Studio environment (ASP.NET Development Server), it is necessary to delete all temporary files on the development website folder. To know where that folder is, look for the ASP.NET Development Server icon on the Windows tray icon (it should have a title like this: ASP.NET Development Server - Port ####), right click the icon and select Show Details; thn, the field Physical path will tell you what the temporary folder is, all items there should be deleted to solve the problem. Build and run again the website and the problem should be solved (again, solved for the Development Environment).
I had the same problem with different assemblies referencing different versions of Newtonsoft.json. The solution that worked for me was running update-package from Nuget Package Manager Console.
Its almost like you have to wipe out your computer to get rid of the old dll. I have already tried everything above and then I went the extra step of just deleting every instance of the .DLL file that was on my computer and removing every reference from the application. However, it still compiles just fine and when it runs it is referencing the dll functions just fine. I'm starting to wonder if it is referencing it from a network drive somehwere.
I had the same message when switching between two versions of an application that referenced different versions of the same DLL. Although I was testing in different folders I accidentally copied the newer version over the older version.
So the first thing to check is the version of the referenced DLL in the application's folder. Just in case.
Maybe this helps or maybe not. I cleaned my debug and release versions then I renamed the OBJ folder. This finally got me thorugh. Previous steps were basically project removing references and them adding them back in at the project properties.
In My Visual Studio 2015, I ensured that the offending Visual Studio Project's Reference Paths List is empty:
This is what worked for me:
I was using the Microsoft.IdentityModel.Clients.ActiveDirectory version 3.19 in a class library project but only had version 2.22 installed in the actual ASP.NET Web Application project. Upgrading to 3.19 in the web app project got me past the error.
In my case i had 3 projects, 1 main project and 2 sub projects referenced by main project.. So i updated the main project, leaving out sub project. That's where the conflict was. After i updated all my project everything worked just fine.
In VS2017, have tried all the above solution but nothing works. We are using Azure devops for versioning.
From the teams explorer > Source Control Explorer
Select the project which driving you nuts for a long time
Right click the branch or solution > Advanced > get specific version
Then make sure You have ticked the checkbox of overwrite files as per screenshot
In my case, I accidentally chose the wrong version of the Telerik package from nuget, which nuget then replaced every package i referenced with the incorrect version. It then inserted a binding redirect to the incorrect version so that even after I replaced everything with the correct version, it was still looking for the incorrect version.

generating an asp.net web application dll requirement list

I'm trying to set up a web app (32bit on ii7/win7, 32bit setting is enabled, everything is compiled to x86, using vs2008), but there's clearly some dll module loading issue happening. I've been watching procmon and fusion logs but I'm not seeing the name of the missing dll.
I'm a complete newbie to asp.net (but fairly heavy experience on other platforms).
I know I can call depends.exe on a binary to see what the dependancies are, but how do I do it for asp.net? specifically, is it possible to get a list of the dlls that iis7 loads for my application?
update: I manually blew away all of the binaries for my application and rebuilt (clean didnt seem to do the trick, I guess). it's now sort of working. or at least it's getting further and more detailed.
An asp.net web project dll shouldn't depend on anything that is not part of the default .net run-time or explicitly referenced in the project. I would start by reviewing the references. Noramlly an asp.net web project has a bin folder that contains the compiled website/webapplication and any dll's that it depends on (aside from the .net run-time). This is usually done by the programming tool used to create the project.
If you still don't find the culprit, you could try using Filemon (http://technet.microsoft.com/en-gb/sysinternals/bb896642.aspx) and use it to watch IIS to see what files it is looking for and isn't finding.
An additional option is to examine the web.config file that should have been included with the web site/application. Its an XML file and usually has an Assemblies section that lists assemblies that should be loaded. For example you might see:
<assemblies>
<add assembly="MySql.Data, Version=6.2.3.0, Culture=neutral,
PublicKeyToken=C5687FC88969C44D"/>
</assemblies>
This means that the code wants to use the MySQL.Data.dll, and specifically version 6.2.3.0 of that DLL. It is possible to have different versions of .Net dll files installed at the same time. So you might have the desired DLL, but not the correct version as specified in the Web.Config file.

Dll in both the bin and the gac, which one gets used?

We have a web application that's deployed to many websites with only frontend changes, the shared backend portion has it's DLL in the GAC so we only have to update that one dll and all the sites get the update.
Is there a way to override the GAC with a DLL in the /bin folder to test out new features before they get released?
If it has the same version number as the referenced DLL, the GAC gets used.
If you increment the version number, rebuild the website referencing the new version number, put the new version in the /bin directory, then that DLL will be used.
If you do not want to change the version number, you're pretty much out of luck.
When .NET loads strong named assemblies, first it tries to decide what version number to use. It does this via the reference first, then it looks for publisher policies, then it looks for binding redirects in the configuration file.
After it does this, it looks for the assembly in the GAC, then in any codebase specified, then it probes various file system folders for the DLL. If at any one of those steps it finds the right version assembly, it stops.
If you are not changing the version number of your strong named assembly, .NET will find the original one in the GAC and stop looking. Note that because it stops when it finds one, and because looking in the GAC is first, specifying a codebase for your assembly will do no good unless you also specify a new version number.
I have been able to override the GAC with the assembly in the \bin folder using the <codebase>Element.
By specifying <codebase version="1.2.3.4" href="/bin/MyAssembly.dll" /> in my web.config file I can tell my application to use this version rather than the version specified in the GAC.
You may also want to take a look at the <probing>Element for specifying assembly locations?
I think I might be saying the same think as Adam Sills, but re-worded it for my understanding. Through my own testing, looks like this is what happens:
If your app is compiled with version 1.0.0.0 and 1.0.0.1 is in the GAC, then you can omit the .dll from your /bin.
If your app is compiled with version 1.0.0.1 and 1.0.0.0 is in the GAC, then you MUST place the .dll in your /bin to ignore the GAC. A error will occur if the GAC version is older than the required version of your app, unless you include the newer version in your /bin.
I hope this is correct...
You can view binding information in the log file using the Assembly Binding Log Viewer (Fuslogvw.exe), which is included in the Windows Software Development Kit (SDK).
s

Resources