smsohan / MvcMailer

A Mailer for ASP.Net MVC that forms the Email Body using MVC Views (Razor etc.) following Ruby on Rails ActionMailer style
MIT License
585 stars 176 forks source link

Value does not fall within the expected range. #96

Closed zzzzzzed closed 11 years ago

zzzzzzed commented 11 years ago

I am getting a 'Value does not fall within the expected range.' error a lot.

If I send the email whilst running in Visual Studio the first time it works then it always fails unless I put a breakpoint in the razor view and step through it in which case it always works.

I have installed the program on a 'live' test server and that fails as well.

Stack trace:


"Value does not fall within the expected range."}
    [System.ArgumentException]: {"Value does not fall within the expected range."}
    Data: {System.Collections.ListDictionaryInternal}
    HelpLink: null
    HResult: -2147024809
    InnerException: null
    Message: "Value does not fall within the expected range."
    Source: "mscorlib"
    StackTrace: "   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
at System.Web.Hosting.IIS7WorkerRequest.GetServerVariableInternal(String name)
at System.Web.Hosting.IIS7WorkerRequest.GetServerVariable(String name)
at System.Web.Hosting.IIS7WorkerRequest.GetRemoteAddress()
at System.Web.HttpWorkerRequest.IsLocal()
at System.Web.HttpRequestWrapper.get_IsLocal()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
at System.Web.WebPages.StartPage.RunPage()
at System.Web.WebPages.StartPage.ExecutePageHierarchy()
at System.Web.WebPages.StartPage.RunPage()
at System.Web.WebPages.StartPage.ExecutePageHierarchy()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
at Mvc.Mailer.StringResult.ExecuteResult(ControllerContext context) in c:\Dev\GitHub\Mvc.Mailer\StringResult.cs:line 55
at Mvc.Mailer.StringResult.ExecuteResult(ControllerContext context, String mailerName) in c:\Dev\GitHub\Mvc.Mailer\StringResult.cs:line 31
at Mvc.Mailer.MailerBase.EmailBody(String viewName, String masterName) in c:\Dev\GitHub\Mvc.Mailer\MailerBase.cs:line 65
at Mvc.Mailer.MailerBase.PopulateHtmlBody(MailMessage mailMessage, String viewName, String masterName) in c:\Dev\GitHub\Mvc.Mailer\MailerBase.cs:line 147
at Mvc.Mailer.MailerBase.PopulateBody(MailMessage mailMessage, String viewName, String masterName, Dictionary`2 linkedResources) in c:\\Dev\\GitHub\\Mvc.Mailer\\MailerBase.cs:line 120
at Mvc.Mailer.MailerBase.Populate(Action`1 action) in c:\Dev\GitHub\Mvc.Mailer\MailerBase.cs:line 77
at MySite.Mailers.UserMailer.VenueListingDetails(Email email, Venue venue, Guid guid) in c:\Dev\MySite\Mailers\UserMailer.cs:line 75
at MySite.Mailers.MailSender.VenueUpdateDetails(EmailSendRequestDto requestDto) in c:\Dev\MySite\Mailers\MailSender.cs:line 104"
    TargetSite: {Void ThrowExceptionForHRInternal(Int32, IntPtr)}
zzzzzzed commented 11 years ago

I have solved the problem - I was re-using the UserMailer class. As long as I create a new UserMailer() each time I send a mail it seems to be OK.