18

I have a solution that has one class library project, and the others are WPF applications. I have added class library's reference the but, but both of them cannot use its classes.

So, what is the problem?

NOTE: sorry for tags, it's safari's problem.

TrueWill
  • 25,132
  • 10
  • 101
  • 150
Kaan
  • 902
  • 2
  • 16
  • 38
  • have you tried to use reflector to check your library assembly to see everything is right? – treehouse Nov 30 '10 at 15:56
  • @Kaan: What do you mean by "cannot use its classes"? Did you get compiler errors? – treehouse Nov 30 '10 at 21:35
  • Yes, I'm getting compiler error: "The type or namespace name 'Core' does not exist in the namespace 'lt' (are you missing an assembly reference?)" – Kaan Dec 01 '10 at 08:46
  • I realized that when I click "Clean Solution" button then it doesn't give an error but after I pressed Build it start to give me the errors. There is the error: http://img826.imageshack.us/img826/4823/errornf.png – Kaan Dec 01 '10 at 09:09
  • found that if I add ADO.NET Entity Data Model to the class library, it starts to give me error. It contunies, although I removed it from class library. – Kaan Dec 01 '10 at 09:56

4 Answers4

79

Make sure that all your projects target same Framework. It may be a case that your library class project targets full .Net Framework 4.0 while your wpf projects target .Net Framework 4.0 Client Profile.

To do that go to project properties of each project in a solution and check Application | Target Framework property. Alternatively you can download VSCommands 2010 extension and see all properties in one place via Solution Properties window.

Registered User
  • 1,630
  • 14
  • 11
2

I got the same problem, but the solution was different...

We work in team and one of the developers (called dev1) installed the .NET 4.5 (the others has only the .NET 4.0). After dev1 made some changes in the solution the others got the problem, and colud't build. The project referrences didn't work (but if they used it like a dll it worked)... So we install the .NET 4.5 for everybody and it resolved the prolem.

Moha

Moha
  • 181
  • 1
  • 5
2

Things to check:

  • The class library classes are public
  • You have an appropriate using directive in your calling code:

    using MyCompany.ClassLibrary;
    

If that doesn't help, please post what happens when you try to use the classes from the library.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • 2
    All of them are public and I'm already defined using statement. I realized that, if I remove and then add reference it is ok until I hit the Build button. Then errors comes again. I have created another solution and moved codes by cop and paste (not direclty copy file) again problem continues. I think I have a problem with VS but I have also tried it with another computer that has same version of VS – Kaan Nov 30 '10 at 14:28
  • Have the exact same problem here. I only want to add that when I first add the project to the reference and start typing in the using directive, visual studio even finds that project for me (with its IntelliSense thing). I then clean, and re-build, and then it can't find the type or namespace. Same as Kaan describes. – justian17 Jul 01 '14 at 21:03
  • @Ilia. Where is the class library? – Jon Skeet Jul 01 '14 at 21:08
  • @JonSkeet; it was added under "References" to the current project; all of its classes had the correct namespace, too... The answer below regarding the project framework solved this problem for me. Thanks =) – justian17 Jul 02 '14 at 11:58
-1

Found the problem. One of my references in class library has caused it, and I have removed it. Now I can built the solution without errors.

Thanks for your comments..

Kaan
  • 902
  • 2
  • 16
  • 38