The problem is likely with CslaDataSource... At least if you are using 2.0.1 or higher.
The broader issue is this:
The Web Forms designer does some funky stuff with shadow directories so it can reload your assemblies during development as you change them. In other words, your assemblies aren't loaded directly, but first they are copied into a shadow directory and they are loaded from there (presumably into a temporary AppDomain). This allows Visual Studio to reload them when you change them over time.
The CslaDataSource also needs to load your assemblies (at least the one you reference with the control) in order to get at its metadata. This is discussed in the book, and you can see there how the metadata is loaded from the assembly in order to provide the right shape and sample data for the Web Forms designer.
The version of CslaDataSource in the book just uses straight reflection to load the assembly - which you'd think would work fine, but it doesn't. The reason it doesn't work is that the CONTROL is loaded from the first shadow directory created by VS and it is never unloaded. When CslaDataSource uses reflection to load the business assembly, that assembly is loaded into that same, unchanging, AppDomain from that same, original, shadow directory.
If you then change and rebuild the business assembly, the new version goes into a new shadow directory - but CslaDataSource continues to load from that original shadow directory, and continues to run in that original AppDomain.
So the trick then, is to figure out how to get CslaDataSource to load your updated business assembly from the new shadow directories as they are created. And to load them into new AppDomains so they can be unloaded over time too. Unfortunately it doesn't appear that there's any supported way within .NET to actually do this.
So what I did in 2.0.1, concious that this is a hack, is to infer the path of the shadow directory based on where CslaDataSource comes from. Using that information I can find all the other shadow directories used by VS, and I can find the latest one and then I can load your business assembly from that location.
This appeared to work fine in my testing - I used it on various simple projects. I don't know though, that I tested it with a virtual root that is hosted in IIS, or if I just tested with Cassini.
I am also nervous about possible changes when using the upcoming web project concept that Microsoft is currently testing. If that somehow changes the way the shadow directories are created/used it would break my code as well.
So I'll repeat my original plea - if anyone does know of a way to get the path to the current shadow directory I'll gladly put it into the control.
Otherwise, any help tracing down the specific details of any failure cases is also greatly appreciated. Specifically, tell me how you created the project, the web page, how you referenced the business library, etc.
I'll be honest - debugging web controls is a serious pain. It is a long, tedious process of debugging and sometimes doing tons of trace statements into a log. Getting CslaDataSource to where it is has taken more hours of work than any other single part of CSLA .NET.
But given detailed info about failure scenarios I'm glad to try and replicate them in an attempt to find solutions to get the control working.
Hmm. I don't know what is different about your configuration. If you are willing, perhaps we can work to figure it out.
Debugging a web UI control is not fun, but it is possible. I think the first thing to do is figure out what path the control is trying to use when looking for the assembly - then you can see if there's actually an assembly by that name at the path.
To do this, do the following:
VS #2 should pop up in the debugger at your breakpoint. You should be able to step through the GetType() method to see the path and file name of the assembly it is trying to load. That might provide some insight into where it is looking and why it can't find it.
I'm getting the same error when I set the DataSourceID of a gridview to a CslaDataSource.
Error setting value 'VenDataSource' to property 'DataSourceID'. Details: Could not load file or assembly 'file:///C:\WINDOWS\assembly\GAC_MSIL\Csla\2.0.1.0__93be5fdc093e4c30\MyDLL.dll' or one of its dependencies. The system cannot find the file specified.
MyDLL is a project reference and it's not in the GAC. I'm not sure why it's looking in the GAC.
Any help would be appreciated. Thanks.
From: mking [mailto:cslanet@lhotka.net]
Sent: Monday, July 03, 2006 4:34 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] CslaDataSource error - Please HelpI'm getting the same error when I set the DataSourceID of a gridview to a CslaDataSource.
Error setting value 'VenDataSource' to property 'DataSourceID'. Details: Could not load file or assembly 'file:///C:\WINDOWS\assembly\GAC_MSIL\Csla\2.0.1.0__93be5fdc093e4c30\MyDLL.dll' or one of its dependencies. The system cannot find the file specified.
MyDLL is a project reference and it's not in the GAC. I'm not sure why it's looking in the GAC.
Any help would be appreciated. Thanks.
RockfordLhotka:Did you put Csla.dll into the GAC? That is not a scenario I have tested, but it could easily lead to problems - ones that I do not know how to resolve.As I've discussed in previous threads, the original CslaDataSource implemention in the book suffers from the problem that it doesn't reload your business assembly as it changes over time. On the upside, it does work fine as long as you are willing to close VS each time you update your business assembly. :-(To fix this, version 2.0.1 does some trickery. Since Microsoft doesn't provide any way (that I or any of my contacts can find) to determine the current shadow directory from which the business assembly is being loaded by VS, I am stuck. So what I do is look at the directory from where Csla.dll is being loaded, and then infer the shadow directory path from that directory.If you put Csla.dll into the GAC it would totally throw that scheme off - and it would also leave me with no way at all to find the shadow directories...Yes, this is unfortunate. No, I am not pleased with the current solution. But no, I have no better alternative. Neither 2.0 nor 2.0.1+ are good answers - but lacking any solution to find the shadow directory, these are the choice we are faced with at the moment...RockyThanks for the help, Rocky. I really appreciate it. (Hope you're feeling better.)
I did have Csla.dll in the GAC. (It was also a project reference in my solution.)
When I removed Csla from the GAC, I started getting a different error which I corrected by switching from the project setting of "Use default web server" to "Use custom server".
Now I'm able to use the CslaDataSource control at design time.
-Mike
Thanks for the help, Rocky. I really appreciate it. (Hope you're feeling better.)
I did have Csla.dll in the GAC. (It was also a project reference in my solution.)
When I removed Csla from the GAC, I started getting a different error which I corrected by switching from the project setting of "Use default web server" to "Use custom server".
Now I'm able to use the CslaDataSource control at design time.
RockfordLhotka:The proposed changes for 2.0.3 (in cvs) _should_ allow you to put Csla.dll into the GAC - and should provide more reliable results overall. In my limited testing these changes resolved the quirky issues I was having from time to time, which is encouraging.If you get a chance, Mike, would you be willing to try those changes?Thx, Rocky(Thanks for the well wishes; I'm starting to feel better - summer colds are just no fun at all...)
Sorry for the delayed response.
I used cvs to get your code and upgraded my machine from 2.0.1 to 2.0.3. I put Csla back in the GAC. Now I do not get the design time error I was getting before. Now I can start my web site from Visual Studio using either "Use default Web Server" or "Use custom server".
I haven't done any other testing of the web site. I will post any problems I find that are new to 2.0.3.
Thanks for coding the fix.
-Mike
RockfordLhotka:To fix this, version 2.0.1 does some trickery. Since Microsoft doesn't provide any way (that I or any of my contacts can find) to determine the current shadow directory from which the business assembly is being loaded by VS, I am stuck. So what I do is look at the directory from where Csla.dll is being loaded, and then infer the shadow directory path from that directory.Are all the shadow directories for a project off of the same root directory? If so, why not just take the latest version (by file timestamp) in any shadow directory you find?I'm betting it's not that easy, but...
From: david.wendelken [mailto:cslanet@lhotka.net]
Sent: Thursday, August 03, 2006 9:21 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] RE: CslaDataSource error - Please HelpRockfordLhotka:To fix this, version 2.0.1 does some trickery. Since Microsoft doesn't provide any way (that I or any of my contacts can find) to determine the current shadow directory from which the business assembly is being loaded by VS, I am stuck. So what I do is look at the directory from where Csla.dll is being loaded, and then infer the shadow directory path from that directory.Are all the shadow directories for a project off of the same root directory? If so, why not just take the latest version (by file timestamp) in any shadow directory you find?I'm betting it's not that easy, but...
RockfordLhotka:That's exactly what I do :)The problem is that I need to find the shadow directory root path to start with - and I do that by loading the type in the first place (using GetType(), which gets it from the original shadow directory). With a new class that GetType() call fails...I don't think I was clear. (Then again, maybe I was and I'm just wrong this time! :)My machine has thousands of directories on it, but VS Studio surely isn't randomly picking a different one each time to build a shadow directory in. Surely it uses the same directory to build each shadow directory structure in? Each and every time? Or at least for any given solution or project?If so, and if I record that directory someplace where your code can find it, then a search of all directories underneath it for the latest version of the assembly in question would seem like it would work.Ok, it's a kluge, but so its the whole moving shadow directory idea. You can put lipstick on the pig, but it still wallows in garbage.
From: david.wendelken [mailto:cslanet@lhotka.net]
Sent: Thursday, August 03, 2006 11:22 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] RE: RE: CslaDataSource error - Please HelpRockfordLhotka:That's exactly what I do :)The problem is that I need to find the shadow directory root path to start with - and I do that by loading the type in the first place (using GetType(), which gets it from the original shadow directory). With a new class that GetType() call fails...I don't think I was clear. (Then again, maybe I was and I'm just wrong this time! :)My machine has thousands of directories on it, but VS Studio surely isn't randomly picking a different one each time to build a shadow directory in. Surely it uses the same directory to build each shadow directory structure in? Each and every time? Or at least for any given solution or project?If so, and if I record that directory someplace where your code can find it, then a search of all directories underneath it for the latest version of the assembly in question would seem like it would work.Ok, it's a kluge, but so its the whole moving shadow directory idea. You can put lipstick on the pig, but it still wallows in garbage.
I am also now getting this error in the designer. The web app seams to function, but I cannot modify my FormView.
From: Truth [mailto:cslanet@lhotka.net]
Sent: Tuesday, July 04, 2006 12:34 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] CslaDataSource error - Please Help
Haven't been able to get very far with solving it.
Jeff
Maybe stress isn't all bad. I've got an incredibly bad head cold, primarily due to overdoing it during this long 4th of July weekend (swimming, waterskiing, knee-boarding, tubing, camping, etc.). So I thought I'd lay down and catch a bit of a nap before we head out to watch the fireworks (kids gotta have their fireworks, even if I can't breath )
Anyway, as is often the case, as I was drifting off to sleep my brain solved the issue - or at least so I hope.
If you go to www.lhotka.net/cslacvs you can download Csla\Web\Design\TypeLoader and Csla\Web\Design\ObjectViewSchema (in either VB or C#). Replace your 2.0.1 or 2.0.2 files of the same names with these and rebuild Csla.dll.
What I am now doing is getting the business type like I did with version 2.0. But I'm not using that Type object; instead I'm just using it to find the original (typically old) shadow directory path. Then I pass that path to the temporary AppDomain like in 2.0.1, so I can find the shadow directory for the most recent business assembly.
This seems to get the right path, without issues around having Csla.dll in the GAC and so forth.
If those of you having immediate problems could download and try these two files - and let me know your results - I would appreciate it. If it is a real fix I'll put it into 2.0.3.
It does appear to solve the issue. Will need a bit more validation though to prove it.
From: Truth [mailto:cslanet@lhotka.net]
Sent: Friday, July 07, 2006 1:20 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] CslaDataSource error - Please Help
Here's what happended:
I ran into the same issue as previously mentioned, so I grabbed those files from CVS and rebuilt CSLA.dll (C# version). I then replaced all versions of csla.dll I had locally with the newly compiled version. When I reloaded the project the CSLDADataSource objects no longer appeared broken, but when trying to set a GridView datasource, I got a different error related to not being able to find CLSA version 2.0.2 (or something similar). I just redragged the CSLADataSource component back onto the form and all was fixed. (Sounds like just an issue with having rebuilt CSLA and getting a reference to it).
Jeff
Rocky,
I've applied the changes from the 2 files in CSV and it seemed to work fine on the page I was working on at that time (a week ago), this cslaDataSource control made use of a library.dll not included in the solution (just a reference). Now I'm picking up where I left of last week, in the same project and am now trying to use the cslaDataSource in several new pages but I can't seem to get it to work again, trying to use a library.dll wich is part of the solution. I can click on 'Refresh schema' without errors occuring, but when I then try to set the datasource of a gridview to the cslaDataSource I get the following error
'Could not load file or assembly 'avuCsla' or one of its dependencies. The system cannot find the file specified.'
I know that all references used in my avuCsla project are also in my avuWb web application. It's driving me nuts, I can't make any progress...
I have also tried not to reference the project avuCsla in my webapp but directly reference the dll in the bin\debug folder but that doesn't help either.
I do not have any of my assemblies (or Csla ) in the GAC.
Regards,
Jurjen.
P.S. I am using Petar's ActiveObjects
Jurjen,
I'm using VB with the 2 files in CSV and attached to the devenv process that Rocky referred to in this thread. It errored loading the assembly in CslaDataSource.[GetType]. Turns out the reference to the assembly is case sensitive and I was off one letter in my .aspx file. (TypeAssembly="RnD.Library" vs. TypeAssembly="RND.Library")
jwinkjwink,
You're right, that solved it, TypeNameAssembly is also case-sensitive... It works great now...
jurjen.
I realize this isn't always easy - but if you can provide details about how you were doing your development up to the failure that would help. I obviously have no way to try and replicate a sporadic problem without details...
In particular, did you just reference the business dll, or just rebuild it? Did you set up the CslaDataSource first, or the grid/details control first? Were you editing a different page just prior to editing this page? Is this a new page or an existing page?
The more detail you can provide, the more likely it is that I'll be able to help.
I have noticed that when on a Form I drag a new Control, say a GridView, and from the Choose Data Source dropdown in GridView Tasks I select <New Data Source>, I get an error that says;
"Error setting value '<New Data Source...>' to Property DataSourceID. Details: The path is not a legal form."
When I click Ok, and select <New Data Source> again, invariably the Data Source Configuration Wizard comes right up, including the CslaDataSource as an option.
I have always assumed that this was problem with Asp and not with Csla.
Jav
FYI - I'm using CSLA version 2.0.3.0 and I'm still getting the file not found error when using the CSLADataControl in design time. It happens sporadically. I just closed visual studio 2005, opened it back up again, and now the error is gone.
From: mking [mailto:cslanet@lhotka.net]
Sent: Thursday, August 03, 2006 11:27 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] CslaDataSource error - Please Help
Copyright (c) Marimer LLC