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

问题描述

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

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

我有一个.NET 2.0 Web应用程序引用了程序集 abc123。该程序集存在于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.

要注意的一件事是,此报告在我的开发PC上运行良好,但在部署后在任何​​服务器上都无法正常运行。我的电脑是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应用程序确实有参考,也只能从此UserControl的GAC中加载。该应用程序的其余部分按预期工作。我们通过将程序集的副本放置在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.

我们的解决方案是在Assemblys部分中手动向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是在未引用的程序集中定义的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 06:16