Got a wonderful little error yesterday that had me pulling out my hair of which I have less and less each day. It starts with "System.TypeLoadException: Could not load type" and ends only after a good 4 or 5 hours of trying to deduce the problem through my code.
Here's a little background:
- VS.net 2008 Desktop Application (2.0 framework, 9.0.21022.8 RTM)
- Class library for container objects sent
- Class library for data layer which pulls information, creates the container objects, then returns the container objects to the caller.
Simple enough. Here is how I reproduce the error:
- Have a container class library project with one class in it.
- Have a desktop app project with a datasource associated to that container project's single class.
- Recompile
- Close solution
- Open solution
- Recompile
- Add a new container class in the container Class library called Test.
- Rebuild your desktop app which should already have a project reference to the container class library.
- Add a new datasource pointing to that new object called Test.
- Create a new User Control called ctlTestControl
- Drag the datasource item 'Test' to the ctlTestControl. You should now have a datagrid with the container class's public fields as columns in said grid.
- Recompile
- Now attempt to add the control from your toolbox in your desktop apps Components section of the Toolbox.
- This is where I get the fun error:
'System.TypeLoadException: Could not load type '.......
Research:
Here is where I got the answer to my problem: http://support.microsoft.com/kb/873267
The title of this kb article is:
You may receive a System.TypeLoadException exception when you try to preview a report in Report Designer after you install SQL Server 2000 Reporting Services Service Pack 1 (SP1)
This directed me to C:\Documents and Settings\
What I noticed from looking at the files in the directories under ProjectAssemblies is that every time I rebuild my app it adds more directories and leaves the older compiled dll directories. So every time you rebuild the app, a new directory will appear in ProjectAssemblies, at least when you are developing a desktop app(haven't checked web apps, etc).
- Closed solution (which happenned to delete all the associated subdirectories of ProjectAssemblies as described above)
- Openned solution
- Recompiled
- Successfully added control to form
Perhaps my install is out of date, perhaps I have a setting out of whack, don't really care. All I care is that my...
Fury is contained...
Thank you so much for posting this. I had the same problem with a user control I created.
ReplyDeleteIt wasn't enough for me to just close/open/recompile the solution, I actually had to close down Visual Studio (2008 SP) & restart it, but your post gave me the clue as to what I should be doing.
What an odd little bug..
Your post was VERY helpful!
Thank you,
Yann
Thank you!!! I had the same problem and I've been dealing with this for hours.
ReplyDeleteSeriously this problem is really annoying there must be a way to configure Visual Studio not to cache files or a fix release.
Pablo