I came across this error today which made me quite curious on why it is happening. This occured to me in a SharePoint WebPart, but it is a very general .NET Framework error and as such can occur in any type of .NET application.
CS0011: Referenced class someClass’ has base class or interface
someNamespace.someBase’ defined in an assembly that is not referenced. You must add
a reference to assembly ’someNameSpace’.
To explain the scenario. You have an assembly in the GAC with some classes. You have some code which you are running which reference the GAC dll. For my case, I was inheriting my webpart from one of the baseclasses defined in the GAC assembly. If I put the assembly in the /bin directory as well as the GAC it worked beautifully, but if I deleted the assembly from my /bin directory, I got the above error. This sort of nullified the entire purpose of having a GAC.
What was happening was that the code was trying to reference the someNamespace.someBase Class but as there was no link in the code to provide it with a hint that the required assembly is in the GAC, it was complaining. As soon as the dll was in the /bin directory it was able to reference it and all was ok. To solve the problem, there are two ways to do it.
1. If you have a ASP.NET application, you can add a @Register Assembly derivative in your page.
2. You can add the reference in your web.config to hint the application to look for the assembly in the GAC by adding the following lines in your web.config file..
<system.web>
<compilation batch=”false” debug=”true”>
<assemblies>
<add assembly=”someAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=s0m3publ1ck3y” />
</assemblies>
</compilation>
</system.web></code>
The solution was found, the day was won. But it made me wonder if this is a design defect with .NET. If placed in the \bin directory, the application was very happy to reference the dll. If an assembly is in the GAC, why do we have to explicitely tell out application to look for the reference in the GAC. Shouldn’t it be doing that automatically in the first place.