Web Reference namespace not seen by Visual Studio 2010 compiler after 2.0 to 3.5 project conversion

4.6k views Asked by At

I'm getting a build error in Visual Studio that's not making any sense:

The type or namespace name 'MyService' does not exist in the namespace 'My.Project' (are you missing an assembly reference?)

The namespace MyService is defined in a Web Reference. In the Object Browser, I can clearly see that namespace and all of the classes defined in it. There are no compile errors for any of the code in the Web Reference.

The code stopped compiling after I changed the framework target from 2.0 to 3.5. Why could the compiler be choking, and how can I go about fixing this? I already tried updating the web reference, but the problem remains. I even tried commenting out the code in the generated "Reference.cs" and copying the code to another code file in the project, and the namespace was still not seen.

My project is referencing the following:

System                     2.0.0.0
System.Data                2.0.0.0
System.EnterpriseServices  2.0.0.0
System.Net                 3.5.0.0
System.Web.Services        2.0.0.0
System.Xml                 2.0.0.0

Update

It isn't just my web service generated code that is having compile problems; for all of the projects converted to .NET 3.5, I cannot reference their namespaces.

I'm still not sure why this is all happening, but I found a workaround; by adding a using Ns = My.Project.MyService to my code, I was able to reference types in the namespace with Ns.MyType.

1

There are 1 answers

0
Jacob On BEST ANSWER

This is apparently documented as a bug in Visual Studio:

https://connect.microsoft.com/VisualStudio/feedback/details/570557/targeting-net-framework-3-5-actually-targets-3-0-gac

I utilized the workaround documented in the post by copying System.Web.Extensions.dll from C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5 to C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0. Then I restarted Visual Studio.

That alone didn't fix the problem. I had to redo the project conversion from 2.0 to 3.5 after the assembly was copied. After the new conversion, the code compiled as expected. Doing a diff between the project file pre- and post-workaround didn't reveal any substantial differences, so the build errors must have been due to some internal state of Visual Studio.