The type is defined in an assembly that is not referenced, how to find the cause?

I know that an error message is common, and there are many questions about SO about this error, but no solutions have helped me so far, so I decided to ask a question. The difference with most of these questions is that I use the App_Code directory.

Error message:

CS0012: The type 'Project.Rights.OperationsProvider' is defined in an assembly that is not referenced. You must add a reference to assembly 'Project.Rights, version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. 

Original file:

 c:\inetpub\wwwroot\Test\Website\App_Code\Company\Project\BusinessLogic\Manager.cs 

The following sentences here and here , I deleted all instances of Project.Rights.dll inside C: \ Windows \ Microsoft.NET /*.* According to this , I checked if the .cs files for which the compile action is set . They make. I also double-checked that the .cs file containing the type "Project.Rights.OperationsProvider" is being deployed in the App_Code directory.

For some reason, the application is not looking for a type in the App_Code directory. Since I deleted all instances of Project.Rights.dll (what I know), I do not know on which assembly the error message is mentioned.

+46
Dec 18 '13 at 14:37
source share
13 answers

When you get this error, it’s not always obvious what is happening, but as the error says, you are missing a link. Take the following line of code as an example:

 MyObjectType a = new MyObjectType("parameter"); 

It looks simple enough, and you probably specified "MyObjectType" correctly. But suppose that one of the overloads for the constructor "MyObjectType" accepts a type that you are not referring to. For example, there is overload defined as:

 public MyObjectType(TypeFromOtherAssembly parameter) { // ... normal constructor code ... } 

This is at least one case when you get this error. So, find this type of template in which you specified the type, but not all types of properties or method parameters that are possible for functions called in this type.

Hope this at least makes you go in the right direction!

+58
Dec 18 '13 at 14:44
source share

Check the target structure in the projects.

In my case, “You must add an assembly reference” actually meant that the calling and referencing projects did not have the same target structure. The caller project had .Net 4.5, but the link to the library had a target of 4.6.1.

I am sure that the MS compiler can be smarter and write more meaningful error messages. I added a sentence https://github.com/dotnet/roslyn/issues/14756

+15
Oct 26 '16 at 12:06 on
source share

In my case, this was due to the fact that when updating the NuGet package, links to the dll dependency were updated in some, but not all projects in my solution, which leads to conflicting versions. Using the grep-style tool to search for text in * .csproj files in my solution, then it was easy to see projects that still needed updating.

+11
Apr 27 '15 at 11:12
source share

When you get this error, it means that the code you are using makes a reference to the type that is in the assembly, but the assembly is not part of your project, so it cannot use it.

Removing Project.Rights.dll is the opposite of what you want. You must ensure that your project can reference the assembly. Therefore, it must be placed in the global assembly cache or in the directory of your web application ~ / Bin.

Change If you do not want to use the assembly, removing it is also not the right solution. Instead, you should remove all links to it in your code. Since the assembly is not directly needed for the code you wrote, but instead you use something else to reference it, you will have to replace this assembly link with one that does not have Project.Rights.dll as a dependency.

+7
Dec 18 '13 at 14:41
source share

one of the main reasons the DLL property may be you must do something before checking for a specific version property if it truly makes it false

Reason: it is possible that the source code was associated with a different (old) version when it was created, but this library was updated with a new update, now the new version in Cash Cash and your application were forbidden to receive a new DLL, and after disconnecting the specific version property your applacaten will be free to get the new version of the dll links

0
Apr 08 '14 at 15:14
source share

It also means that you are using a library that provides (public) types defined in the library. Even if you do not use them specifically in your library (one that is not created).

What this probably prevents, you are writing code that uses a class (which in its signature has types from a library that is not referenced) that you cannot use.

0
Dec 14 '15 at 11:08
source share

It just happened to me that different projects referred to different copies of the same DLL. I made sure that all the links were to the same file on disk, and the error went away as I expected.

0
Mar 29 '16 at 2:52
source share

For me, the reason the error occurred was because WebForm, where the error was reported, was moved from another folder, but the class name of its code remained unchanged and did not match the actual path.

Initial state:
Original file path: /Folder1/Subfolder1/MyWebForm.aspx.cs
Source code class name: Folder1_Subfolder1_MyWebForm

After moving the file:
File Path: /Folder1/MyWebForm.aspx.cs
Codefile class name (unchanged, with error shown): Folder1_Subfolder1_MyWebForm

Decision:
Rename the codefile class Folder1_Subfolder1_MyWebForm
to one matching with the new path : Folder1_MyWebForm

All at once - the problem is solved, there are no error messages.

0
Jun 30 '16 at 10:15
source share

In my case, none of this happened. It turned out that the dll link version was actually newer than the version I had before.

I just needed to revert to the previous version, and this is fixed.

0
Dec 05 '16 at 12:53 on
source share

The type "Domain.tblUser" is defined in an assembly that is not a reference. You must add a reference to the assembly "Domain", Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null '.

 **Solved:** Add reference of my domain library layer to my web app libary layer 

Note. Make sure your links are correct according to your DI container

0
Apr 30 '17 at 4:40
source share

In my case, it was because I used

Implicit statement

between BLL and DAL classes.when I want to use BLL Layer In Application Layer, I got this error. I changed

implicit statement

to

explicit operator

everything is fine. Thanks

0
May 03 '17 at 17:51
source share

Perhaps the library (DLL file) you are using requires a different library. In my case, I referenced the library containing the database entity model, but I forgot to reference the entity library.

-one
Oct. 15 '14 at 14:28
source share

Clear your solution and rebuild the work for me (in Visual Studio these are the parameters that you get when you right-click in your solution browser), the error went to my project.

-one
Dec 30 '16 at 8:30
source share



All Articles