asp.net Object reference not set to an instance of an object
1 minute ago, ScottDurkin said:
pModels.models is a List/Dictionary in the MODELS class that is probably not instantiated.
There are basically three options on how to fix this (from best to worst IMO)
1. (Add a function in MODELS to add models). Make a function in MODELS that is called "AddModel". This function inside MODELS will get a string as a parameter, it will check if the list in the class is already instantiated and if not, instantiate it. Then it will add whatever you want, to the list.
2. (Instantiate the list inside MODELS' constructor) The reason why this is not preferred is because you might not always need the list I guess.
3. (Instantiate the list above the pModels.models.Add) That is probably quite bad practice, just like adding something to a class' list outside of said class could be seen as bad practice. Because if someone wants to delete the models-list in MODELS, they now have to check in whatever other classes it is used.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now