smsohan/MvcMailer — Issue #35: Why is MvcMailer give intermittent NullReferenceException Errors?
Author: gabrielfuller
Created: 2012-01-05 21:23:45+00:00
State: open

On StackOverflow as well: http://goo.gl/sZXoS

I am using MvcMailer via Nuget to try and send Emails using the MVC Views and Models system. I am also using Sharp Architecture so I have my Domain Objects, Infrustructure, Presentation, Tests and Tasks in different projects within the solution.

I created my IClientMailer interface and ClientMailer class in the Presentation project and am able to create the mail message and call EmailBody(ViewName, EmailBoilerplate) method on the MvcMailer's MailerBase class, but the odd thing is that sometime it works and sometimes it gives me the below error. I do not understand why I am only getting this error some of the time and I cannot seem to find how to debug the project more to find out more information.

Anyone have any thoughts on how to get it to work correctly 100% of the time.

[NullReferenceException: Object reference not set to an instance of an object.]
Mvc.Mailer.StringResult.ExecuteResult(ControllerContext context, String mailerName) +142
Mvc.Mailer.MailerBase.EmailBody(String viewName, String masterName) +181
EasyOptions.Web.Mvc.Code.ClientMailer.FirstPaymentCoupon(String[] emailAddresses, FirstPaymentCouponEmailViewModel model) in C:\Users\Gabriel\Documents\Repositories\EasyOptions\Solutions\EasyOptions.Web.Mvc\Code\ClientMailer.cs:53
EasyOptions.Web.Mvc.Controllers.FirstPaymentCouponController.SendEmail(Int64 loanId, FirstPaymentCouponViewModel model) in C:\Users\Gabriel\Documents\Repositories\EasyOptions\Solutions\EasyOptions.Web.Mvc\Controllers\FirstPaymentCouponController.cs:64
lambda_method(Closure , ControllerBase , Object[] ) +166
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +208
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
System.Web.Mvc.<>c__DisplayClass15.b__12() +55
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +263
System.Web.Mvc.<>c__DisplayClass17.b__14() +19
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +263
System.Web.Mvc.<>c__DisplayClass17.b__14() +19
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +191
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343
System.Web.Mvc.Controller.ExecuteCore() +116
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
System.Web.Mvc.<>c__DisplayClassb.b__5() +37
System.Web.Mvc.Async.<>c__DisplayClass1.b__0() +21
System.Web.Mvc.Async.<>c__DisplayClass8`1.b__7(IAsyncResult _) +12
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.<>c__DisplayClasse.b__d() +50
System.Web.Mvc.SecurityUtil.b__0(Action f) +7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8963149
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184