0

We use Fortify to scan the code for our application. In one particular code as shown below

dr["test"] = GetTest(temp.Type!.Substring(0, 1));

Fortify throws null Deference error. So, I changed the code as shown below

dr["test"] = GetTest(temp.Type.Length > 0 ? temp.Type!.Substring(0, 1) : temp.Type);

though I am getting the same Null Deference error. I googled some codes related to null deference but I did not get the exact solution.

Dave
  • 4,794
  • 16
  • 30
  • 38
Zia Zee
  • 17
  • 6
  • Does this answer your question? [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – madreflection Mar 29 '21 at 18:54

1 Answers1

1

If the problem is in temp.Type, you could try validating with IsNullOrEmpty. link

Juan Ozuna
  • 32
  • 4