I'm running into an issue I can't seem to find the solution to, simply because I don't understand how to fix this NullReferenceException.
I have my constructor;
public MainViewModel()
{
this.Refresh = new DelegateCommand(this.DoRefresh);
//...More like this...
//...and finally...
this.InitializeObjects();
}
then somewhere between properties there is the dependency
[Dependency]
public IUnityContainer Container { get; set; }
and finally the InitializeObjects-method generating the NullReferenceException on 'Container'
private void InitializeObjects()
{
using (var context = this.Container.Resolve<IDbContextScope>())
{
//...remainder of the method...
}
}
The exception is thrown at the 3rd row of this block of code, the row starting with 'using (var ...'
The exception is an ArgumentNullException;
Message "Value cannot be nul.Parameter name: container"
Source = Microsoft.Practices.Unity
StackTrace = at Microsoft.Practices.Unity.UnityContainerExtensions.Resolve....etc..
So my concrete questions are; Is it indeed the IUnityContainer Container throwing the exception? Why does it throw the exception? How do I work around this?
Edit:
As found in the first 2/3 comments under the post, the cause of the NullReferenceException is asserted. However, I still don't know how to work around it, as I don't experience this as your every-day NRE. The function needing the Container is there to initialize the values the program needs to function, and therefore needs to be called INSIDE the constructor. AFAIK I can't just declare the dependency, so how do I work around this..?