Wednesday, February 07, 2007
« Does workflow compete with CSLA .NET? | Main | ADO.NET Entity Framework, LINQ and CSLA ... »

I have a custom data source control as part of my CSLA .NET framework. It is somewhat like ObjectDataSource, but works with objects that are created through factory methods rather than default constructors (and some other variations).

 

All is pretty well with this control, except one issue: it fails when adding a CslaDataSource control to a page as a new data source from a DetailsView or other control.

 

In other words, you add a DetailsView to the page, then tell that control you want it to bind to a new data source and it brings up a wizard, where you pick CslaDataSource so a new one is added to the page.

 

The problem I’m getting is a VERY odd exception: Csla.Web.CslaDataSource can not be cast to Csla.Web.CslaDataSource.

 

Yes, that’s right – the type can’t be cast to itself.

 

I believe this is because the wizard is loading its own copy of Csla.dll into memory, separate from the one used by the web forms designer. Or something like that. This even confuses the debugger – it can’t show details about the type because it says the type is loaded into two different GUIDs. I don’t know what the GUIDs represent (appdomains, versions?), but it is obviously not good.

 

This is very weird, and after hours of time on this, I’m quite stumped. Any help, clues, pointers or ideas are VERY welcome!

 

Thanks! Rocky

Wednesday, February 07, 2007 3:40:22 AM (Central Standard Time, UTC-06:00)
Any chance you're loading some combination of 1.0, 1.1 or 2.0 framework assemblies?

James.
Wednesday, February 07, 2007 4:00:59 AM (Central Standard Time, UTC-06:00)
I have the same thing with my LLBLGenProDataSource(2) controls. When I flip to html and back to design it's OK. Very strange. Though as you also know, it's not the first strange thing you'll run into as a datasourcecontrol developer... Luckily, the bug with the error that the control couldn't find any types in the referenced project is fixed in SP1 for vs.net 2005, though I have the feeling this is related, so indeed, the loaded type is in a different appdomain or something...

As it seems to be easily fixed with a simple workaround (flip to html, flip back), I wont look into this for now, also because it's already a pain in the *** to develop a datasourcecontrol, debug it and get around the myriad of issues with asp.net at that level, plus in orca's the complete designer is replaced with apparently better code, so...
Wednesday, February 07, 2007 9:16:15 AM (Central Standard Time, UTC-06:00)
Weird that I am experiencing a similar issue at the same time...my quick solutions was to GAC the CSLA dlls...however, that's not the solution I want long term.
Owen Graupman
Wednesday, February 07, 2007 12:03:59 PM (Central Standard Time, UTC-06:00)
Yes, the GAC is a solution - but as you say, it is not a _good_ solution.

It is really unclear why the wizard would somehow load a different instance (or version?) of Csla.dll from the one loaded by the web page designer - but that appears to be what is happening. The result is confusion for VS, as the page surface ends up with what appears to be the same thing, when in memory they are different...
Wednesday, February 07, 2007 2:17:10 PM (Central Standard Time, UTC-06:00)
If you flip to html view and back, it's fixed?
Wednesday, February 07, 2007 2:34:09 PM (Central Standard Time, UTC-06:00)
Yes, exactly.

This may be an issue with VS more than with ASP.NET or the page designer.
Friday, February 09, 2007 6:42:11 AM (Central Standard Time, UTC-06:00)
I have a similar problem with my business objects in my WinForms applications:

When I rebuild my Business-DLL and then rebuild my WinForms application, I can’t load my User Controls and Forms into the designer any more. I get a “Csla.SmartDate can not be cast to Csla.SmartDate” exception or a “XYZ.Business.Order can not be cast to XYZ.Business.Order” exception.

Even restarting Visual Studio after every build doesn’t work. I must search for all Bin- and Obj-folders in my Project-directory, delete them, and rebuild all projects again before I can use the designer again. After installing SP1 it works better now, but sometimes this problem still occurs...

Christian
Christian
Friday, February 09, 2007 5:20:08 PM (Central Standard Time, UTC-06:00)
I believe this is probably because you are loading the DLL that contains your type twice. Check your code to see if you are calling Assembly.Load/LoadFile/LoadFrom anywhere in your application. I encountered the same problem when I was displaying all available objects in my own custom data binding control.

Also encountered this when I was examining and loading a directory of assemblies for any assemblies marked with a custom attribute, the custom attribute was declared in a dll that I was also loading (it was also in the /bin) so the tests would fail like 'typeof(xyz).IsAssignableFrom(typeof(MyCustomAttribute))' and even 'myAttribute is MyAttribute'.
Friday, February 23, 2007 9:31:46 AM (Central Standard Time, UTC-06:00)
To close this out, it does turn out to be a bug in VS. VS is loading the assembly once in the page designer appdomain, and then again in some other appdomain used by the wizard. I've provided the bug info to Microsoft, so hopefully we'll see a fix sometime in the future.

Until then, the CslaDataSource can be added using the <add datasource> wizard, but you have to switch to Source view and back again in the designer before you can actually interact with the new control.
Wednesday, March 21, 2007 5:18:10 PM (Central Standard Time, UTC-06:00)
Thanks for posting this - I ran into the problem on two different web pages. On one web page, I can set the datasource property on my grid control and on the other webpage I cannot (unable to cast...). The only way it worked in that situation was to set datasource programmatically on first page load. From your description, it looks like I need to walk through the setup a little differently.
Comments are closed.