totpero / DeviceDetector.NET

The Universal Device Detection library will parse any User Agent and detect the browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), brand and model.
Apache License 2.0
348 stars 73 forks source link

Parse() crashes if userAgent is null #13

Closed garychapman closed 5 years ago

garychapman commented 5 years ago

Not sure if this is a bug or by design, but the following code just threw a System.ArgumentNullException in our production system while processing a request where HTTP_USER_AGENT was not set:

var botParser = new BotParser();
botParser.SetUserAgent(HttpContext.Current.Request.UserAgent);
return null == botParser.Parse();

A simple workaround is to check if HttpContext.Current.Request.UserAgent is null, but I thought I'd raise this in case it actually is a bug.