Click here to Skip to main content
13,052,494 members (68,560 online)
Click here to Skip to main content
Add your own
alternative version


2 bookmarked
Posted 31 Oct 2013

Getting round Visual Studio when it decides a class isn't the same as itself...

, 31 Oct 2013
Rate this:
Please Sign up or sign in to vote.
Sometimes (far too often, I find) you will try to open a form in the Visual Studio designer, and it won't open it because "the type X declared in Project X is not the same as the type X declared in Project X". This is annoying, as well as being blatantly untrue. Stop laughing at the back there!


Visual Studio keeps temporary intermediate files which it doesn't handle very well sometimes.

And every now and then if you have a Solution with multiple projects - as is recommended by good practices - VS ends up with two copies of intermediate files for the same project - and it ends up complaining about designer generated code like this:

protected MyWalletBL.Branch Branch;
this.selectFavourites.Branch = 

Saying that the class is different on the two sides of the equals sign - which is blatantly untrue!

What has happened is that somehow, VS has got confused and is using two different intermediate files with slightly different class signatures (even if you haven't changed the class) and doesn't know what to do.

So when you try to open the form, it throws up it's electronic hands, and collapses.

Fixing it!

Stop right where you are. Do not do anything else: VS is in a fragile state right now, and could easily start to corrupt stuff.

It's actually pretty simple to fix:

  1. Remove all inter-project references. 
  2. Clean solution. (I don't think this does anything useful here, but it can't hurt) This does not get rid of the intermediate files. 
  3. Close VS. Wait until it is completely gone, the disk has stopped rattling, etc.
  4. Delete the intermediate files. Where are they?  Here on my PC:
  5. C:\Users\griff\AppData\Local\Microsoft\VisualStudio\10.0\ProjectAssemblies

    Which means they will be under your user name - but be aware than AppData is a hidden folder, so you will probably be best creating a shortcut to this location using your username. I find that once this problem crops up, it will be back, and back, and back...

    Delete everything in that folder. All the files (shouldn't be any). All the folders. If you can't delete a folder, then VS is still running. Find it. Kill it. Try again. 

  6. Restart VS
  7. Re-instate the references, and rebuild the solution. 


Points of Interest 

There are times when I hate VS... 


  • Original version.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Wales Wales
Born at an early age, he grew older. At the same time, his hair grew longer, and was tied up behind his head.
Has problems spelling the word "the".
Invented the portable cat-flap.
Currently, has not died yet. Or has he?

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170713.1 | Last Updated 31 Oct 2013
Article Copyright 2013 by OriginalGriff
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid