奇怪的错误 - CS0012:类型 x 在未引用的程序集中定义 [英] Strange Error - CS0012: The type x is defined in an assembly that is not referenced

查看:24
本文介绍了奇怪的错误 - CS0012:类型 x 在未引用的程序集中定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类型x"在未引用的程序集中定义.您必须添加对程序集abc123"的引用.

The type 'x' is defined in an assembly that is not referenced. You must add a reference to assembly 'abc123'.

我有一个引用我的程序集abc123"的 .NET 2.0 Web 应用程序.该程序集存在于 GAC 中,我已经验证它是正确的(相同的)版本.除了一个 .aspx 页面外,应用程序的其余部分没有问题.有问题的页面有一个转发器,它将用户控件显示为其字段"之一.在将 y 类型的列表绑定到中继器后,我向用户控件传递了一个 x 类型的列表(y 的属性),如下所示:

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:

<uc1:usercontrol id="ucusercontrol " runat="server" myPublicUserControlProperty='<%#Eval("CollectionOfX") %>'/>

在用户控件的属性集上,我将 x 类型的列表绑定到用户控件中的 gridview.

On the user control's property set, I bind the list of type x to a gridview in the user control.

需要注意的一件奇怪的事情是,该报告在我的开发电脑上运行良好,但在部署后无法在任何服务器上运行.我的电脑是 Windows XP、IIS6、VS2005.服务器是 Windows Server 2003、IIS6.

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.

我希望我解释得足够好.提前感谢您提供的任何见解.

I hope I explained that well enough. Thanks in advance for any insight you can provide.

推荐答案

我是 Mike 的同事,我们制定了解决方案.

I'm Mike's coworker, and we worked out a solution.

类型 X 是在他的程序集中定义的,即仅在 GAC 中.尽管他的 ASP.NET Web 应用程序确实有一个引用,但它无法从 GAC 仅为此 UserControl 加载.应用程序的其余部分按预期工作.我们通过将程序集的副本放在 bin 目录中来确认加载失败,并且一切正常.我们卸下了组件,问题又回来了.

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.

我们的解决方案是手动向程序集部分的 web.config 添加一个条目,以将 ASP.NET 指向 GAC.

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 文件或页面指令中定义的程序集信息.

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.

<assemblies>
        <add assembly="MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=[MyPublicKeyToken]"/>   
</assemblies>

这篇关于奇怪的错误 - CS0012:类型 x 在未引用的程序集中定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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