1

I have been working on an asp.net/C# website for a while and decided to put my SQL C# code into a class library (.dll). The problem is, when I try to add it to my website application in vs2010 it sees it, but doesn't at the same time. What I mean is the web application tells you that it is added as a reference under the reference folder, but when compiling the code it will say you don't have the reference.

The way I add the reference is by right clicking the solution and selecting "add reference". I browse for the reference (.dll file) and then add it.

here is the error:

    CS0246: The type or namespace name SQL_lib could not be found (are you missing a using directive or an assembly reference?)

I did add all the references in the web application that the dll file code had so it can't be that... I really don't know whats going on. Thank you in advance :-)

edit:

The only time the web application shows that it cannot find the reference is when it is done compiling and just executed. In the browser it shows the error above. When I go into the code I see no underlined error markings in the code for some reason and I can access the class within the reference. I will further look into it...

Also it has the error in aspx based cs file and plain cs files.

Sovr Sov
  • 196
  • 3
  • 17

4 Answers4

3

Make sure you have added reference to the namespace in which the SQL_lib class is defined:

using Namespace_In_Which_You_Declared_The_SQL_libClass;

Now you could use the SQL_lib class. Also make sure that this class is public:

public class SQL_lib
{
    ...
}
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • I did do that and I can access the class in the web application code while coding, but when I compile and try to run the code it shows me that error. I am maybe thinking of not putting a namespace in the class library to see if that would help. – Sovr Sov Aug 21 '13 at 17:35
1

Either add a using for your namespace, like this:

using YourNamespaceForSQL_Lib;

or fully qualify the object name in your code, like this:

YourNamespaceForSQL_Lib.YourClass = new YourNamespaceForSQL_Lib.YourClass();

Note: If you have correctly added the reference and you have a class name underlined, then you can click on the class name and press Ctrl + . and it will offer to automatically add the correct using namespace entry in your code file. Visual Studio will reflect across all DLLs in your References and offer multiple namespace choices if they exist.

Karl Anderson
  • 34,606
  • 12
  • 65
  • 80
1

In Visual studio right click on the method or class thats causing the error in the code window and click 'resolve', this will suggest adding the using reference for you.

Matt
  • 274
  • 4
  • 15
1

I struggled with a similar problem and found my way here. The answers here didn't work for me, but here is what I did to solve it.

I had to add the file to the GAC.

gacutil.exe /i MyFile.dll

Then you can get the version and

gacutil /l MyFile

The Global Assembly Cache contains the following assemblies:

MyFile, Version=6.8.0.6, Culture=neutral, PublicKeyToken=99ttt95b5a5 d634b, processorArchitecture=MSIL

Then you take the values and copy them into the top of your aspx page to Register and then include.

Uri Agassi
  • 36,848
  • 14
  • 76
  • 93