Type or namespace name does not exist [closed]

2019-01-02 22:27发布

I have a WCF Data Service project built with Visual Studio 2010, which was working fine. All of a sudden, it didn't compile anymore. It was giving me messages like:

Error 7 The type or namespace name 'Services' does not exist in the namespace 'System.Data' (are you missing an assembly reference?) C:\U...s\Visual Studio 2010\Projects...\DataService.cs ...

Error 8 The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?) DependencyResolver.cs 3 14

Error 10 The type or namespace name 'Web' does not exist in the namespace 'System.ServiceModel' (are you missing an assembly reference?)

Error 12 The type or namespace name 'DataService' could not be found (are you missing a using directive or an assembly reference?)

How can I fix it?

17条回答
可以哭但决不认输i
2楼-- · 2019-01-02 23:09

And if all else fails, such as ensuring that the target frameworks are the same, and you are dealing with a WPF class library in VS2010, simply restart Visual Studio. That did it for me.

查看更多
Ridiculous、
3楼-- · 2019-01-02 23:10

In my case there was no change in projects, it just stopped to compile and with "type or namespace name XXX does not exist" and in the complaining class itself intellisense for that XXX namespace/class works fine. The problem was in references indeed!

Steps to reproduce:

  1. Solution has ProjectA, ProjectB. ProjectA references to third party log4net and it is marked Copy local: true. ProjectB references ProjectA and does not have reference to log4net. Solution compiles fine.

  2. Change in ProjectA: reference property for log4net to Copy local: false.

  3. Clean bin and obj folders.
  4. When you compile, ProjectA compiles but ProjectB complains about not finding ProjectA namespace.

This is because ProjectB bin folder is missing third party library (log4net in my case)!

In this case solution would be -

  1. make sure that third party libraries references are set to Copy local: true or
  2. add path to such libraries in project properties under reference path.
查看更多
女痞
4楼-- · 2019-01-02 23:10

I am referencing Microsoft.CommerceServer.Runtime.Orders and experienced this error. This project is old and has Target framework .NET 2.0. In output I had this error:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1605,5): warning MSB3268: The primary reference "Microsoft.CommerceServer.Runtime" could not be resolved because it has an indirect dependency on the framework assembly "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "Microsoft.CommerceServer.Runtime" or retarget your application to a framework version which contains "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

I simply changed the target framework to .NET 4 and now it builds.

查看更多
Evening l夕情丶
5楼-- · 2019-01-02 23:12

I encountered this problem while using Visual Studio's Git integration to manage the project. For some reason the Windows Phone 8 project would compile just fine when targeting x86, but when I set it to target ARM, it would fail compiling with an error indicating that "Advertising" didn't exist in the Microsoft namespace.

I ended up resolving the issue by removing the Microsoft.Advertising.*.dll reference and adding it again.

查看更多
叛逆
6楼-- · 2019-01-02 23:13

I got a very similar error message that was caused by inadvertently having made a duplicate of a class in another project of my solution. Deleting the duplicate fixed the issue

查看更多
小情绪 Triste *
7楼-- · 2019-01-02 23:14

I have had the same problem, and I had to set the "Target Framework" of all the projects to be the same. Then it built fine. On the Project menu, click ProjectName Properties. Click the compile tab. Click Advanced Compile Options. In the Target Framework, choose your desired framework.

查看更多
登录 后发表回答