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条回答
Root(大扎)
2楼-- · 2019-01-02 23:14

Check to see that your target framework has the same .NET versions. I had the same problem and my class .NET was 3.5 and web solution had 4.5. I synchronised those, and then it worked :)

查看更多
闹够了就滚
3楼-- · 2019-01-02 23:15

I had an issue with System.Linq not being recognized. The using statement had a red squiggly, etc. The way I solved it was to change my website to target dotnet 3.5, then switch back to the original targeted framework (4.0 in my case).

查看更多
趁早两清
4楼-- · 2019-01-02 23:15

FOR ANYONE WITH LINKED FILES: I had this problem and was using silverlight and the offending file that was throwing this error was a linked file.

The error from the compiler told me the error was happening in the project that the file lived in. It ended up that the error was NOT in that project, it was occurring in the project that contained the linked file. That project was missing a reference.

查看更多
看我几分像从前
5楼-- · 2019-01-02 23:18

I found that this is caused by me having the same namespace name as class name (MyWorld.MyWorld = Namespace.ClassName).

Change your namespace to a name that is not the same name as your class and this will compile.

Source

查看更多
地球回转人心会变
6楼-- · 2019-01-02 23:18

Delete the .refresh.dll file if you are under source control. Then rebuild. It should work. This worked for me

查看更多
登录 后发表回答