"Add New Data Source" - where's my ViewModel?

"Add New Data Source" - where's my ViewModel?

Old forum URL: forums.lhotka.net/forums/t/9442.aspx

skagen00 posted on Friday, August 27, 2010

Using 3.8.3 right now.

Wanted to add my ViewModel as a data source and then drag it over onto my XAML control, but it doesn't show up when I browse through the project (to click on and select as a new object data source).

Anyone else run into this?

(This is in "Data Sources", "Add New Data Source", "Object")

RockfordLhotka replied on Friday, August 27, 2010

The Data Sources window uses reflection to find types. So you have to build your solution before it can reflect against your assemblies. Maybe that's the issue?

RockfordLhotka replied on Friday, August 27, 2010

Of course this only works in VS10 - so I assume you aren't trying this in VS08.

skagen00 replied on Friday, August 27, 2010

We have rebuilt & then some, yep.

I manually finagled the file by adding a datasource to something else and editing the actual data source file that got created (I am actually OK now), but my coworker who did a GLV simply sees:

'ProductName.Silverlight.ViewModels.OrganizationViewModel is no longer available. Verify the class name is correct and the reference to this class is still valid.'

I was just going to confirm in this reply that going into the add new data source shows everything except the view model, and this time it decides to start showing up.  We rebuilt, cleaned solution, closed VS and reentered, refreshed,...  I'd swear it wasn't there earlier.

So now I can see everything properly, including ViewModels, when browsing for data source within Add New Data Source (including ones I just create and then build project) and he can see everything except the view models.

I'm sure we'll figure it out, but I'm certainly confused.

(Yes VS 2010)

ajj3085 replied on Friday, August 27, 2010

I had a problem where I couldn't find the datasources because there was a type exposed but wasn't referenced.  For example, I was accidently exposing a class from my DAL in my business layer.  The UI worked when run because it never invoked anything that actually needed that class, but just the fact that it was publicly visible was enough to screw up VS. 

Maybe something similar which you've since resolved?  I don't know if that happens in VS2010 though, but I know it was a problem for me in 2008.

skagen00 replied on Saturday, August 28, 2010

I'm not sure what the actual answer was - my coworker had some assemblies in a common public ssemblies directory from some earlier task that he said when removed allowed him to select his ViewModels - and my messing around by adding a datasource to some other class and then manually changing the file seemed to press some magic button for me.

Regardless, both of us can see our ViewModels when adding a new data source now.  I'm still not sure exactly what the problem/solution combination was.

Thanks for the replies

JonM replied on Friday, January 28, 2011

I'm working on my first CSLA Silverlight MVVM project and I just hit this!  If I change my viewmodel class to be a ViewModel<object> instead of ViewModel<MyCSLBusinessClass> and compile it shows up in my data sources window.  If I change it back to ViewModel<MyCSLABusinessClass> it doesn't show up! 

That tells me it is something wrong with my business class.  ;(

Any suggestions would be appreciated.

RockfordLhotka replied on Friday, January 28, 2011

The VS designer will actually instantiate the type as you do drag-and-drop. So if there's something blocking the type from instantiating (like it tries to talk to the database when in design mode) that'd cause this issue.

JonM replied on Friday, January 28, 2011

I took all the code out of my ViewModel except for I made it a ViewModel<MyCustomerCSLAclass>.   That was enough to keep it from showing up.  So here's my work around.  Change the code to ViewModel<object>.  Then it shows up in the list.  Add it to your datasources.  Then change it back and recompile.  It still shows up.

RockfordLhotka replied on Friday, January 28, 2011

Yeah, in that case the problem is almost certainly that your viewmodel's constructor is calling DoRefresh or BeginRefresh when in design mode - which calls the business object factory, which tries to call the data portal and fails because the data portal isn't configured to run inside Visual Studio.

Copyright (c) Marimer LLC