我已经成功复现了一个错误,并在一个类似于生产代码结构的测试项目中进行了测试。它由三个简单的项目组成:
Common(类库):
namespace Common
{
public enum PrimaryColor
{
Red,
Green,
Blue
};
}
Library(WCF服务库),它引用了Common:
using Common;
namespace Library
{
[ServiceContract]
public interface ILibrary
{
[OperationContract]
PrimaryColor GetColor();
}
public class Library : ILibrary
{
public PrimaryColor GetColor()
{
return PrimaryColor.Red;
}
}
}
ClientApp(控制台应用程序),它引用了Common,并且具有对名为“LibraryServiceReference”的Library的服务引用:
using Common;
using ClientApp.LibraryServiceReference;
namespace ClientApp
{
class Program
{
static void Main(string[] args)
{
LibraryClient client = new LibraryClient("WSHttpBinding_ILibrary");
PrimaryColor color = client.GetColor();
}
}
}
ClientApp和Library中的app.config文件是自动生成的,我没有修改过它们,并且我没有更改ClientApp中LibraryServiceReference的默认配置。
当我编译这个解决方案时,我在ClientApp项目中遇到了以下错误:
Error 1
'PrimaryColor' is an ambiguous reference between 'Common.PrimaryColor' and 'ClientApp.LibraryServiceReference.PrimaryColor'
错误 2
Cannot implicitly convert type 'ClientApp.LibraryServiceReference.PrimaryColor' to 'Common.PrimaryColor'. An explicit conversion exists (are you missing a cast?)
请帮我解决这个问题。