Windows Form Designer: Could not load file or assembly

Chien Chern Khor picture Chien Chern Khor · Oct 3, 2008 · Viewed 49k times · Source

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.

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. Does anyone have a understanding of why this error happens in the first place, and possibly the 'correct' way to fix it?

Answer

TcKs picture TcKs · Oct 3, 2008

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 unhandled 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 maybe source code, if the exception was thrown from your code ) and other typical information about thrown exception. This information may be very helpful.