Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5959637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:42:47+00:00 2026-05-22T18:42:47+00:00

As usual, I’m trying to use a new technology and having problems right off

  • 0

As usual, I’m trying to use a new technology and having problems right off the bat.

I have a Silverlight Business Application + MvvmLight.

In my viewmodel I try to get the logged in users’ roles:

    public HomeViewModel()
    {
        if (IsInDesignMode)
        {
            // Code runs in Blend --> create design time data.
        }
        else
        {
            // Code runs "for real"                
            DetermineStartableProcesses();
        }
    }

    private void DetermineStartableProcesses()
    {
        _startableProcesses = new ObservableCollection<WorkflowProcess>(
            WebContext.Current.User.Roles.SelectMany(r =>
                WorkflowProcess.GetStartableByRole(r))
                .Distinct());
    }

At runtime, I get this exception:

System.Windows.Markup.XamlParseException occurred
  Message=The invocation of the constructor on type 'CompanyHR.ViewModel.ViewModelLocator' that matches the specified binding constraints threw an exception. [Line: 18 Position: 57]
  LineNumber=18
  LinePosition=57
  StackTrace:
       at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
       at CompanyHR.App.InitializeComponent()
       at CompanyHR.App..ctor()
  InnerException: System.ArgumentNullException
       Message=Value cannot be null.
Parameter name: source
       StackTrace:
            at System.Linq.Enumerable.SelectMany[TSource,TResult](IEnumerable`1 source, Func`2 selector)
            at CompanyHR.ViewModel.HomeViewModel.DetermineStartableProcesses()
            at CompanyHR.ViewModel.HomeViewModel..ctor()
            at CompanyHR.ViewModel.ViewModelLocator..ctor()
       InnerException: 

Looks like the ViewModelLocator is instantiating the ViewModels at app startup before the webcontext get’s created, which means it’s a bad idea for me to do a lot of work in my viewmodel constructors.

So, where at in the viewmodel should I be retrieving data that will get databound?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:42:48+00:00Added an answer on May 22, 2026 at 6:42 pm

    Instantiate your WebContext in the App constructor. then add it to your resources in the App_startup before you call

    public App()
            {
                Startup += Application_Startup;
                Exit += Application_Exit;
                UnhandledException += Application_UnhandledException;
    
                if (IsInDesignModeStatic)
                {
                    Services.ServiceLoader.LoadDesignTimeServices();
                    DispatcherHelper.Initialize();
                }
                else
                {
                    try
                    {
    
                        ServiceLoader.LoadRunTimeServices();
                        DispatcherHelper.Initialize();
    
                        WebContext webContext = new WebContext();
                        ApplicationLifetimeObjects.Add(WebContext.Current);
    
                        FormsAuthentication fa = new FormsAuthentication();
                        fa.DomainContext = new Web.Services.AuthenticationDomainContext();
                        WebContext.Current.Authentication = fa;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }
    
                InitializeComponent();
            }
    
    
    
    private void Application_Startup(object sender, StartupEventArgs e)
            {
                this.Resources.Add("WebContext", WebContext.Current);
    
                RootVisual = new MainPage();
    
            }
    

    I find its easier to do this part in the code behind because of my custom AuthenticationDomainContext and Membershipprovider…But Dereks works well too, i just was using the code behind while i was getting everything working.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have the usual web.xml for our web application which includes some jsp and
The usual pattern for a ReadWriteMutex is to use a semaphore and have the
I have a shop system that integrates PayPal in the usual way, i.e. the
As usual, regular expressions are causing my head to hurt. I have the following
The usual way to use Qt widgets from Python seems to be to subclass
as usual i come here after testing around for hours and not having any
My usual workflow with git is to create a new feature branch, do some
I have the usual polymorphic associations for comments: class Book < ActiveRecord::Base has_many :comments,
So as usual I have an issue with ria service + nhibernate. The question
I have the usual type or namespace name does not exist error, except that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.