部署项目 dll 导致“类型 x 存在于两者中” 错误

发布于 2024-07-10 04:50:17 字数 633 浏览 8 评论 0原文

我有一个 WebApplication 项目、一个业务逻辑项目和一个用于 Web 应用程序的 WebDeployment 项目。

当我构建解决方案时,部署“Release”bin 包含每个项目的 1 个 dll - 因此我为 MyWeb.dll、MyWebBusiness.dll 和 MyWebDeploy.dll 获得一个 dll。

当我尝试运行该站点时,它在 MyWeb.dll 和 MyWebDeploy.dll 中看到相同的类型并被阻塞。

错误信息: CS0433:类型“AV”存在于“c:\ WINDOWS \ Microsoft.NET \ Framework \ v2.0.50727 \ Temporary ASP.NET Files \ root \ 53d45622 \ 6c032bd2 \ assembly \ dl3 \ 33f3c6b2 \ abc9430a_285ac901 \ MyWeb.DLL”中和'c:\ WINDOWS \ Microsoft.NET \ Framework \ v2.0.50727 \ Temporary ASP.NET Files \ root \ 53d45622 \ 6c032bd2 \ assembly \ dl3 \ 631e5302 \ 0231160d_285ac901 \ MyWebDeploy.DLL'

I have a WebApplication project, a business logic project, and a WebDeployment project for the web app.

When I build solution, the deployment "Release" bin contains 1 dll for each of the projects - so I get one for MyWeb.dll, MyWebBusiness.dll, and MyWebDeploy.dll.

When I try to run the site, it sees the same type in both MyWeb.dll and MyWebDeploy.dll and chokes.

Error message:
CS0433: The type 'AV' exists in both 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\53d45622\6c032bd2\assembly\dl3\33f3c6b2\abc9430a_285ac901\MyWeb.DLL' and 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\53d45622\6c032bd2\assembly\dl3\631e5302\0231160d_285ac901\MyWebDeploy.DLL'

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

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

发布评论

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

评论(4

甲如呢乙后呢 2024-07-17 04:50:17

我能想到的一些原因:

  • 您的项目中有一个 App_Code 目录
  • 您在某些页面标记中有一个 CodeFile 页面指令,而不是 CodeBehind

Some reasons I can think of:

  • You have an App_Code directory in your project
  • You have a CodeFile page directive in the some page markup instead of CodeBehind
盛装女皇 2024-07-17 04:50:17

有一个很棒的论坛帖子:http://forums.asp.net/t/980517 .aspx

似乎只需要在 Web 应用程序项目中添加正确的代码,VS 会说“哦,这是一个网站项目,所以我最好自动编译它”,然后当它找到时就崩溃了它也已经被编译为单个 DLL。

上面达林列出的原因是罪魁祸首。

请注意,由于意外对同一程序集有两个引用、web.config 程序集部分中的双重引用或意外将代码文件的重复副本放入项目中的文件夹中,可能会出现类似的错误,但这些通常会出现如果您在 web.config 中打开了调试,那么错误消息应该会提到除 Web App 程序集 {WebAppName}.dll 和自动编译程序集 App_Web_{number}.dll 之外的程序集,

这一点非常 明显。人们说(在引用的线程中)事件处理程序导致了问题,但我认为这只是背后的代码中有一些奇怪的东西被解释为需要自动编译。
我也有同样的情况,我已将一大堆示例代码剪切并粘贴到我的 Web 应用程序中,并检查了上述所有内容。 但是,许多页面的代码背后已经有“Web 表单设计器生成”代码,因此当我右键单击解决方案资源管理器上的应用程序并选择“转换为 Web 应用程序”时,什么也没有发生。
旧代码保留在那里,双重编译继续。

所以除了这些帖子之外我还要说:
如果代码已被剪切和粘贴,并且转换器不喜欢某些内容,则它将不会转换它并且双重编译将继续。 唯一的解决方案是将有问题的页面添加为新项目,复制标记和代码(如果需要,一点一点地),然后删除旧版本。

就我而言,我只是访问了该项目的网站,因为我不想被打扰,而且它只是一个演示项目。

There's a great forum post on this at: http://forums.asp.net/t/980517.aspx

Seems that all it takes is the right bit of code in the Web Application project and and VS says 'Oh, this is a website project so I'd better autocompile it', and then falls over when it finds it has already been compiled as a single DLL as well.

Causes listed by Darin above are the primary culprits.

Note that it is possible to get a similar error by accidentially having two references to the same assembly, double references in your web.config assemblies section, or accidentally dropping a duplicate copy of a codefile into a folder in the project, but these will usually be pretty obvious if you have debugging switched on in your web.config, and the error message should mention an assembly other than the Web App assembly {WebAppName}.dll and auto-compiled assembly App_Web_{number}.dll

There are quite a few people saying (in the referenced thread) that event handlers were causing problems, but I think it's just that there is something weird in the code behind which is being interpreted as requiring an autocompile.
I'm in the same boat, I have cut and pasted a whole bunch of sample code into my web application, and checked all the above. However, a lot of the pages have code behind which have the 'Web Form Designer generated' code on them already, so when I right click the application on solution explorer and choose 'convert to web application', nothing happens.
The old code stays there and the double compilation continues.

So I'd say in addition to these posts:
If the code has been cut and pasted and there is something the converter doesn't like, it won't convert it and the double compilation will continue. The only solution is to add the offending pages as new items, copy markup and code over (bit by bit if necessary), then remove the old versions.

In my case, I just went to a Web Site for the project because i couldn't be bothered and it was only a demo project anyway.

Smile简单爱 2024-07-17 04:50:17

我将我的项目从网站转换为 Web 应用程序,并在所有页面中使用 CodeFile 而不是 CodeBehind,即使我使用 VS“转换为 WebApp”选项。 手动用 CodeBehind 替换 Codefile 确实解决了我的问题。 添加此内容是为了帮助其他人转换为 Web 应用程序。

I converted my project from Web site to Web app and had CodeFile in all pages instead of CodeBehind even though I used VS "convert to WebApp" option. Replacing Codefile with CodeBehind manually did solve my problem. Added this so that it might help any one else converting to webapp.

晒暮凉 2024-07-17 04:50:17

将batch =“false”添加到web.config文件

为您的文件提供修复名称,主要用于母版页

<compilation ... batch="false"/>

  ...

Add batch="false" to web.config file

Give your files fix names mostly for masterpages

<compilation ... batch="false"/>

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