wpf - Why do I get error "ArgumentException was thrown on "ViewModelLocator": Cannot create an instance of "ViewModelLocator" -


i have narrowed down simple method attempting fill observable collection entity model. don't know if i'm doing correctly.

note: appears designer error. can build , run program...so appears.

    private observablecollection<lessongroup> lessongroups;     public observablecollection<lessongroup> lessongroups     {         { return lessongroups; }         set { lessongroups = value; raisepropertychanged("lessongroups"); }     }       private void getlessongroups()     {         //this using statement causes argumentexception         using (myentities ae = new myentities())         {             foreach (lessongroup lg in ae.lessongroups)             {                 lessongroups.add(lg);             }         }     } 

exception follows:

the specified named connection either not found in configuration, not intended used entityclient provider, or not valid.    @ system.data.entityclient.entityconnection.changeconnectionstring(string newconnectionstring)    @ system.data.entityclient.entityconnection..ctor(string connectionstring)    @ system.data.objects.objectcontext.createentityconnection(string connectionstring)    @ system.data.objects.objectcontext..ctor(string connectionstring, string defaultcontainername)    @ impact.arctrainer.model.arctrainerentities..ctor() in c:\users\leland\documents\visual studio 2010\projects\arctrainer\model\arctrainer.designer.cs:line 56    @ impact.arctrainer.viewmodel.lessonsviewmodel.getlessongroups() in c:\users\leland\documents\visual studio 2010\projects\arctrainer\viewmodel\lessonsviewmodel.cs:line 171    @ impact.arctrainer.viewmodel.lessonsviewmodel..ctor(viewmodellocator viewmodellocator) in c:\users\leland\documents\visual studio 2010\projects\arctrainer\viewmodel\lessonsviewmodel.cs:line 37    @ impact.arctrainer.viewmodel.viewmodellocator..ctor() in c:\users\leland\documents\visual studio 2010\projects\arctrainer\viewmodel\viewmodellocator.cs:line 46 

getlessongroups seems called within constructor of class lessonsviewmodel.

this method make call myentities , looks entity framework context not same project gui project.

to resolve issue, best way have check wether in design mode or not. if using mvvm light, can check isindesignmode property (and thus, call getlessongroups method if property false).


Comments