WCF 和客户端应用程序中的不明确引用 [英] Ambiguous reference in WCF and client application
问题描述
我设法在一个测试项目中重现了一个错误,其结构与我的生产代码相似.它由三个简单的项目组成:
I've managed to reproduce one of the errors in a test project with a similar structure to my production code. It consists of three simple projects:
通用(类库):
namespace Common
{
public enum PrimaryColor
{
Red,
Green,
Blue
};
}
Library(WCF 服务库),其中引用了 Common:
Library (WCF service library), which has a reference to 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"的库的服务引用:
ClientApp (console application), which has a reference to Common, and a service reference to Library called "LibraryServiceReference":
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 的默认配置.
The app.config files in ClientApp and Library are auto-generated and I have not modified them, and I have not changed the default configuration for the LibraryServiceReference in ClientApp.
当我编译此解决方案时,我在 ClientApp 项目中收到以下错误:
When I compile this solution, I get the following errors in the ClientApp project:
错误 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?)
请帮我解决这个问题.
推荐答案
确保在高级选项中选择在所有引用的程序集中重用类型strong>添加服务引用或配置服务引用.
Make sure that 'Reuse types in all referenced assemblies' is selected in the Advanced options of Add service reference or Configure Service Reference.
这篇关于WCF 和客户端应用程序中的不明确引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!