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条回答
Animai°情兽
2楼-- · 2019-01-02 22:51

I faced the same issue with an ASP.NET MVC site when I tried to use LINQ to SQL. I fixed the problem by:

Solution Explorer -> References -> Right-click on System.Data.Linq -> Copy Local (True)

查看更多
对你真心纯属浪费
3楼-- · 2019-01-02 22:53

I had the same problem and tried all of the above without any success, then I found out what it was:

I'd created a folder called "System" in one of my projects and then created a class in it. The problem seems to stem from having a namespace called "System" when the .cs file is created, even if it is in a namespace of "MyProject.System".

Looking back I can understand why this would cause problems. It really stumped me at first as the error messages don't initially seem to relate to the problem.

查看更多
我只想做你的唯一
4楼-- · 2019-01-02 22:55

I experienced the same errors. After I discovered my project had the wrong Assembly name (I copied files from a different project and the namespaces got a little confused), and changed it back, the project compiled nicely.

查看更多
成全新的幸福
5楼-- · 2019-01-02 22:57

In my case the problem was happening because the class I created had a namespace that interfered with existing classes. The new class A had namespace zz.yy.xx (by mistake). References to objects in another namespace yy.xx were not compiling in class A or other classes whose namespace was zz.

I changed the namespace of class A to yy.xx , which it should have been, and it started working.

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

I have experienced same problem with System.Data.SQLite. The source of the problem is the dll you have used should have same .NET version with your project.

For example if you have used (in my case) SQLite for .NET 4.5, your platform target should be .NET 4.5 too.

You can find platform target by: Project > (project name) Properties > Build.

查看更多
叛逆
7楼-- · 2019-01-02 23:06

I recently needed to do a System Restore and it caused several of my files to change/disappear that I had been working on since the restore. Some of those were DLL files. I used Source Control to retrieve the entire project but I still had a similar issue as above. I found this answer that described you may need to remove a DLL and readd it to get your errors fixed. This was the case in my scenario.

Removing WebMatrix.WebData and readding it as well as adding in WebMatrix.Data fixed my error of The type or namespace name 'Data' does not exist in the namespace 'WebMatrix' ....

查看更多
登录 后发表回答