-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why is MvcMailer give intermittent NullReferenceException Errors? #35
Comments
Just from this description, it will be very hard for me to realize why github and try debugging it to catch the problem.Sohan On Thu, Jan 5, 2012 at 2:23 PM, Gabriel Fuller
|
I got the exact same stack trace. Having got the source code, and stepped through, it turned out it was a nullreferenceexception in my view, but the stack trace had been replaced at some point during the exception making its way to the browser screen. (possibly due to the try..finally block in ExecuteResult(ControllerContext context, String mailerName) ). I think the real problem here is that the stack traces are getting mucked up. |
I seem to have the same problem. I also added the source to my solution to debug and I end up at the same spot in ExecuteResult(ControllerContext context). It appears to be incapable to render the view after the first request on a fresh build. For instance, if I stop the virtual servers, rebuild and debug it will work the first time around. Yet all the successive attempts fail. |
Actually, never mind. I got the problem fixed. I turns out the MvcMailer isn't compatible with the Castle Windsor project. I tried to get the MvcMailer controller to get instantiated automatically in my controller and it wasn't doing something right apparently. |
@abrahamD I see you came to the conclusion that MvcMailer isn't compatible with Castle Windsor. Can I ask you how you got around this issue? Thanks in advance. |
@walkindude It's fairly simple. All you have to do is instantiate your MailService (class that extends MailerBase) manually in your controller's constructor. |
@abrahamD thank you very much for the quick reply. That's an approach I considered, but won't that make the controller hard to test? If I instantiate the mailer directly inside the constructor, I'm not going to be able to mock it in my unit tests. Or maybe I'm missing something? |
@walkindude Well, what I do to get around that is reassign my controller's Mailer manually in my test's setup as such: Target = new Controller(...) |
I managed to get mvcmailer working together with castle windsor. Install component like this: mvcmailer uses an mvc controller under the covers so the transient lifestyle is important as it keeps the http context avaliable |
I still randomly get this issue. I can send the same message over and over and sometimes it works and other times it doesn't |
Is it going to spam? Sometimes the email servers will block repeated mails Sent from my iPhone On 2013-01-09, at 7:46 AM, Eonasdan notifications@github.com wrote: I still randomly get this issue. I can send the same message over and over and sometimes it works and other — |
spam? No, I'm getting
I'm testing this on a local dev machine currently and I'm using an local basic smtp server |
You'd need to find out what object/method it's invoking when this error Sohan On Wed, Jan 9, 2013 at 9:37 AM, Eonasdan notifications@github.com wrote:
|
when trying to step through this
it works, but if just let it run I get the nullref |
@Eonasdan are you getting the exact same stacktrace as the one posted at the beginning? Have you tried debugging? As @kobeyu pointed out, the stacktrace gets munged, so your best bet is adding MvcMailer's source to your solution and stepping through. Also, if you do it, please try commenting out lines 30, 32 and 35 of This is a weird one, though. The fact that it works every time you step through the code you posted would lead one to believe it's a timing issue, but I don't think it's the case here. |
I now get
|
shameless bump. any idea's @walkindude or @smsohan? |
@Eonasdan I don't have a clue, sorry. The problem is somewhere else than It's hard to be much more specific. I've been able to drill down to That—I think—is the call that fails. This is the method's declaration
and since an Figuring out who, how and why is left as an excercise for the reader ;) I'm sorry I can't be more helpful. But hey, I think it has to do with some setting in your project. |
I've no clue about it. It would help if you could share a project where I Sohan On Mon, Jan 14, 2013 at 4:11 PM, Stefano Mioli notifications@github.comwrote:
|
changing the
|
for kicks I put the I setup each mailer to bcc another address to make sure it is at least going out and I get mixed results. Sometimes the email is at the bcc and sometimes it's at the intended email |
It's really hard for me to get a clear picture of this without having a Sohan On Wed, Jan 16, 2013 at 9:05 AM, Eonasdan notifications@github.com wrote:
|
I'd need a way to reproduce it. Sohan On Wed, Jan 16, 2013 at 9:55 AM, Eonasdan notifications@github.com wrote:
|
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) +27System.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.<InvokeActionMethodWithFilters>b__14() +19 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func
1 continuation) +263System.Web.Mvc.<>c__DisplayClass17.b__14() +19
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList
1 filters, ActionDescriptor actionDescriptor, IDictionary
2 parameters) +191System.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.<BeginSynchronous>b__7(IAsyncResult _) +12 System.Web.Mvc.Async.WrappedAsyncResult
1.End() +62System.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
The text was updated successfully, but these errors were encountered: