Why can Visual Studio detect which "using" is needed, but then say the type or class which provoked the addition of the reference does not exist?

StackOverflow https://stackoverflow.com/questions/17432960

Question

On trying to build, all of a sudden (a couple of days since I worked on this project) I get:

"The type or namespace name 'IO' does not exist in the class or namespace 'OpenNETCF' (are you missing an assembly reference?)"

But when I comment out that line (using OpenNETCF.IO.Ports;), I get:

? OpenNETCF.IO.Ports.Handshake (multiple choices...)?

When I click that, the choices are two:

OpenNETCF.IO.Ports.Handshake 
- and:
OpenNETCF.IO.Serial.Handshake

As the code in this unit deals with printing, I select "Ports" (rejecting "Serial" because of its yin/yanginess to "Parallel"). So it then adds back the using I had which it complained about (using OpenNETCF.IO.Ports)...and then it's back to the original err msg.

Yet I do have several OpenNETCF items in my References, namely:

OpenNETCF
OpenNETCF.Data
OpenNETCF.Drawing
OpenNETCF.Net
OpenNETCF.Phone
OpenNETCF.VisualBasic // I don't know why, this is a C# project
OpenNETCF.Web.Services2
OpenNETCF.Windows.Forms
OpenNETCF.WindowsCE.Forms
OpenNETCF.Xml

What could possibly cause this chicken-and-egg tail-chasing exercise in frustration?

Odder yet, I get, "The type or namespace name 'Windows' does not exist in the class or namespace 'OpenNETCF' (are you missing an assembly reference?)" pointing to this using in another .cs file:

using OpenNETCF.Windows.Forms;

...and yet that using is grayed out as being unused at any rate, but when I comment it out, I get a lot of other errors purportedly because it's gone, such as on this line:

IntPtr hwnd  = OpenNETCF.Win32.Win32Window.GetCapture();

The type or namespace name 'Win32Window' does not exist in the class or namespace 'OpenNETCF.Win32' (are you missing an assembly reference?)

UPDATE

In another episode of "Well Flip My Bits!" I just now compiled, got those err msgs about not being able to reconcile this line of code with what is installed and configured, etc., scrolled up to see that the "using" it was supposedly missing was there, compiled again, and now it compiles fine. What the blue blazes?!?!?!?

Was it helpful?

Solution

This sounds like a problem you see when you are building a project for a "Client Profile" .net version while referencing assemblies that are not supported in client profile.

Try changing your project's build settings to use a .net framework version that is not "Client Profile".

OTHER TIPS

One can use the namespace using inside class also, so consider moving it there, if there are classes that use both than use the full name as in OpenNETCF.IO.Ports.Handshake handshake = new OpenNETCF.IO.Ports.Handshake()

And for the class using namespace:

using System;

namespace MyNamespace
{
    using OpenNETCF.IO.Ports;

    //...
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top