wpf 奇怪的错误 - CS0012:类型 x 在未引用的程序集中定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/284433/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Strange Error - CS0012: The type x is defined in an assembly that is not referenced
提问by Mike T
The type 'x' is defined in an assembly that is not referenced. You must add a reference to assembly 'abc123'.
类型“x”是在未引用的程序集中定义的。您必须添加对程序集“abc123”的引用。
I have a .NET 2.0 web application that references my assembly 'abc123'. The assembly exists in the GAC and I've verified that it is the correct(same) version. The rest of application has no issues except for one .aspx page. The page in question has a repeater that displays a user control as one of its "fields". Upon binding a list of type y to the repeater I pass the user control a list of type x (a property of y) as shown here:
我有一个引用我的程序集“abc123”的 .NET 2.0 Web 应用程序。该程序集存在于 GAC 中,我已经验证它是正确的(相同)版本。除了一个 .aspx 页面外,其余的应用程序没有问题。有问题的页面有一个中继器,将用户控件显示为其“字段”之一。将 y 类型列表绑定到转发器后,我向用户控件传递一个 x 类型列表(y 的属性),如下所示:
<uc1:usercontrol id="ucusercontrol " runat="server" myPublicUserControlProperty='<%#Eval("CollectionOfX") %>'/>
On the user control's property set, I bind the list of type x to a gridview in the user control.
在用户控件的属性集上,我将 x 类型的列表绑定到用户控件中的 gridview。
One strange thing to note is that this report works fine on my development pc but not on any servers once I deploy. My pc is Windows XP, IIS6, VS2005. The servers are Windows Server 2003, IIS6.
需要注意的一件奇怪的事情是,此报告在我的开发电脑上运行良好,但在我部署后在任何服务器上都无法正常运行。我的电脑是Windows XP、IIS6、VS2005。服务器是 Windows Server 2003、IIS6。
I hope I explained that well enough. Thanks in advance for any insight you can provide.
我希望我解释得足够好。预先感谢您提供的任何见解。
采纳答案by Aaron Daniels
I'm Mike's coworker, and we worked out a solution.
我是迈克的同事,我们想出了一个解决方案。
The type X is defined in his assembly, that is only in the GAC. Even though his ASP.NET web appplication did have a reference, it was failing to load from the GAC only for this UserControl. The rest of the application worked as expected. We confirmed the failed loading by placing a copy of the assembly in the bin directory, and everything worked. We removed the assembly, and the problem came back.
X 类型是在他的程序集中定义的,即仅在 GAC 中。即使他的 ASP.NET Web 应用程序确实有一个引用,它也无法从 GAC 仅为此 UserControl 加载。应用程序的其余部分按预期工作。我们通过在 bin 目录中放置一个程序集副本来确认加载失败,并且一切正常。我们卸下了组件,问题又回来了。
Our solution was to manually add an entry to the web.config in the assemblies section to point ASP.NET to the GAC.
我们的解决方案是手动向程序集部分中的 web.config 添加一个条目,以将 ASP.NET 指向 GAC。
It looks like any time you reference a type in the page (not the code-behind), you need the assembly information defined in the web.config file or in a page directive.
看起来每次在页面中引用类型(而不是代码隐藏)时,都需要在 web.config 文件或页面指令中定义的程序集信息。
<assemblies>
<add assembly="MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=[MyPublicKeyToken]"/>
</assemblies>
回答by Tom Lianza
There's also a bug that can manifest itself with similar symptoms, described here.
还有一个错误可能会表现出类似的症状,描述为here。
The workaround is to delete everything in the C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\ directory, and it only seems to manifest itself in debug mode.
解决方法是删除 C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\ 目录中的所有内容,它似乎只在调试模式下显示出来。
回答by Maxam
When troubleshooting these types of problems, the Fusion Log Viewerhas always been a great help.
在对这些类型的问题进行故障排除时,Fusion Log Viewer一直是一个很大的帮助。
回答by Charbarred
I found that if type x
is actually a class in your App_Code
, dirtying it and re-saving often forces the web app to recompile and solves the problem.
我发现 iftype x
实际上是你的一个类App_Code
,弄脏它并重新保存通常会迫使网络应用程序重新编译并解决问题。
回答by Max Izrin
For me it was a version control pull problem.
对我来说,这是一个版本控制拉取问题。
In Visual studio, open "References" in your Solution explorer, and scroll through it.
在 Visual Studio 中,在解决方案资源管理器中打开“参考”,然后滚动浏览。
If anything has a yellow warning triangle on it, remember the name, remove it, and add it back again (or have ReSharper do it for you).
如果任何东西上有黄色警告三角形,请记住名称,将其删除,然后重新添加(或让 ReSharper 为您执行此操作)。
Happened to me several times after pulling a project when a co-worker added a new package and references.
当一位同事添加了一个新的包和引用时,在拉动一个项目后,我发生了好几次。
回答by Dan
I had the exact same error, but I had a publicconstructor in my class that used as a parameter, an object from another project.
我有完全相同的错误,但我的类中有一个公共构造函数,用作参数,来自另一个项目的对象。
I resolved the problem by making that constructor internal.
我通过将该构造函数设置为内部来解决该问题。