奇怪的错误 - CS0012:类型 x 是在未引用的程序集中定义的

发布于 2024-07-08 03:02:58 字数 610 浏览 7 评论 0原文

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

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

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

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

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

我希望我解释得足够好。 预先感谢您提供的任何见解。

The type 'x' is defined in an assembly that is not referenced. You must add a reference to assembly '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:

<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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

執念 2024-07-15 03:02:58

我是迈克的同事,我们找到了解决方案。

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

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

看起来每当您引用页面中的类型(而不是隐藏代码)时,您都需要在 web.config 文件或页面指令中定义的程序集信息。

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

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.

Our solution was to manually add an entry to the web.config in the assemblies section to point ASP.NET to the 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.

<assemblies>
        <add assembly="MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=[MyPublicKeyToken]"/>   
</assemblies>
等你爱我 2024-07-15 03:02:58

在对这些类型的问题进行故障排除时,Fusion 日志查看器 一直是一个很大的帮助。

When troubleshooting these types of problems, the Fusion Log Viewer has always been a great help.

所谓喜欢 2024-07-15 03:02:58

还有一个错误可以表现出类似的症状,描述为此处

解决方法是删除 C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\ 目录中的所有内容,并且它似乎只在调试模式下显现出来。

There's also a bug that can manifest itself with similar symptoms, described 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.

撩起发的微风 2024-07-15 03:02:58

我发现,如果 type x 实际上是您的 App_Code 中的一个类,则弄脏它并重新保存通常会迫使 Web 应用程序重新编译并解决问题。

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.

活泼老夫 2024-07-15 03:02:58

通常,这是因为缓存的程序集。 解决此问题的一种方法是在 proj 或配置文件中进行“强引用”。 请参阅此博客帖子

More often than not, it is because of the cached assemblies. One way resolve this issue is by making the "strong reference" in the proj or config file. Refer this blog post

深海夜未眠 2024-07-15 03:02:58

我遇到了完全相同的错误,但我的类中有一个 public 构造函数,它用作参数,即来自另一个项目的对象。

我通过将该构造函数设为内部解决了该问题。

I had the exact same error, but I had a public constructor in my class that used as a parameter, an object from another project.

I resolved the problem by making that constructor internal.

仅一夜美梦 2024-07-15 03:02:58

对我来说这是一个版本控制拉动问题。

在 Visual Studio 中,在解决方案资源管理器中打开“参考”,然后滚动浏览它。

如果任何东西上有黄色警告三角形,请记住名称,将其删除,然后再次添加回来(或让 ReSharper 为您完成)。

当同事添加了新的包和引用时,在拉出项目后,我曾多次遇到过这种情况。

For me it was a version control pull problem.

In Visual studio, open "References" in your Solution explorer, and scroll through it.

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).

Happened to me several times after pulling a project when a co-worker added a new package and references.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文