ASP.NET MVC NullReferenceException when inheriting from a Base Controller
- by rockinthesixstring
I've got a base controller that I inherit all of my Controllers from. It's job is to basically set caching and error handling as well as check for mobile browsers.
My UI works fine, but my Unit Tests are failing.
Imports System.Web.Mvc
<HandleError()> _
<CompressFilter()> _
<OutputCache(Duration:=30, VaryByParam:="id")> _
Public Class BaseController : Inherits System.Web.Mvc.Controller
Protected Overrides Function View(ByVal viewName As String, ByVal masterName As String, ByVal model As Object) As System.Web.Mvc.ViewResult
Dim ismobile As Nullable(Of Boolean) = Request.Browser.IsMobileDevice
If ismobile Then
Return MyBase.View(viewName, "Mobile", model)
Else
Return MyBase.View(viewName, "Site", model)
End If
End Function
End Class
The error I'm getting in my Unit test is on Dim ismobile As Nullable(Of Boolean) = Request.Browser.IsMobileDevice saying
Object Reference Not Set To An Instance Of An Object.