I'm trying to reference Oracle.DataAccess.dll in my c# project assembly. When running the project I get the following error:
Could not load file or assembly 'Oracle.DataAccess, Version=2.112.2.50, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
I'm really confused because when I right click references and add an assembly I navigate to a copy of the dll that I have in a folder contained within the project and add the reference. When I look at the properties of the reference, though, it shows a path of
C:\Program Files\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\Profile\Client\Oracle.DataAccess.dll
and sure enough there is a dll in there by that name, but it's an old version. Why does this reference not point to the path that I specified when adding it, and how can I get it to use the dll at the location that I specified?
We take a couple of steps to resolve issues like this when we know that the specific version does not matter to the built application:
1) In the properties for the reference within the project, ensure the Specific Version property is set to False.
2) Save the project, the edit it in notepad or the text editor of your choice. Find the DLL reference and remove all version and key information and ensure the hint path points to your copy of the file. For example:
<Reference Include="Oracle.DataAccess">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Assemblies\Oracle.DataAccess.dll</HintPath>
</Reference>
Visual Studio can be a bit flaky when it comes to references. Many times we have to just edit the project file directly. Setting the properties of the reference directly doesn't always stick. Right-click your project, select Edit Project File, and make the change there. It should stick.
Related
My web project use .NET Framework 4.7.2 and use some references like
System.IO
System.Net
System.Net.Http
System.Net.Http.Formatting
My project works perfectly in local.
However, when I publish my web project on a target directory (for online), and look what it contains in /bin/ :
System.IO is missing
System.Net is present
System.Net.Http is missing
System.Net.Http.Formattingis present
Therefore, when I use my website, I get the obvious error Could not load file or assembly 'System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
All references have Copy Local = True in Properties but some dll are always ignored. If i copy the dlls from local directory to target directory i get the error Server Error in '/' Application. Cannot load a reference assembly for execution. Exception Details: System.BadImageFormatException: Cannot load a reference assembly for execution. Exactly the same problem as this one.
However the delete/rebuild solution, or adding compilation options solution, doesn't work for me
What do I need to do to get these missing dlls to the destination folder?
Go to Solution Explorer on VS, open references tree, right click on the library(dll) and select properties on the menu. On properties box Copy Local should be True
I have a scenario where i have library say for example : SomeLibrary.dll which references to System.Net.Http and System.Net.Http.Formatting just an example with Copy Local flag true, and that assembly is actually consuming some types of these two dlls.
Then i create a new Project and i add reference to SomeLibrary.dll with Copy Local flag true, when use methods of this dll which are internally using the above 2 libraries, the runtime error comes saying:
Could not load file or assembly 'System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
What i was expecting was it should have dependent assemblies on which SomeLibrary.dll depends should also be in the bin folder copied, which is not happening.
Am i missing something here?
UPDATE:
For your information, i am able to make it work by adding reference seperateely to those 2 dlls but wondering why i need to add seperately if i have reference to SomeLibrary.dll which is dependent on those 2 dlls.
I just had a very similar sounding problem, where I had assembly A depending on assembly B, and B depended on System.Net.Http.Formatting.dll. For some reason on my build server it wasn't copying System.Net.Http.Formatting.dll so it was missing in the final package it created (though in my case it wasn't in either projects' output folder). It worked fine locally on my development machine and I verified the assembly existing in the same place on the build server as it did on my machine (C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies).
I worked-around the problem with this answer to the related question, which was to switch to using the Microsoft.AspNet.WebApi.Client NuGet package to pull in that assembly explicitly. Unfortunately I'm still not sure what the problem was.
I'm converting my project from MVC 4 to MVC 5 (and .Net 4 to .Net 4.5.2, which is the real driver of the changes.)
When I run one of my pages I get this error (blank space added by me for easier reading)
[A]System.Web.WebPages.Razor.Configuration.HostSection cannot be cast
to [B]System.Web.WebPages.Razor.Configuration.HostSection.
Type A originates from 'System.Web.WebPages.Razor, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context
'Default' at location
'C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_1.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll'.
Type B originates from 'System.Web.WebPages.Razor, Version=3.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context
'Default' at location
'C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET
Files\studentportal3g\2204bad2\aece9b3b\assembly\dl3\ad80387c\91adbf51_fc73d101\System.Web.WebPages.Razor.dll'.
When I first saw this is though, Ah easy! Not so much :)
I've gone over every project and made sure it's version is upgraded to MVC 5 which has the 3.0.0.0 version of System.Web.WebPages.Razor.dll.
Clean rebuild, still get the error. No problem , I'll delete the cached temp files.
Clean rebuild, still get the problem. I go back, manually check each version of System.Web.WebPages.Razor.dll, in the references of each project that has a reference to it. I check my folder where I copy dlls to make references to them manually, it's not there.
If my solution doesn't' contain a copy of the DLL or a reference to the DLL, and I've manually deleted the cache folders in 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET
Files\studentportal3g...
Where is the old bad dll coming from? How do I fix this error? How do I prevent it happening again?
Thanks,
Eric-
Visual Studio is a great tool, but it doesn't always make the right choices when it comes to upgrading dependencies, nor does it support every possible option available in MSBuild. Whenever you find yourself in a bind such as this you should manually review and (if necessary) edit your .csproj file in order to resolve it.
The problem isn't that your file exists in the GAC or that it has not been installed by NuGet, the issue is most likely that one of your project files still has a reference to the old version of System.Web.WebPages.Razor version 1.0.0.0, and you need to find all references to it and change them to 3.0.0.0 accordingly.
Right-click on your project node in Solution Explorer and click Unload Project.
Right-click the project node again and click Edit <projectName>.csproj.
Search the file for references to System.Web.WebPages.Razor and update the version and the HintPath accordingly (as shown below). Make sure the HintPath you use actually points to an existing file.
Repeat these steps for all dependent projects in the solution (and any that are in DLLs that are not part of the solution).
Old Reference
<Reference Include="System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\Microsoft.AspNet.WebPages.1.0.20105.408\lib\net40\System.Web.WebPages.Razor.dll</HintPath>
</Reference>
Updated Reference
<Reference Include="System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.0.0\lib\net45\System.Web.WebPages.Razor.dll</HintPath>
</Reference>
You should also go through the web.config and /Views/web.config files to ensure that they are not referencing any old versions of this assembly.
NOTE: If the above instructions don't solve your issue, the issue likely is outside of your solution. Most likely there is a 3rd party library that is referencing the old version of the file somewhere. If so, you could attempt to get an updated version of the DLL.
You may also want to check out this question.
It looks like the old DLL is in the Global Assembly Cache (GAC). The GAC is a place where you can store assemblies that can be referenced from several applications on the machine. Click here to read more about GAC.
Use the tool gacutil to update the assembly in the GAC.
The tool is located somewhere under "Microsoft SDKs" folder in Program Files. For me, it was located in
C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\
Open cmd and navigate to the place where gacutil i stored. Then use it like this:
gacutil.exe -i [path to your assebly] -f.
The -i parameter is for indicating where your assembly is located. The -f parameter is used to force an update of the assembly, if it was already there.
Example
Say your DLL is located in
C:\temp\System.Web.WebPages.Razor.dll
Then you would run gacutil.exe -i "C:\temp\System.Web.WebPages.Razor.dll" -f
I've upgraded a VB6 project to C# and I'm trying to run a winforms project and I have the Interop.InetCtlsObjects.dll file in my project and I've added a reference to it, but when I'm trying to run it I'm getting this error:
Could not load file or assembly
'Interop.InetCtlsObjects, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
or one of its dependencies.
The system cannot find the file specified.
But I can see the file and I added a reference to it's exect location...
So what am I missing here ???
Delete the reference, save the project and add it in again. It is possible that you are somehow referencing a different version and the compiler cannot find the right DLL because of it. If that doesn't work, check your app.config and make sure the versions for this particular DLL match.
i have create a c# form application for parsing Html using Winista.html parser.
Now i have created a setup project for this and when i install the setup and run it generates error
System.IO.FileNotFoundException: Could not load file or assembly 'Winista.HtmlParser,
Version=1.8.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The
system cannot find the file specified.
File name: 'Winista.HtmlParser, Version=1.8.0.0, Culture=neutral, PublicKeyToken=null'
at Investigator.Form1.googleNewsSearcher()
Why is this happening ? Why is it not finding the dll , i pasted the winistal.HTMLParser in the bin folder ,and add reference to it .Is there any thing missing please help this is very urgent , i have to submit this?
Thank you
YOu have to add a reference, when you create a setup project it doesn't look in the bin folder for assemblies it checks references. You should be able to add the assembly to the setup project. I would suggest that you add it as a reference though.
You might also need to re-add the primary project to the setup project once you do this, but I think a rebuild should solve it once you added the reference to the assembly.
Update
Try right clicking on the reference and select copy always. This will insure that the assembly is always coppied to the bin folder.