如何消除歧义键入监视窗口时,有两种类型的具有相同名称 [英] How to disambiguate type in watch window when there are two types with the same name

查看:177
本文介绍了如何消除歧义键入监视窗口时,有两种类型的具有相同名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在监视窗口,我想看看 TaskScheduler.Current ,但它表明我以下错误:

In the watch window, I'm trying to look at TaskScheduler.Current, but it shows me the following error:

The type 'System.Threading.Tasks.TaskScheduler' exists in both 
'CommonLanguageRuntimeLibrary' and 'System.Threading.dll'   

这是真的对我的计划,因为:

This is true for my program since:


  • 这是一个.NET 4.0的exe它使用了的TaskScheduler 出的mscorlib的(CommonLanguageRuntimeLibrary)

  • DLL是通过后期带来结合它引用一个老反应扩展.NET 3.5 System.Threading.dll其中也有的TaskScheduler 在相同的命名空间。

  • This is a .NET 4.0 exe which uses the TaskScheduler out of mscorlib (CommonLanguageRuntimeLibrary)
  • A dll is brought in through late binding which references an old Reactive Extensions .NET 3.5 System.Threading.dll which also has TaskScheduler in the same namespace.

问:我可以在调试器中使用什么样的语法来指定的DLL中的的TaskScheduler 我要?检查

Question: What syntax can I use in the debugger to specify the dll of the TaskScheduler I want to inspect?

顺便说一句:我假设有在有这两个同名的类型方面没有问题(即没有明确的行为)被带入同一个可执行文件,右?

As an aside: I assume there is no issue (i.e. no undefined behavior) in terms of having these two identically named types being brought into the same executable, right?

推荐答案

我不知道,如果这个工程通过观察窗口(但我不明白为什么它不应该,谁知道) - 但一直到两个DLL-S与同类型使用外部别名之间的歧义。

I'm not sure if this works through the watch window (but I don't see why it shouldn't, who knows) - but the way to disambiguate between two dll-s with same types is using extern alias.

这是同样的事情作为全球:: - 只是在这种情况下,你可以使用指定的DLL别名。

That's the same thing as the global:: - except that in this case you can use to specify dll aliases.

您可以通过设置/在DLL
的参考定义别名自己使用它(我认为这是在别名字段有属性)。

You can use it by setting / defining alias yourself on the dll reference (I think there is alias field there in the properties).

两个不同的DLL具有相同的命名空间

我不知道这是否完全适用于你的情况,也就是说,如果你能要做到这一点,但你必须要尝试一下在你自己的情况。

I'm not sure if this entirely applies to your case, i.e. if you are able to do that, but you'll have to try it out in your own case.

编辑:(基于评论)

由于细节 - 我试着它在我的调试器。由于另一种是后期绑定 - 编译器不知道它(当然,因为它不会工作)。

Given specifics - I tried it in my debugger. Since the other one is late-binding - compiler doesn't know about it (of course, as it wouldn't work).

因此,在你的源代码(在这里你需要做的工作表的.cs)添加在顶部例如

So in your source code (.cs where you need to do the watch anyway) add at the top e.g.

using mysystem = global::System.Threading.Tasks.TaskScheduler;  



然后在表 mysystem.Current (我立足在我的例子)

Then in the watch mysystem.Current (I'm basing it on my example)

或...

using mytasks = global::System.Threading.Tasks;  

mytasks.TaskScheduler - 不事情真的哪一个真的。

and mytasks.TaskScheduler - doesn't matter really which one really.

EDIT2:结果
和历史的原因 - 我有种证实,代码编辑是不可避免的。


And for historical reasons - I kind of confirmed that code-editing is unavoidable.

1)从项目中删除 mscorlib程序 - 项目设置,构建先进。

1) remove mscorlib from the project - project, setting, build, advanced.

2),卸载和编辑项目配置手动 - 添加mscorlib程序引用(通过增加VS不允许)。还需要其他修复了WPF应用程序(超出范围在这里),

2) unload and edit project configuration manually - add the mscorlib reference (adding through VS is not allowed). Also another fix is required for WPF apps (out of scope here),

3)添加别名mscorlib程序 - 你可以添加多个的,独立的瓦特/ ,工作正常,

3) add aliases for mscorlib - you can add multiple ones, separate w/ ,, that works fine,

4)添加外部别名<您的别名>

从这一点,你可以参考它的调试器 - 但没有放弃手动代码编辑方式。同时外部别名是每个建设单位,即文件,所以没有全球性的。

from that point you can reference it in debugger - but there is not way of forgoing the manual code editing. Also extern alias is per 'building unit', i.e. file, so nothing global.

在短,这是我们能做的最好的,恕我直言。

In short, that's the best we could do, IMHO.

和来自@JaredPar对这个结果
确认的How可以出线与汇编名字Visual Studio调试.NET类型,而用暧昧的类型进行区分?

And a confirmation from @JaredPar on this
How can I qualify a .NET type with assembly name for Visual Studio debugger to disambiguate while using an ambiguous type?

这篇关于如何消除歧义键入监视窗口时,有两种类型的具有相同名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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