Object reference not set to an instance of an object

I get the above error in my wpf solution. When running the mainwindow there is no error - I get my 3 rows as I should. It is “only” on the Error list the error is. The stack trace says it is in this method that the error is LoadCategories().

I have an UI project with my mainwindow. In this I make a reference (to another project) to a UserControl.

It is on this line the Error list gives me the error:

<views:CategoryView x:Name=“CategoryView” Grid.Column=“0” Grid.ColumnSpan=“3” Grid.Row=“2” />

In the UserControl, I make a reference to the ViewModel.Account.CategoryViewModel. In this I have the method

public void LoadCategories()
{
try
{
DalCategory dalCategory = new DalCategory();
Categories_GetAll = new List();
var categories = dalCategory.GetCategories();

            if (categories != null)
            {
                Categories_GetAll = dalCategory.GetCategories();
            }                
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
    }

I have changed this method a lot of times without any help. Can You Please let me know what the error is and most important why:

Thank You very much

Best regards
Simsen :slight_smile:

I do not know what went wrong but this is my LoadCategory;

public void LoadCategories()
    {
        try
        {
            DalCategory dalCategory = new DalCategory();
            Categories_GetAll = new List<Category>();
            var categories = dalCategory.GetCategories();

            if (categories != null)
            {
                Categories_GetAll = dalCategory.GetCategories();
            }                
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
    }
.NET Foundation Website | Blog | Projects | Code of Conduct