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

  • Question

  • I have seen posts regarding this error message many time but none of them gives the answer to the problem. I will try to explain what happens very simple. I have 64 bit Windows 7, Visual Studio 2010.  I created an empty solution.
    I added existing Class Library Project to the solution, lets call it ClassLibrary1.
    I added a new Console application to the solution, lets call it ConsoleApplication1.
    In ConsoleApplication1 I clicked <Add Reference> and added a reference ClassLibrary1 project.
    Now... the problem - I cannot use code in ClassLibrary1.
    When, in ConsoleApplication1 I type:
    ClassLibrary1.Class1 c1 = new ClassLibrary1.Class1();
    it is not working, namespace is not recognized and code in ClassLibrary1 is inaccessible. Same happens when I try to add a using directive for ClassLibrary1 namespace.

    I simplified the code to show the problem, but that is what happens.

    Details: ClassLibrary1 was created in VS2008 and target framework is set to .NET 3.5. ConsoleApplication1, I just created. I thought this problem comes from the difference in target framework, which is 4.0 in ConsoleApplication1. So, I changed target framework for ConsoleApplication1 to .NET 3.5, same as ClassLibrary1.

    But it didn't solve the problem. I have spent many days trying to figure out what the problem is, but unsuccessfully, since everything seems absolutely normal to me. I broke my brain :) Strangely, such behavior is random - sometime it works fine and sees all the references and namespaces, but sometimes it throws that weird exception, even if no change was done to the code.

    I anyone has ANY ideas what is wrong here I would really appreciate any advice. Cause I am stuck here :(

     

     

     

     

     


    • Moved by spacewrangler Tuesday, August 2, 2011 5:13 AM (From:Building Development and Diagnostic Tools for .Net)
    Saturday, July 23, 2011 4:25 PM

Answers

All replies

  • Everything you describe sounds like it should work; so without being able to see code I am going to go off on a limb and ask have you made the class public

    PS. Don't shoot the messenger...

    Sunday, July 24, 2011 9:27 AM
  • Yes, everything's public of course. The code I cant present but it worked just fine. This anomaly occurs sometimes, and now it's bugging me for quite some time :)

    First time when I experienced it, the problem was in difference between target platform, where class library was compiled in .NET 3.5, and the console app in 4.0 client profile. When I changed it to 3.5 everything began to work, namespaces are recognized, etc... But after a few days (without any change to any code) same problem came back. I realized that changing target platform was not an issue. Some said that deleting bin, obj folders and rebuilding the project again helps sometimes, not in my case.

    The weird fact is that the class library project property / Build tab says platform "Any CPU", but for console app I added, it says "x86". And there is no way to change it. Have no idea why... I am running 64-bit Windows 7 as I said before. Maybe that could be the reason. I fount on MS bug reporting site that target platform being set to "x86" was reported as a bug, and no solution have been found and fixes.

    Weird stuff  to say the least.

    Sunday, July 24, 2011 1:11 PM
  • You should be able to add a new platform by going to Build/Configuration Manager and then choose new from the Active Solution Platform drop down. However I don't think it is that. causing your problems.

    I have never encountered such an issue personally so I can only guess but there is so little to go on; if you can post a sample that replicates the problem then you may get someone to help.

    Sunday, July 24, 2011 9:44 PM
  • Is that library accessible all the time ?

    Can you place the library file under your console application's bin folder and reference from there ?


    Malayalam SMS Website http://smsmallu.brinkster.net
    Monday, July 25, 2011 7:17 AM
  • I have this problem too---I am in .Net 4.0, and created a new console app which refers to a library which is compiled as "AnyCPU".  I had to add "Any CPU" in the console app from the Properties -> Build menu because the Configuration Manager's only option was x86.

    However, when I try to compile it, it says "The type or namespace name 'MyLibrary' could not be found".  I have several non-console apps which link to this library successfully, so I don't know what's causing it to fail.

    Did you ever find a solution to this?

    Tuesday, April 10, 2012 5:02 PM
  • It is hard to guess the problem. Can you please upload your project if possible? May be to https://skydrive.live.com/  ?


    Please mark this post as answer if it solved your problem. Happy Programming!

    Tuesday, April 10, 2012 5:50 PM
  • Ok, I fixed this in my project.  The problem seems to be that there were some transitive dependencies on System.Web, System.Data, etc. which weren't being included in the console application:

    http://connect.microsoft.com/VisualStudio/feedback/details/510573/referenced-assembly-could-not-be-resolved-because-it-has-a-dependency-conflict

    These missing dependencies were appearing in the warnings, but not reflected in the error messages.

    The fix is to right-click on the project, select "Properties", then the "Application" tab and change the Target Framework from".Net Framework 4 Client Profile" to ".NET Framework 4".

    See also:

    http://stackoverflow.com/questions/4880685/c-sharp-visual-studio-2010-suddenly-cant-see-namespace

    -Mike


    Tuesday, April 10, 2012 5:54 PM
  • it helps me in case of Umbraco.
    my application was on .Net FrameWork 4.0 
    umbraco previous version was using .Net FrameWork 4.0
    so i was try to use new release of Umbraco 7.0.1 on same FrameWork after reading your post i check for .netFramework for new release i found 4.5 so i upgrade my application to 4.5 it resolve the issue.

    thanks.
    Monday, December 23, 2013 7:06 AM
  • it helps me in case of Umbraco.
    my application was on .Net FrameWork 4.0 
    umbraco previous version was using .Net FrameWork 4.0
    so i was try to use new release of Umbraco 7.0.1 on same FrameWork after reading your post i check for .netFramework for new release i found 4.5 so i upgrade my application to 4.5 it resolve the issue.

    thanks.
    Monday, December 23, 2013 7:07 AM