Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange Error - CS0012: The type x is defined in an assembly that is not referenced

The type 'x' is defined in an assembly that is not referenced. You must add a reference to assembly 'abc123'.

I have a .NET 2.0 web application that references my assembly 'abc123'. The assembly exists in the GAC and I've verified that it is the correct(same) version. The rest of application has no issues except for one .aspx page. The page in question has a repeater that displays a user control as one of its "fields". Upon binding a list of type y to the repeater I pass the user control a list of type x (a property of y) as shown here:

<uc1:usercontrol id="ucusercontrol " runat="server" myPublicUserControlProperty='<%#Eval("CollectionOfX") %>'/> 

On the user control's property set, I bind the list of type x to a gridview in the user control.

One strange thing to note is that this report works fine on my development pc but not on any servers once I deploy. My pc is Windows XP, IIS6, VS2005. The servers are Windows Server 2003, IIS6.

I hope I explained that well enough. Thanks in advance for any insight you can provide.

like image 669
Mike T Avatar asked Nov 12 '08 16:11

Mike T


People also ask

How do I fix error CS0012?

You could resolve this CS0012 by compiling with /reference:cs0012b. dll;cs0012a. dll , or in Visual Studio by using the Add Reference Dialog Box to add a reference to cs0012a. dll in addition to cs0012b.

Is defined in assembly that is not referenced?

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


2 Answers

I'm Mike's coworker, and we worked out a solution.

The type X is defined in his assembly, that is only in the GAC. Even though his ASP.NET web appplication did have a reference, it was failing to load from the GAC only for this UserControl. The rest of the application worked as expected. We confirmed the failed loading by placing a copy of the assembly in the bin directory, and everything worked. We removed the assembly, and the problem came back.

Our solution was to manually add an entry to the web.config in the assemblies section to point ASP.NET to the GAC.

It looks like any time you reference a type in the page (not the code-behind), you need the assembly information defined in the web.config file or in a page directive.

<assemblies>         <add assembly="MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=[MyPublicKeyToken]"/>    </assemblies> 
like image 138
Aaron Daniels Avatar answered Sep 21 '22 03:09

Aaron Daniels


There's also a bug that can manifest itself with similar symptoms, described here.

The workaround is to delete everything in the C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\ directory, and it only seems to manifest itself in debug mode.

like image 33
Tom Lianza Avatar answered Sep 18 '22 03:09

Tom Lianza