Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
436 views
in Technique[技术] by (71.8m points)

c# - Where does error CS0433 "Type 'X' already exists in both A.dll and B.dll " come from?

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

The full error (source file Default.aspx.cs):

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'

The preceding full warning:

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

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?

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.

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.

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Theory

When this issue is not caused 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 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.

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.

Solution

  1. Close Visual Studio
  2. Perform an iisreset
  3. Delete all the folders and files within the "Temporary ASP.NET Files" folder (the path is referenced in the error message)
  4. Delete the offending application's "obj" and "bin" folders
  5. Restart Visual Studio and open the solution
  6. Perform a "Clean Solution" followed by a "Rebuild Solution"

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...