Object reference not set to an instance of an object?

"YOU AND THE ART OF ONLINE DATING" is the only product on the market that will take you step-by-step through the process of online dating, provide you with the resources to help ensure success. Get it now!

Either ag is null, the FirstOrDefault call is returning null arrangement is null, or parent is null Only you are in a position to determine which one of those is actually the culprit.

Either ag is null, the FirstOrDefault call is returning null, arrangement is null, or parent is null. Only you are in a position to determine which one of those is actually the culprit.

1 I would recomend use debuger or divide it into multiple statements. – Euphoric Apr 28 at 11:38.

If the property ag.FirstOrDefault().arrangement.parent. Name is null it means the object ag is null also. This is the reason you are getting object reference error.

The answer Leons provided is actually what I was going to suggest. You need to do some research on the problem its one of the simplest thing to avoid ( trying to reference a null object ) in programming.

It doesn't necessarily mean ag is null. Ag might be null; the output of FirstOrDefault might be null; the arrangement member might be null; the parent member might be null. – LukeH Apr 28 at 11:50.

You cannot access the properties of a null object. If ag.FirstOrDefault() will return null, then you will not be able to access arrangement. Var temp = ag.FirstOrDefault(); string pname = (temp!

= null)? Temp.arrangement.parent. Name : null; You may need to do further null checking.

Try var obj = ag.FirstOrDefault(); if( obj! =null) pname = obj.arrangement.parent. Name?String.

Empty; or you can try //This will set the variable to null: var obj = ag.FirstOrDefault(); if( obj! =null) pname = Convert. ToString(obj.arrangement.parent.Name); Note : ag.FirstOrDefault().arrangement.parent.

Name is nullable type.

2 This will throw an exception if ag.FirstOrDefault() return null – Leons Apr 28 at 11:43 The filed parent. Name is empty(null) -- this line is written by op anyways I am updating my ans – Pranay Rana Apr 28 at 12:08.

If the model is not valid and you are unable to do execute some of your code in the.

Don't forget to pass the model to the view.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions