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 170743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:51:48+00:00 2026-05-11T12:51:48+00:00

Can anyone explain why, when I step through my unit tests with the debugger,

  • 0

Can anyone explain why, when I step through my unit tests with the debugger, that I get null references whenlooking at objects or properties. For example:

1      [TestMethod] 2            [Description('Test to confirm that upon initial class creation, the login view is loaded as the default content for the TaskRegion.')] 3            public void Shell_Initialisation_LoginViewIsLoadedByDefault() 4            { 5                Shell shell = new Shell(); 6     7                TestPanel.Children.Add(shell); 8     9                Shell_ViewModel viewModel = shell.DataContext as Shell_ViewModel; 10    11               Assert.IsTrue(viewModel.TaskRegionContent is ContentControl); 12    13               EnqueueTestComplete(); 14           } 

[Line 9] When I set my viewModel field to the DataContext of the shell view I get a ‘object not set to instance…’ exception. I know for sure that my datacontext is being set in my shell.xaml.cs; entire file:

1    using System.Windows; 2     3    namespace eg.WorkManager.UI.Shell 4    { 5        public partial class Shell 6        { 7     8            public Shell() 9            { 10               InitializeComponent(); 11               this.Loaded += new RoutedEventHandler(Shell_Loaded); 12           } 13    14           void Shell_Loaded(object sender, RoutedEventArgs e) 15           { 16               this.DataContext = new Shell_ViewModel(); 17           } 18       } 19   } 20    

I know I’m doing something wrong, but can anyone explain what?

Thanks, Mark

  • 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. 2026-05-11T12:51:48+00:00Added an answer on May 11, 2026 at 12:51 pm

    I am guessing that the problem is that you are instantiating the Shell object in isolation. Have you confirmed that Shell_Loaded (the Loaded event) is even being called?

    Why are you not creating your view model as a static resource in your xaml? With MVVM, I usually create it as a static resource in the xaml and then bind it as the data context in the LayoutRoot… all in xaml.

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

Sidebar

Ask A Question

Stats

  • Questions 102k
  • Answers 103k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer From what I can see, you'll be alright with the… May 11, 2026 at 8:20 pm
  • Editorial Team
    Editorial Team added an answer Instead of: expression<int, int> exp(10, 11, >); you could do… May 11, 2026 at 8:20 pm
  • Editorial Team
    Editorial Team added an answer Not bad practice as sometimes a PHP variable's value will… May 11, 2026 at 8:20 pm

Related Questions

Can anyone explain why following code won't compile? At least on g++ 4.2.4. And
I'm trying to capture key presses so that when a given combination is pressed
Not sure what's going on here. I have a DateTime object, and when I
I'm trying to create a custom search interface for Apache Solr using Drupal ,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.