project reference won't compile 'should be reference' - c#

In the following new test project I've created for testing the web code I have the following error when trying to compile my code.
Not sure what this means because I've added the reference to the project including the controllers into the test project??
Any ideas
Many thanks,
James
Error message
Error 330 The type 'Web.Supporting.BaseControllers.PowerController' is defined in an assembly that is not referenced. You must add a reference to assembly 'Web.Areas, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. C:\Power\Test.Unit.Web.Portal\Controllers\SearchProductControllerTests.cs 39 13 Test.Unit.Web.Portal
UPDATE
Tried adding system.web.mvc into the test project although I can't see it, see image below
UPDATE
Found it by looking at an existing test project. Can't see it in the dialog (???) but I located it here: C:..\packages\Microsoft.AspNet.Mvc.4.0.30506.0\lib\net40\System.Web.Mvc.dll

Did you include reference to Web.Areas library which it is asking for? If not add it.
If you already have a reference to it then "Target Framework Version" will be the problem. If your current project is targeted to lesser version than the referenced assemblies this will happen. Ex: If current project targets to .net4.0 and Web.Areas is targeted to .net4.5 this error will appear.
To fix it you may need to downgrade all other projects version or upgrade current project's version.

To resolve this I added a reference into the test project for the PowerController dll and also the system.web.mvc. Note: system.web.mvc is in the extension tab of the 'add reference' dialog.

Related

You must add reference to assembly... without web.config file

I’m using visual studio 2015 to write in c#.
I have a logic project which is a class library (package), and UI project which is console application (package) and I’m connecting the two with reference.
I have the error: CS0012 The type object is defined in an assembly that is not referenced. You must add a reference to assembly ‘System.Runtime, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”
I’ve searched online and the solution I’ve found was to change the web.config file, but I don’t have one. Another solution was to add reference to System.Runtime.dll but it made 1135 errors when I did that, such as “Predefined type System.Object is not defined or imported”. So what other solutions there are?
I don't have VS 2015 installed right now. But from what I remember it's the same than 2017 :
Project > References > Add reference > Assembly

.Net Framework You must add a reference to assembly mscorlib, Version=4.0.0.0

After updating and including some NuGet packages, I now get many compile errors similar to:
The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
I looked at You must add a reference to assembly mscorlib, version=4.0.0 but I'm not running .Net core - this is an ASP.NET MVC, .Net Framework 4.7.2 Project.
There is no project.json to update. I already included the Microsoft.NETCore.Portable.Compatibility NuGet package to no effect.
What is causing this, and how can I fix it?
Right-Click on your project and click Clean Solution in Visual Studio, and then try building it again. Solves the problem most of the time for me.
Or else, in case you copy-pasted a class from somewhere else, try creating a new class in your project and instead, copy-paste the code within the other class instead of just copying the class itself.
I also faced the same issue, I got this when I was trying to install EntityFramework.
Code Clean-Up worked for me. Go to analyze and then try to run code cleanup using both profiles.
For completeness's sake, I'll include the fix that actually worked for me as an answer.
Just delete the repo, re-clone, and try again.

Referenced project dependencies DLL are not being copied

My project solution is currently having three projects:
MyProject, which is my main startup project (using .NET Framework 4.7) - WPF, UI specfic,
MyProject.Core - class library (.NET Standard 2.0) - holding the models, and all of the 'behind the scenes' data
MyProject.Relational - class library (.NET Standard 2.0) - responsible for processing and saving the database specific informations
Project 1 (main) has set a reference to project 2 and 3.
For the project 3 I have installed a NuGet dependency of Microsoft.EntityFrameworkCore.Sqlite (2.0.3).
Now, when I finally want to make use of project 3 and call it's method, the following exception is being thrown:
System.IO.FileNotFoundException: 'Could not load file or assembly 'Microsoft.EntityFrameworkCore, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The system cannot find the file specified.
This, of course is a missing DLL file - no entity framework DLL's are being copied to the app Debug directory.
Why is that? Is this intended behaviour? Do I have to install the dependency of Microsoft.EntityFrameworkCore.Sqlite for project 1 as well? Pretty pointless to me, referencing the same dependency to project that is making no use of it.
What have I tried:
Cleaning up the project, removing bin/obj directories,
Set project reference properties setting copy local to True,
Solutions given in this question: Referenced DLL not being copied to referencing project
Using Visual Studio 2017.
Solved this by adding the following line into my .csproj file:
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
Specifically to the PropertyGroup group.
Not sure why it makes such difference, if anyone could explain and post in the comment it would be great. Any additional informations I will add to this answer.

Use .net DLL with broken References

I have to use a DLL as an API in my application (C#, .NET 4.5). I can reference the DLL normaly. No error at all. But if I want to use any class of this DLL, I get the following compile error:
Error CS1705 Assembly 'Assembly_X' with identity 'Assembly_X,
Version=12.3.0.0, Culture=neutral, PublicKeyToken=c878e80841e75d00'
uses 'Assembly_YY, Version=65535.65535.65535.65535, Culture=neutral,
PublicKeyToken=c878e80841e75d00' which has a higher version than
referenced assembly 'Assembly_YY' with identity 'Assembly_YY,
Version=12.3.0.0, Culture=neutral, PublicKeyToken=c878e80841e75d00'
Then i checked the DLL (Assembly_X) in ILSpy. The Assembly_X has two references to Assembly_YY: One with the version 12.3.0.0 and one with the version 65535.65535.65535.65535.
I tried the "bindingRedirect" in the App.config. But since the error occures during compile time this doesn't help.
I don't have the source code of Assembly_X or Assembly_YY.
How can I use this DLL or repair it?
UPDATE
The developers of the dll finally answered my call for help. The only work around they know of is to use Visual Studio 2013 instead of Visual Studio 2015 or 2017. It seems VS 2013 is not bothered by these double reference at all.
They write, that the error is created by a encrypting tool for the dll.
Thank you all for your ideas and help.
It looks like the first DLL is referencing a library which is a higher version than the other DLL you are using.
so you have 3 DLL's to consider: A, B & Bv2
Your project is referencing A & B
But A references Bv2 (an updated version of B)
SO when you go to use functions of A it throws an error because it finds B instead of Bv2.
The problem basically that you are referencing 'Assembly_X' which references assemblies 'Assembly_YY' versions 12.3.0.0 and 65535.65535.65535.65535 and you referenced only 'Assembly_YY' version 12.3.0.0 in your application and didn't reference 65535.65535.65535.65535
Now according to the problem explanation on Microsoft Docs, and your example which you don't have the source code for the assemblies you have to:
Add a reference to 'Assembly_YY' version 65535.65535.65535.65535 of the DLL to your application to make it compile and to enable the application to run, you can provide an application configuration file that includes a <dependentAssembly> element that uses <assemblyIdentity> and <codeBase> child elements to specify the location of version 12.3.0.0 of the DLL.
You are referencing a higher version of DLL then the one you currently have.
You will need to add the reference to the higher version assembly:
'Assembly_YY, Version=65535.65535.65535.65535, Culture=neutral, PublicKeyToken=c878e80841e75d00'
in order to solve this.
Right now you are referencing
'Assembly_X' with identity 'Assembly_X, Version=12.3.0.0, Culture=neutral, PublicKeyToken=c878e80841e75d0
If this is a downloadable library, search for it in the nuget package manager and download it.
If it's a library written by you, obtain the latest version of the library and add it to your project.

How to resolve "The located assembly's manifest definition does not match the assembly reference." error?

I downloaded source code for pdfiumviewer from git hub. I made changes to one of the projects in that solution.Then I added that project to my application and added reference of that project to one my application's project.I had to uncheck the Signing option for the PDfiumViewer project, as some of the dll in that project are unsigned.I am able to build the application successfully.But at run time when I create an object of one of the class of PDfiumviewer project.It gives me the following error:
Could not load file or assembly 'PdfiumViewer, Version=2.11.0.0,
Culture=neutral, PublicKeyToken=null' or one of its dependencies. The
located assembly's manifest definition does not match the assembly
reference. (Exception from HRESULT: 0x80131040)
The version number of the assembly is correct.So, why am I getting this error?
The problem was that I had added reference of old unmodifed PdfiumViewer dll to another project.Hence, there was conflict between the two dlls (old and customized) at runtime.I removed the old dll reference and it worked.
Ive also encountered this issue, my scenario was thou that I had to add a reference from another solution into my project removing the reference was not an option - what worked for me was reinstall SQLclient from nuget package managerer on both solution. Hopes it helo someone else
The issue here is that you have a library that references v2.11.0.0 of the Pdfium library. This library could be an assembly that you built earlier, or another assembly that came from Pdfium that references this version of the library. When you built your version of the library you probably didn't use this same version number, and it wouldn't have been strong named correctly. To fix this, you can add an assembly binding redirect in your applications configuration file to redirect the offending library to your custom built one.
I wrote a program to fix this issue automatically: https://github.com/BackTrak/DependencyFixup/releases/tag/1.0.0.0
I know this question is old, but hopefully this helps out others!

Categories

Resources