I want to detect the browser language so I can switch languages when people connect to my website.
But when a user hasnt filled in the language in the browsers options I always get a null value with
string browserlanguage = Request.UserLanguages[0]
How could I avoid the error “Object reference not set to an instance of an object.”
Check for
Request.UserLanguages != null.For instance:
Edit: (re your comment) If the above fails, too,
Requestitself was null, which afaik is impossible (could you checkRequest != nullto make sure?). Did you possibly have a null reference later in your code?