locked
The type or namespace name 'xxx' could not be found (are you missing a using directive or an assembly reference?) RRS feed

  • Question

  • User-1842880510 posted

    I had a Asp.Net 4.0 Web Forms web application.  It has been working fine.  I created a class Library project.  I created the assembly.

    I added the assembly to the bin directory of the web forms project.  I added a reference in the web forms project to the assembly, pointing at the file in the bin directory.  I am doing this is VS 2012.

    I added a couple of "using"s for this assembly.  Now the "using"s are throwing the error "The type or namespace name 'xxx' could not be found (are you missing a using directive or an assembly reference?)"  when I try to compile.  This is a process I've done a thousand times without this issue.  What could be going on now?

    Thursday, October 17, 2013 4:18 PM

Answers

  • User-1842880510 posted

    I got this reply on Experts Exchange

    From the project properties, check whether it is targeting .NET Framework Client Profile.
    If yes, you may need to change it to appropriate .Net framework
    
    Hope this may helps.

    Because of this suggestion

    I checked the properties of the class library project.  Turns out that it was compiled as a .Net 4.5 project whereas the Web App was compiled as a .Net 4.0 project.  So I changed the class library to 4.0 and re-compiled it.  Then copied the new assembly to the the bin directory of the Web app.  I then opened the web app and it compiled quite nicely.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 18, 2013 8:43 AM

All replies

  • User465171450 posted

    Don't put it in the bin directory. That can sometimes get over-written when the app compiles. Best to put it somewhere else then add it as a reference with the copy local option set to true. It's not uncommon to have a Dependencies folder in a solution to hold dlls used by all projects in a solution.

    Thursday, October 17, 2013 4:35 PM
  • User281315223 posted

    You'll need to actually add a reference to the actual DLL that you are using to ensure that the library is included when you compile you application. You can do so through the following steps : 

    • Open your Project within the Solution Explorer
    • Right-click the References folder and Choose Add Reference....
    • Find and select the XXX library or assembly from the list provided (or by browsing to its existing location)
    • Click the Ok button to add it to your Project.
    • You should then be able to reference the XXX  namespace within your code through a using statement or otherwise.
    Thursday, October 17, 2013 4:42 PM
  • User-1842880510 posted

    Rion;

    Those steps are exactly the steps that I took.  I browsed to the actual location of the file.

    Mark;

    I have to put it in the bin directory because it will not otherwise be deployed with the project.  All of our deployments are Xcopy.  We are not allowed to add anything to the web server's GAC.  And the Copy Local option is already set to "True".  Overwritten by what?  This is the only version of that assembly anywhere.  Or are you suggesting it may be deleted? 

    This link on MSDN, http://msdn.microsoft.com/en-us/library/vstudio/ez524kew(v=vs.100).aspx says "In earlier versions of Visual Studio, you could set the CopyLocal property on a reference to ensure that the assembly was deployed. Now, you must manually add the assembly to the \Bin folder. ",   even when you use the property copyLocal.

    Thursday, October 17, 2013 4:50 PM
  • User-1842880510 posted

    I got this reply on Experts Exchange

    From the project properties, check whether it is targeting .NET Framework Client Profile.
    If yes, you may need to change it to appropriate .Net framework
    
    Hope this may helps.

    Because of this suggestion

    I checked the properties of the class library project.  Turns out that it was compiled as a .Net 4.5 project whereas the Web App was compiled as a .Net 4.0 project.  So I changed the class library to 4.0 and re-compiled it.  Then copied the new assembly to the the bin directory of the Web app.  I then opened the web app and it compiled quite nicely.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 18, 2013 8:43 AM