Deployment Project dlls cause 'type x exists in both' errors

我只是一个虾纸丫 提交于 2019-12-07 09:57:10

问题


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'


回答1:


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



回答2:


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.




回答3:


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.




回答4:


Add batch="false" to web.config file

Give your files fix names mostly for masterpages

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

  ...


来源:https://stackoverflow.com/questions/353721/deployment-project-dlls-cause-type-x-exists-in-both-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!