本文介绍了调试错误“类型”xx“在未被引用的组件中定义”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

完整的错误如下:

,它指向不需要系统的库项目中第一个类的第一个语句(一个Debug.Assert行) .Windows.Forms (或许我以为)。我知道如何解决它:添加提到的参考。但是如何找出什么库导致这个错误,或者更好的是什么部分代码触发使用WinForms库?

and it points at the very first statement (an Debug.Assert line) in the very first class in a library project that doesn't need System.Windows.Forms (or so I thought). I know how to solve it: add the mentioned reference. But how do I find out what library is causing this error, or better, what part of the code triggers using the WinForms library?

通常,您可以添加引用的库其他人,但您只需要在实际使用时添加对这些其他人的引用。

Normally, you can add libraries that reference others, but you only need to add references to these others when they're actually used.

这个或类似的问题也可以使用。它显示了您的应用程序绑定的所有尝试和组件的成功。

This or similar problems can also be resolved using the Binding Log Viewer Fuslogvw.exe from Microsoft's Framework Tools. It shows all attempts and successes of assemblies your application binds to.

推荐答案

我怀疑你的代码没有一行这是因为你说你没有使用System.Windows.Forms类型,编译器错误并不指向你的代码的一个(有用的)一行。

I suspect there's no line of your code that's causing this, since you say you aren't making use of the System.Windows.Forms types and the compiler error isn't pointing to a (useful) line of your code.

我认为发生的是你引用一个具有公开可见的方法或属性的库,它返回一个System.Windows.Forms.Control或者一个作为参数。您是否真的最终调用该方法/属性无关紧要,因为它的公开显示意味着您自己的代码必须能够解析库正在使用的所有类型。如果图书馆只使用System.Windows.Forms 内部,那么你不会遇到这种情况。

What I think is happening is that you're referencing a library which has a publicly-visible method or property that either returns a System.Windows.Forms.Control or takes one as a parameter. It doesn't matter whether you actually end up calling that method/property, the fact that it's publically visible means that your own code has to be able to resolve all the types that the library is using. If the library only used System.Windows.Forms internally, you wouldn't be experiencing this.

这也意味着只要看依赖关系您所依赖的程序集可能只会缩小疑犯列表,因为可能会有一些程序集内部依赖于System.Windows.Forms(没有问题)和一个具有公共参数/返回值的故障排除程序集一个来自SWForms程序集的类型。

It also means just looking at the dependencies of the assemblies you're depending on may merely narrow down the list of suspects, since there could be some assemblies that depend on System.Windows.Forms internally (no problem) and the one troublemaking assembly that has a public parameter / return value of a type from the S.W.Forms assembly.

我的建议是您只是设置一个空项目而不引用SWForms,然后依次添加每个依赖项在每一个之后编译。

My suggestion is you just set up an empty project without a reference to S.W.Forms, then add each of your dependencies in turn and try to compile after each one.

这篇关于调试错误“类型”xx“在未被引用的组件中定义”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 16:42