开发者

Visual Studio extending namespace to produce error

I've encountered a problem in Visual Studio 2008 where recompiling a library project has Visual Studio to be unable to resolve the namespace. The problem is that Visual Studio is extending the namespace unnecessarily. For example, I have a cast like

... = (MyCompany.Dashboard.Data.BaseObjects.ZonesStruct) value;

which has compiled fine in the past suddenly begins to fail when recompiling. Visual Studio is unable to resolve it and gives an error message "The type or namespace name 'Data' does not exist in the namespace 'MyCompany.MyCompany.Dashboard'...". The change that kicked this off was adding a new class to the library. The classes that are failing are existing and untouched classes.

I've encountered something similar once before, but that was the UI designer producing code that was explicitly qualified as "MyCompany.MyCompany...". I'm hoping the root cause is the same in both situations.

Not sure if it's useful or not, but the default namespace of the library project is "MyCompany". I've tried modifying that, but I didn't notice any changes开发者_JAVA百科.

Thanks.


Change it to this

global::MyCompany.Dashboard.Data.BaseObjects.ZonesStruct

The global:: escapes the namespace all the way out to the root namespace. This isn't a Visual Studio issue, it's a conflicting namespace issue.


This doesn't address the problem, just the symptom. But you could try ensuring that the namespace you have is in the global scope to start with by using

... = (global::MyCompany.Dashboard.Data.BaseObjects.ZoneStruct) value;

See MSDN for more information on the global keyword: http://msdn.microsoft.com/en-us/library/c3ay4x3d.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜