简体   繁体   English

无法解决含糊的引用

[英]Cannot resolve ambiguous reference

Apparently I have 3 dlls with the same namespace (however the object browser says it only exists in one). 显然我有3个具有相同名称空间的dll(但是对象浏览器说它仅存在于一个)。

Usually in Resharper I can automatically resolve a reference, but in this case it won't do it. 通常,在Resharper中,我可以自动解析参考,但是在这种情况下,它不会这样做。 The type in question is ItemEvents_10_Event and when I search for that type here's what comes up: 有问题的类型是ItemEvents_10_Event ,当我搜索该类型时,结果如下:

在此处输入图片说明

I've tried prefixing the interface with Microsoft.Interop.Outlook , but it still complains with the same message. 我尝试使用Microsoft.Interop.Outlook对该接口添加前缀,但是它仍然抱怨相同的消息。

Here's the usage in case that helps: 以下是在有帮助的情况下的用法:

((ItemEvents_10_Event)MailItem).Send += OnSend;
((ItemEvents_10_Event)MailItem).BeforeAttachmentAdd += BeforeAttachmentAdd;
((ItemEvents_10_Event)MailItem).Write += OnInspectorSaved;

Note that I do not get any compile or runtime errors (at runtime my method never gets invoked), however the class has squiggly red lines under them which alerts me there is an issue. 请注意,我没有得到任何编译或运行时错误(在运行时从未调用我的方法),但是该类下有波浪状的红线,提醒我有问题。

This may be a case of needing extern alias . 这可能是需要extern alias The error is occuring because you have 3 assemblies ( .dll s), that all contain the same class in the same namespace. 发生错误是因为您有3个程序集( .dll ),它们均在同一名称空间中包含相同的类。

In VS, select your reference that you want to use (Can be any of the 3), and give it an alias: 在VS中,选择要使用的引用(可以是3个中的任何一个),并为其指定别名: http://i.imgur.com/dLXahuC.png

You can then use this in your file as: 然后,您可以在文件中使用以下代码:

extern alias MyAlias;
using ItemEvents_10_Event = MyAlias::Microsoft.Office.Interop.Outlook.ItemEvents_10_Event;

This will use the ItemEvents_10_Event from the .dll with the alias. 这将使用别名来自.dll的ItemEvents_10_Event

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM