One of my biggest complaints about using CSLA has been the issue of Visual Studio’s failure to work correctly in the watch window with CSLA objects.
I wrote a post a while back about my issues:
So for example I have a simple list called “projects” which is of type ProjectList containing ProjectListItems.
If I put “projects” in the watch window, for Value I get:
“Count = {System.TypeLoadException}”
If I put “projects(0)” in the watch window, I get:
{“The generic type ‘System.Collections.ObjectModel.Collection`1’ was used with the wrong number of generic arguments in assembly ‘mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’.” : “System.Collections.ObjectModel.Collection`1”}
Rocky’s response was:
This is a known issue. I’ve actually talked to the VS debugger team about this, and they didn’t have a satisfactory answer – and certainly not a solution. This issue has existed since 2005 when generics were introduced into .NET.
Well, after doing some digging I think I have come across a few work arounds.
If I were to use the Watch Window and put:
projects.Count
it would throw an error. But if I put:
projects.Count.ToString
then I get the correct result.
Also when picking a specific item:
projects.Item(2)
I get the same exception. However, if I use:
CType(projects.Item(2),Object)
I get the object as expected!
I hope this helps out others as this is really important when debugging an application.