I am trying to test values before doing some actions with session variables. This is for initializing( As you can see Session("Chemin") is a List of String:
@If (IsDBNull(Session("Chemin")) Or (ViewContext.RouteData.Values("action") = "Index")) Then
@Code Dim lst As New List(Of String)()
Session("Chemin") = lst // Initialisation
End Code
End If
But the problem is with the test here :
@If (Not IsDBNull(ViewContext.RouteData.Values("action")) AndAlso Not IsDBNull(Session("Chemin")) AndAlso Not Session("Chemin").Contains((ViewContext.RouteData.Values("action").ToString()))) Then
I sometimes get
System.NullReferenceException
I don't understand because I am just testing it, and yet it throws me an error. So my question is : Why and when exactly does it happens ? How to fix this ? Edit: not a duplicate because not a simple System.NullReferenceException