错误 CS0433“A.dll 和 B.dll 中都已存在类型‘X’"在哪里?来自?

Where does error CS0433 quot;Type #39;X#39; already exists in both A.dll and B.dll quot; come from?(错误 CS0433“A.dll 和 B.dll 中都已存在类型‘X’在哪里?来自?)
本文介绍了错误 CS0433“A.dll 和 B.dll 中都已存在类型‘X’"在哪里?来自?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用内部 Web 服务器(不是 IIS)从 Visual Studio 2008 SP1 运行 Web 应用程序时,我收到上述错误.

When I run a webapp from Visual Studio 2008 SP1 using the internal web server (not IIS) I receive the above mentioned error.

完整错误(源文件Default.aspx.cs):

编译器错误消息:CS0433:类型WebApplication3.Site1"存在于两个都'c:WindowsMicrosoft.NETFrameworkv2.0.50727TemporaryASP.NET文件 ootaa563bcf59deedc0App_Web_site1.master.cdcab7d2.muzzy9v.dll'和'c:WindowsMicrosoft.NETFrameworkv2.0.50727TemporaryASP.NETFiles ootaa563bcf59deedc0assemblydl344c3a3cf80dd34ed_6968ca01WebApplication3.DLL'

Compiler Error Message: CS0433: The type 'WebApplication3.Site1' exists in both 'c:WindowsMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET Files ootaa563bcf59deedc0App_Web_site1.master.cdcab7d2.muczzy9v.dll' and 'c:WindowsMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET Files ootaa563bcf59deedc0assemblydl344c3a3cf80dd34ed_6968ca01WebApplication3.DLL'

前面的完整警告:

警告:CS0436:类型'WebApplication3._Default' 在'c:WindowsMicrosoft.NETFrameworkv2.0.50727TemporaryASP.NET文件 ootaa563bcf59deedc0App_Web_default.aspx.cdcab7d2._tlkwdos.0.cs'与导入的类型冲突'WebApplication3._Default' 在'c:WindowsMicrosoft.NETFrameworkv2.0.50727TemporaryASP.NET文件 ootaa563bcf59deedc0assemblydl344c3a3cfe096e61c_6568ca01WebApplication3.DLL'.使用中定义的类型'c:WindowsMicrosoft.NETFrameworkv2.0.50727TemporaryASP.NET文件 ootaa563bcf59deedc0App_Web_default.aspx.cdcab7d2._tlkwdos.0.cs'.

Warning: CS0436: The type 'WebApplication3._Default' in 'c:WindowsMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET Files ootaa563bcf59deedc0App_Web_default.aspx.cdcab7d2._tlkwdos.0.cs' conflicts with the imported type 'WebApplication3._Default' in 'c:WindowsMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET Files ootaa563bcf59deedc0assemblydl344c3a3cfe096e61c_6568ca01WebApplication3.DLL'. Using the type defined in 'c:WindowsMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET Files ootaa563bcf59deedc0App_Web_default.aspx.cdcab7d2._tlkwdos.0.cs'.

警告源指向一个中间文件App_Web_default.aspx.cdcab7d2._tlkwdos.0.cs:

Source of warning points to an intermediate file 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?

webapp(不是网站!)有一个Default.aspx和一个Site1.Master,没有依赖关系.它们几乎是空的,页面上有一个 asp:Label.以前,这个 webapp 运行良好.当我删除 Default.aspx.cs 中对 master 的任何引用时,一切顺利.主人只有一些代码.

The webapp (not website!) has one Default.aspx and 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.

它实际上是许多小型的即发即弃的测试 web 应用程序之一,所以我不在乎.但是我以前没有见过这个,现在我很好奇该怎么做,然后将代码复制到一个新项目中(清理解决方案没有帮助).

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

注意:我已阅读 这篇文章和其他一些,它们不适用.

Note: I've read this post and some others, they don't apply.

推荐答案

理论

当此问题不是由应用程序中的错误(例如,重复的类名)引起时:

When this issue is not caused by a bug in the application (e.g., duplicate class name):

在对应用程序的项目进行更改并导致新的构建(例如,代码/参考/资源更改)后,似乎会出现此问题.问题似乎出在这个新版本的输出中:由于各种原因,Visual Studio 没有替换应用程序 obj/bin 文件夹的整个内容.这会导致应用程序 bin 文件夹中的至少部分内容过期.

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

当出现上述问题时,单独清除Temporary ASP.NET Files"文件夹并不能解决问题.它无法解决问题,因为下次访问应用程序时,应用程序 bin 文件夹的陈旧内容会被复制回Temporary ASP.NET Files"文件夹,从而导致问题持续存在.关键是删除所有现有文件并强制 Visual Studio 重新构建每个对象,因此下次访问您的应用程序时,新的 bin 文件将被复制到Temporary ASP.NET Files"文件夹中.

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.

解决方案

  1. 关闭 Visual Studio
  2. 执行 iisreset
  3. 删除Temporary ASP.NET Files"文件夹中的所有文件夹和文件(错误消息中引用了路径)
  4. 删除有问题的应用程序的obj"和bin"文件夹
  5. 重启 Visual Studio 并打开解决方案
  6. 执行清洁解决方案",然后执行重建解决方案"

解释

  • 步骤 1-2:从我们需要删除的文件夹/文件中移除资源锁.
  • 第 3-4 步:删除所有旧的构建文件
  • 步骤 5-6:创建新版本的构建文件

这篇关于错误 CS0433“A.dll 和 B.dll 中都已存在类型‘X’"在哪里?来自?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)