Creating sample data from a class in Blend throws "Object reference not set to object instance"

I am trying to create some sample data from my ViewModel classes in Expression Blend. However, Expression Blend stops and says: "The reference to the object is not set to the instance of the object." Personally, I do not understand where this exception comes from.

Does anyone have an idea why this is happening?

This is my UserListViewModel:

[Export] public class UserListViewModel : ViewModelBase { [ImportingConstructor] public UserListViewModel(IUserListView view) : base(view) { } private ObservableCollection<UserItem> _userList; public ObservableCollection<UserItem> UserList { get { return _userList; } set { if (_userList != value) { _userList = value; RaisePropertyChanged("UserList"); } } } private UserItem _selectedUser; public UserItem SelectedUser { get { return _selectedUser; } set { if (_selectedUser != value) { _selectedUser = value; RaisePropertyChanged("SelectedUser"); } } } private string _searchText; public string SearchText { get { return _searchText; } set { if (_searchText != value) { _searchText = value; RaisePropertyChanged("SearchText"); } } } private ICommand _searchCommand; public ICommand SearchCommand { get { return _searchCommand; } set { if (_searchCommand != value) _searchCommand = value; } } // ... other ICommands } 

Thank you in advance for your help,

Cheers, G.

+6
c # viewmodel mvvm mvvm-light expression-blend
source share
2 answers

UPDATE! Laurent (author of MvvmLight) has published how to debug development time data. Blog post here.

I found the cause and solution of this error in Blend or when opening .xaml in Visual Studio.

The reference to the object is not installed in the instance of the object.

Blend tries to run development-time code, and if it removes the null pointer somewhere, this is the error you get.

So, keep track of your code by creating development time data. Most likely, you forgot to initialize something, or maybe you have the wrong type.

It would be easy to find if you could have breakpoints when the designer runs the user code, but I don't think it is possible.

+1
source share

When you ran into this problem, I found that the attributes of my properties are causing this error message.

Commenting on [ImportingConstructor] and [Export] when creating sample data (compile the project once with Blend, so as not to work with the old version), you can do the trick here.

0
source share

All Articles