存在于2型组件 [英] Type exists in 2 assemblies

查看:171
本文介绍了存在于2型组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从两个不同的第三方COM DLL文件创建了两个.NET互操作程序集。无论是COM的DLL包含一个名为 COMMONTYPE 类型。因此, COMMONTYPE 现在通过两个互操作程序集公开为好。

I have created two .NET Interop assemblies from two different third-party COM DLLs. Both of the COM DLLs contained a type named COMMONTYPE. Therefore, COMMONTYPE is now exposed through the two Interop assemblies as well.

我的第三个项目,需要使用这两个互操作程序集,我也得到了臭名昭著的编译时错误:

I have a third project that needs to use these two Interop assemblies, and I get the infamous compile time error:

键入< ABC> 同时存在于< ASSEMBLY1.dll> < ASSEMBLY2.dll>

由于COM DLL是由第三方供应商提供的,我要的源代码不能访问了,我正在写一个C#控制台应用程序,这意味着我没有web.config文件,我可以添加调试=假解决方法。我该怎么办?

Since the COM DLLs are provided by a third-party vendor, I have no access to the source code, and I'm writing a C# Console application, which means I have no web.config file where I could add the debug=false workaround. What can I do?

推荐答案

我知道这是旧的,但有比上市更简单的方法。当引用两个组件的份额类型与在精确相同的名称和命名空间这个工作。

I know this is old, but there's an easier way than the listed. This works when you reference two assemblies that share types with the exact same name and namespace.

如果你的权利上单击鼠标右键参考你的DLL和选择化子性质,你会看到这里有一个被称为别名

If you right-click on the Reference to your DLL and select Propeties, you will see that here's a property called "Aliases"

默认值为全局。对于冲突的组件之一将其更改为任何其他值。在下面的例子中,我从地球到目的地改变了它。

The default value is "global". For one of the conflicting assemblies change this to any other value. In the example below, I've changed it from "global" to "destination".

接下来,在你的代码文件,你将不得不使用的 extern关键字使用此别名作为的根级别命名空间的这些类型。在这个例子中,你会发生在你的cs文件的顶部以下内容:

Next, in your code file, you will have to use the extern keyword to use this alias as the root-level namespace for these types. In this example, you would place the following at the top of your .cs file:

extern alias destination

现在,在此文件中,可以参考两种类型。

Now, within this file, you can reference both types.

extern alias destination;
namespace Test
{
    public static class TestClass
    {
        public static void Success()
        {
            var foo = destination::Some.Duplicate.Namespace.SomeDuplicateType();
            var bar = Some.Duplicate.Namespace.SomeDuplicateType();
        }
    }
}

这篇关于存在于2型组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆