Asked  6 Months ago    Answers:  5   Viewed   46 times

I'm getting a:

type or namespace name could not be found

error for a C# WPF app in VS2010. This area of code was compiling fine, but suddenly I'm getting this error. I've tried removing the Project Reference and the using statement, shutting VS2010 and restarting, but still I have this issue.

Any ideas why this might be occurring, where it seems like I'm doing the right thing re Reference & using statement?

I also noted in VS2010 that intellisense for that namespace is working ok, so it seems like VS2010 has the project reference and is seeing the namespace on one hand, but during compile doesn't see it?



This can be the result of a .Net framework version incompatibility between two projects.

It can happen in two ways:

  1. a client profile project referencing a full framework project; or
  2. an older framework version targeting a newer framework version

For example it will happen when an application is set to target the .Net 4 Client Profile framework, and the project it references targets the full .Net 4 framework.

So to make that clearer:

  • Project A targets the Client Profile framework
  • Project A references Project B
  • Project B targets the full framework

The solution in this case is to either upgrade the framework target of the application (Project A), or downgrade the target of referenced assembly (Project B). It is okay for a full framework app to reference/consume a client profile framework assembly, but not the other way round (client profile cannot reference full framework targeted assembly).

Note that you can also get this error when you create a new project in VS2012 or VS2013 (which uses .Net 4.5 as the default framework) and:

  • the referencing project(s) use .Net 4.0 (this is common when you have migrated from VS2010 to VS2012 or VS2013 and you then add a new project)

  • the referenced projects use a greater version i.e. 4.5.1 or 4.5.3 (you've re-targeted your existing projects to the latest version, but VS still creates new projects targeting v4.5, and you then reference those older projects from the new project)

Tuesday, June 1, 2021
answered 6 Months ago

This is the problem:

C:UsersNoobcsharp>csc test.cs

You haven't added a reference to the DLL. You need something like:

C:UsersNoobcsharp>csc test.cs /r:SnarlNetwork.dll

(or whatever the assembly is called).

Alternatively, if you haven't got it as a separate library, just compile both files:

C:UsersNoobcsharp>csc test.cs SnarlNetwork.cs

If you haven't compiled an assembly but want to, you can use:

csc /target:library /out:SnarlNetwork.dll SnarlNetwork.cs

csc Test.cs /r:SnarlNetwork.dll

(In fact, specifying the output file is unnecessary in this particular case, but it's still clearer...)

Wednesday, June 30, 2021
answered 5 Months ago

The issue is that the reference name takes on the project name. It's still referencing the DLL by the appropriate name (A.Core.dll or B.Core.dll), but the reference uses the project name inside VS:

enter image description here

If you look at the project file after adding a reference to A.Core, you'll see this:

<ProjectReference Include="..ClassLibrary1Core.csproj">

Change the Name value to A.Core and you'll be unblocked. (B.Core will still show up as "Core" until you edit it as well.)

Wednesday, August 4, 2021
answered 4 Months ago


using System.Windows.Media.Imaging.BitmapImage;

Instead of

using BitmapImage;

An easier way is to let Visual Studio do it for you : Right click on BitmapImage in your code -> resolve, and select the right namespace (there is generaly only one)

For the xaml, let Visual studio do it for you too, or :

<Page ...
Monday, August 23, 2021
answered 3 Months ago

Even if you post-build-copy the app.config it will not solve your problem. The application is still a web app, so the config system will use the web.config file. The settings will need to go in there one way or another. One way to still keep those settings a bit separate is to put them into a custom config section, and then put the settings for this section into a separate file. It will still need to be referenced from the web.config though (using a configSource attribute).

Tuesday, October 26, 2021
Paulo Calado
answered 1 Month ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :