1

I am writing a wrapper around two different versions of a communication library that work with different versions of my company's database. These communication libraries have classes with identical fully-qualified names, so I am loading the references into different aliases; I've tried it with one or the other in the global alias and with both in non-global aliases, and in both cases Visual Studio 2012 complains that I have compile errors. In specific, in both of my wrapper classes, I am fetching a connection from a factory method

extern alias MyAliasVersionX;
using MyAliasVersionX::Example.MyNamespace;
...
private Connection _connection;
...
_connection = Connection.Create(environmentName); // this returns an Example.MyNamespace.Connection--but this is where the compile error happens

The code is virtually identical in both classes; the biggest difference is the version on the alias in the using statement at the top. In one class (it appears to be whichever reference is listed first), everything works fine, no error. In the other class, Visual Studio tells me that the line noted above will produce a compile error because Connection.Create() returns the other version of Connection object (i.e., MyAliasVersionY::Example.MyNamespace.Connection instead of MyAliasVersionX::Example.MyNamespace.Connection).

Here's the important part: when I actually Build the project, it compiles fine and runs fine, and the error showing in the Error List pane disappears... until I make any change to the code, at which point it comes back, still never causing a Build error.

Is this a bug in Visual Studio? If not, what am I missing?

4

1 回答 1

2

据微软称,这是 Visual Studio 中的一个错误,可以追溯到 VS-2008。在 VB.NET/C# 编辑(称为“Roslyn”)的大修发布之前,它可能不会得到修复。(如果您对此不满意,请在下方支持我的 Connect 反馈,让 Microsoft 知道!)

https://connect.microsoft.com/VisualStudio/feedback/details/786107/visual-studio-shows-error-cs0029-for-types-in-non-global-alias

于 2013-05-09T22:30:00.047 回答