C# 错误 CS0433“类型 'X' 已存在于 A.dll 和 B.dll 中”来自哪里?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1757289/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where does error CS0433 "Type 'X' already exists in both A.dll and B.dll " come from?
提问by Abel
When I run a webapp from Visual Studio 2008 SP1 using the internal web server (not IIS) I receive the above mentioned error.
当我使用内部 Web 服务器(不是 IIS)从 Visual Studio 2008 SP1 运行 web 应用程序时,我收到上述错误。
The full error (source file Default.aspx.cs):
完整错误(源文件Default.aspx.cs):
Compiler Error Message: CS0433: The type 'WebApplication3.Site1' exists in both 'c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\aa563bcf\59deedc0\App_Web_site1.master.cdcab7d2.muczzy9v.dll' and 'c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\aa563bcf\59deedc0\assembly\dl3\44c3a3cf\80dd34ed_6968ca01\WebApplication3.DLL'
编译器错误消息:CS0433:类型“WebApplication3.Site1”存在于“c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\aa563bcf\59deedc0\App_Web_site1.master.cdcab7d2”中。 muczzy9v.dll'和'c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\aa563bcf\59deedc0\assembly\dl3\44c3a3cf\80dd34ed_6968ca01\WebApplication3'。
The preceding full warning:
前面的完整警告:
Warning: CS0436: The type 'WebApplication3._Default' in 'c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\aa563bcf\59deedc0\App_Web_default.aspx.cdcab7d2._tlkwdos.0.cs' conflicts with the imported type 'WebApplication3._Default' in 'c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\aa563bcf\59deedc0\assembly\dl3\44c3a3cf\e096e61c_6568ca01\WebApplication3.DLL'. Using the type defined in 'c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\aa563bcf\59deedc0\App_Web_default.aspx.cdcab7d2._tlkwdos.0.cs'.
警告:CS0436:“c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\aa563bcf\59deedc0\App_Web_default.aspx.cdcab7d2._tlkwdos.0”中的“WebApplication3._Default”类型。 cs' 与'c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\aa563bcf\59deedc0\assembly\dl3\44c3a3cf\e096e61c_10656e61c_6563a3cf\ .DLL'。使用在“c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\aa563bcf\59deedc0\App_Web_default.aspx.cdcab7d2._tlkwdos.0.cs”中定义的类型。
Source of warning points to an intermediate file App_Web_default.aspx.cdcab7d2._tlkwdos.0.cs:
警告来源指向一个中间文件App_Web_default.aspx.cdcab7d2._tlkwdos.0.cs:
Line 162:
Line 163: [System.Runtime.CompilerServices.CompilerGlobalScopeAttribute()]
Line 164: public class default_aspx : global::WebApplication3._Default, System.Web.IHttpHandler {
Line 165:
Line 166: private static bool @__initialized;
and my question: where does this come from?
我的问题:这是从哪里来的?
The webapp (not website!) has one Default.aspxand one Site1.Master, no dependencies. They're almost empty, with an asp:Label
on the page. Previously, this webapp worked fine. When I remove any references in Default.aspx.cs to the master, all goes well. The master has some code only.
webapp(不是网站!)有一个Default.aspx和一个Site1.Master,没有依赖项。它们几乎是空的,asp:Label
页面上有一个。以前,这个 webapp 运行良好。当我删除 Default.aspx.cs 中对 master 的任何引用时,一切顺利。主人只有一些代码。
It's actually one of many little fire-and-forget test webapps, so I couldn't care less. But I hadn't seen this before and now I'm curious of what to do, other then copying code into a new project (cleaning solution doesn't help).
它实际上是许多小型即发即忘的测试 web 应用程序之一,所以我不在乎。但是我以前从未见过这个,现在我很好奇该怎么做,然后将代码复制到新项目中(清理解决方案无济于事)。
Note: I've read this postand some others, they don't apply.
采纳答案by 2Toad
Theory
理论
When this issue is notcaused by a bug in the application (e.g., duplicate class name):
当此问题不是由应用程序中的错误引起时(例如,重复的类名):
This issue appears to present after a change is made to the application's project that results in a new build (e.g., code/reference/resource change). The issue appears to lie within the output of this new build: for various reasons Visual Studio is not replacing the entirecontents of your application's obj/bin folders. This results in at least some of the contents of your application's bin folder being out of date.
在对应用程序的项目进行更改导致新构建(例如,代码/引用/资源更改)后,似乎会出现此问题。问题似乎出在这个新版本的输出中:由于各种原因,Visual Studio 没有替换应用程序 obj/bin 文件夹的全部内容。这至少会导致应用程序的 bin 文件夹中的某些内容过时。
When said issue occurs, clearing out the "Temporary ASP.NET Files" folder, alone, does not solve the problem. It cannot solve the problem, because the stale contents of your application's bin folder are copied back into the "Temporary ASP.NET Files" folder the next time your application is accessed, causing the issue to persist. The key is to remove all existing files and force Visual Studio to rebuild every object, so the next time your application is accessed the new bin files will be copied into the "Temporary ASP.NET Files" folder.
当出现上述问题时,单独清除“Temporary ASP.NET Files”文件夹并不能解决问题。它无法解决问题,因为下次访问应用程序时,应用程序 bin 文件夹的陈旧内容会被复制回“Temporary ASP.NET Files”文件夹,从而导致问题持续存在。关键是删除所有现有文件并强制 Visual Studio 重建每个对象,以便下次访问您的应用程序时,新的 bin 文件将被复制到“Temporary ASP.NET Files”文件夹中。
Solution
解决方案
- Close Visual Studio
- Perform an iisreset
- Delete all the folders and files within the "Temporary ASP.NET Files" folder (the path is referenced in the error message)
- Delete the offending application's "obj" and "bin" folders
- Restart Visual Studio and open the solution
- Perform a "Clean Solution" followed by a "Rebuild Solution"
- 关闭 Visual Studio
- 执行 iisreset
- 删除“Temporary ASP.NET Files”文件夹中的所有文件夹和文件(错误消息中引用了路径)
- 删除违规应用程序的“obj”和“bin”文件夹
- 重新启动 Visual Studio 并打开解决方案
- 执行“清洁解决方案”,然后执行“重建解决方案”
Explanation
解释
- Steps 1-2: remove resource locks from the folders/files we need to delete.
- Steps 3-4: remove all of the old build files
- Steps 5-6: create new versions of the build files
- 步骤1-2:从我们需要删除的文件夹/文件中移除资源锁。
- 步骤 3-4:删除所有旧的构建文件
- 步骤 5-6:创建构建文件的新版本
回答by Alex Polkhovsky
Shut down w3svc and delete everything from c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\
关闭 w3svc 并从中删除所有内容 c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\
added
添加
on Windows 7
c:\Users\{username}\AppData\Local\Temp\Temporary ASP.NET Files\root\
on IIS servers (64 bit)this can also occur. Look for:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root
(replace v4.0.30319 by the framework version you're using if newer on your server)
在 Windows 7 上
c:\Users\{username}\AppData\Local\Temp\Temporary ASP.NET Files\root\
在IIS 服务器(64 位)上,这也可能发生。寻找:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root
(如果您的服务器上较新,请将 v4.0.30319 替换为您正在使用的框架版本)
回答by Naveen Q
Removing the class files from the App_Code
folder, and placing them directly under the website, solved this issue for me.
从App_Code
文件夹中删除类文件,并将它们直接放在网站下,为我解决了这个问题。
回答by Deepak
This may happen when the same classname is specified in multiple .aspx.cs
files, i.e.
when two pages are created with different file name but by mistake have the same classname.
当在多个.aspx.cs
文件中指定相同的类名时可能会发生这种情况,即当两个页面使用不同的文件名创建但错误地具有相同的类名时。
// file a.aspx
public partial class Test1: System.Web.UI.Page
// file b.aspx
public partial class Test1: System.Web.UI.Page
While building the webapplication this gives a warning, but the application runs, however, after publishing the application doesn't work anymore and throws the exception as mentioned in the OP's question.
在构建 web 应用程序时,这会发出警告,但应用程序运行,但是,在发布应用程序后不再工作并抛出异常,如 OP 问题中所述。
Making sure that two classnames do no overlap solves the issue.
确保两个类名不重叠可以解决问题。
回答by NitroxDM
Look at the Inherits tag of all your aspx pages and master pages. Chances are there are two partial classes that have the same name. Change one and recompile.
查看所有 aspx 页面和母版页的 Inherits 标记。可能有两个具有相同名称的部分类。换一个,重新编译。
Here is some more info:
以下是更多信息:
http://blogs.msdn.com/b/carloc/archive/2007/06/12/compiler-error-message-cs0433-in-asp-net-2-0.aspx
http://blogs.msdn.com/b/carloc/archive/2007/06/12/compiler-error-message-cs0433-in-asp-net-2-0.aspx
回答by Jason Geiger
This may also happen if you have duplicate TagPrefix in your ASPX file.
如果您的 ASPX 文件中有重复的 TagPrefix,也可能会发生这种情况。
This would cause this error...
这会导致这个错误...
<%@ Register Src="Control1.ascx" TagName="Control1" TagPrefix="uc1" %>
<%@ Register Src="Control2.ascx" TagName="Control2" TagPrefix="uc1" %>
You can fix this by simply changing the 2nd "uc1" to "uc2"
您可以通过简单地将第二个“uc1”更改为“uc2”来解决此问题
Fixed...
固定的...
<%@ Register Src="Control1.ascx" TagName="Control1" TagPrefix="uc1" %>
<%@ Register Src="Control2.ascx" TagName="Control2" TagPrefix="uc2" %>
回答by Lilja
This might happen if you place .cs files in App_Code and changed their build action to compile in a Web Application Project.
如果您将 .cs 文件放在 App_Code 中并将它们的构建操作更改为在 Web 应用程序项目中进行编译,则可能会发生这种情况。
Either have the build action for the .cs files in App_Code as Content or change the name of App_Code to something else. I changed the name since intellisense won't fix .cs files marked as content.
要么将 App_Code 中的 .cs 文件的构建操作作为内容,要么将 App_Code 的名称更改为其他名称。我更改了名称,因为智能感知不会修复标记为内容的 .cs 文件。
More info at http://vishaljoshi.blogspot.se/2009/07/appcode-folder-doesnt-work-with-web.html
更多信息见http://vishaljoshi.blogspot.se/2009/07/appcode-folder-doesnt-work-with-web.html
回答by Adeel
go to web.config
去 web.config
in the <compilation
add batch="false"
在<compilation
添加batch="false"
it should fix the problem
它应该解决问题
回答by Roman
"Clean Solution" followed by "Rebuild Solution" seems to fix it as well.
“清洁解决方案”后跟“重建解决方案”似乎也解决了这个问题。
回答by mlapaglia
This happened to me because of an error in my Web.Config
这发生在我身上是因为我的 Web.Config 中的错误
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.WebPages, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
The Sytem.Web.Helpers
was pointed at 1.0.0.0 instead of 3.0.0.0 (MVC 3 is being used on this project).
该Sytem.Web.Helpers
指向了1.0.0.0,而不是3.0.0.0(MVC 3时在这个项目上使用)。
Because IIS couldn't find the reference in the local folder it looked in the GAC and found two different versions. After pointing it at the correct reference IIS found the local dll and used that instead of searching the GAC.
因为 IIS 在本地文件夹中找不到引用,所以它在 GAC 中查找并找到了两个不同的版本。在将其指向正确的引用后,IIS 找到了本地 dll 并使用它而不是搜索 GAC。