views:

2568

answers:

7

Hi all,

Has anyone ever had the issue where trying to "View Designer" on a windows form in Visual Studio .NET causes the error: "Could not load file or assembly…" ?

In this case, the assembly in question was XYZ.dll. I managed to fix this by adding XYZ.dll and all its references to my project's references (even though my project doesn't directly depend on them) and rebuilding the whole solution. However, after that, I removed all those references from my project, rebuilt, and it still worked.

Does anyone have a understanding of why this error happens in the first place, and possibly the 'correct' way to fix it?

Thanks, Chien

A: 

This would probably depend a whole lot on what XYZ.dll actually was... Was it part of the .NET runtime? Was it a custom DLL? Was it some other part of your solution?

Matthew Scharley
XYZ is a custom DLL. It was not some other part of my solution, other than being a indirect dependency. That is, the project in my solution with that windows form references ABC.dll which references XYZ.dll.
In this case, then rebuilds and partial builds can do strange things in the designer. A full rebuild without errors usually clears things up.
Matthew Scharley
+1  A: 

It happened to me very frequently on VS2005, specially when adding custom controls to the winform. Usually I just needed to just rebuild, without needing to add extra references, or close and reopen VS.

There is no apparent cause for this, just VS bugs.

Santiago Palladino
Used to happen to me all the time with Infragistics Winforms controls. Freakin annoying, and it only happened on my machine, even though there were 5 people using the exact same code.
jcollum
+3  A: 

We have same problem. Some Form/UserControl classes can not be viewed in designer and Visual Studio causes various exceptions.

There are one typical cause: One of designed component thrown unhalded exception during initialization ( in constructor or in Load event or before ).

Not only for this case, you can run another instance of visual studio, open/create some independent project, go to menu -> Debug -> Attach to process ... -> select instance of devenv.exe process with problematic designer. Then press Ctrl+Alt+E, the "Exceptions" windows should be shown. There check "Thrown" in categories of exception.

Now active the visual studio with designer and try view designer. If the exception will be thrown, you will see callstack ( and maybee source code, if the exception was thrown from your code ) and other typical information about thrown exception. This informations may be very helpfull.

TcKs
Thanks! This sounds like something I would definitely try the next time I get hit by this. I would like to point out though that I have always been open to this form. It just happened recently.
A: 

Thanks for the responses so far!

One other piece of information is that I use Resharper 2.5. Someone else pointed out that it might be Resharper doing some shadow copying. I'll look into this next time this happens.

A: 

Using VS 2005, I ran into this same problem. I performed the steps Chien listed in his original question, but it still didn't work until I closed VS and reopened the solution. Now the Designer view looks fine.

Dean Hill
A: 

I concur with the Resharper comment. I'm running 4.1. I disabled it, restart VS2008, and tried the "Convert to Web Application" again, and it worked.

A: 

I've seen this happen in VS2005 for Window Forms, ASP.NET, and Compact Framework projects. The project I'm building has a dependency on another assembly in my solution, but complains that it can't load it when trying to generate the designer file.

I'm not sure on the exact cause, but this sometimes will happen after we bump up the version number of the assembly. For some reason Visual Studio won't see this assembly as "new" and won't drop the new version in the current project's bin/ folder. Most of the time it does though.

Deleting the bin/ folder (and the obj/ folder for good measure) of the project with the designer error, and then rebuilding, seems to make the hurt go away.

Carl Russmann