none
Don't know how to resolve a CS 1061 error RRS feed

  • Question

  • I'm working on a team developing a new WPF app. This app is going to be used by people throughout the organization, throughout the state. I'm concerned about network latency, so I'm trying to implement async/await. We're using . NET 4.6 and Entity Framework. My colleagues are all wedded to using EF's older .EDMX technology. So, that isn't changing. 

    Here's the async method I wrote:

    public async Task<IList<Program>> GetProgramsForOrganizationAsync(long OrgID)
    {
    	IEnumerable<Program> programs;
    
    	using (var context = new AppEntities())
    	{
    		programs = await context.Programs.Where(p => p.OrgID == OrgID).ToListAsync();
    	}
    
    	return programs.ToList();
    }
    

    The problem I'm having is where to place the call to GetProgramsForOrganizationAsync. I've read where you shouldn't put it in the classes constructor. So I'm leaving it out of that. Placing it in a property setter seems like the most advantageous, because except for the constructor and a few other methods for storing data or a few like GetProgramsForOrganizationAsync, which is new, the rest of the viewmodel is just a lot of properties. So, modifying the solution given in the link I've included, I've come up with putting this into one of the property's setter:

    public Organization SelectedRow
    {
    	get { return _dataHandler.SelectedRow; }
    	set
    	{
    		_dataHandler.SelectedRow = value;
    		TableHeader = _dataHandler.TableHeader;
    		Organization = value;
    		RaisePropertyChanged("SelectedRow");
    		GetPrograms(value.ID).GetAwaiter().GetResult();
    	}
    }
    

    And here's the definition of GetPrograms():

    public async Task GetPrograms(long iD)
    {
    	var tmp = await GetProgramsForOrganizationAsync(iD);
    	Programs = tmp.ToList();
    }
    

    However, if I run it, the application hangs. If I debug it, it also hung, but I was able to narrow down where it hung. It hangs on this line in the SelectedRow setter:

    GetPrograms(value.ID).GetAwaiter().GetResult();

    When the breakpoint hit that line, I could see in the watch window this error:

    "error CS1061: 'OrganizationViewModel' does not contain a definition for 'DataContext' and no accessible extension method 'DataContext' accepting a first argument of type 'OrganizationViewModel' could be found (are you missing a using directive or an assembly reference?)"

    I don't get where this error is coming from. I certainly don't know how to resolve it. And the pressure of getting this out the door is so great that for now I'm going to have to go with our old approach of doing everything synchronously. But I'd really rather not as I believe it will only cause problems for remote users down the road.


    Rod

    Friday, September 6, 2019 7:29 PM

All replies

  • Hi,

    OrganizationViewMode is your custom class?DataContent is FrameworkElement.DataContext Property,see FrameworkElement.DataContext ,see the following error:

    https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs1061

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, September 9, 2019 7:10 AM
    Moderator
  • Yes, OrganizationViewModel is my customer viewmodel class, based upon MVVM Light's ViewModelBase class.

    Why then does the line:

    GetPrograms(value.ID).GetAwaiter().GetResult();

    in the SelectedRow property need a DataContext?


    Rod

    Monday, September 9, 2019 8:49 PM
  • Hi,

    You need to check where your code declares an OrganizationViewModel object and use the DataContext property.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, September 16, 2019 6:15 AM
    Moderator