值不在预期的范围误差范围内

时间:2013-10-15 19:36:36

标签: asp.net-mvc-4 ef-code-first entity-framework-5 mvcmailer

我正在开发一个ASP.Net MVC 4应用程序。我有一个模块,可以通过电子邮件发送发票(使用MVCMailer

出于某种原因,我收到错误:Value does not fall within the expected range

如果我单步执行代码它没有任何错误,但只要我运行它就会给我错误。产生错误的部分是:

        return Populate(x =>
                {
                    x.From = new System.Net.Mail.MailAddress("Sales@Scheduler.com", "Scheduler");
                    x.Subject = System.Configuration.ConfigurationManager.AppSettings["SiteName"].ToString() + " Inovice #" + (invoice.invoiceID + 1000).ToString() + " (" + (invoice.invoiceStatus == InvoiceStatus.paid ? "Paid" : "Pending") + ")";
                    x.ViewName = "Invoice";
                    x.To.Add(new System.Net.Mail.MailAddress(ToEmailAddress, ToName));
                });

我还应该提一下,我已经检查了所有传入的值,它们似乎都是正确的。我个人在堆栈跟踪中找不到任何有用的东西,但这里是:


值不在预期范围内。

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Value does not fall within the expected range.

Source Error:

Line 136:                var ToName = (defaultUser != null && !string.IsNullOrEmpty(defaultUser.EmailAddress)) ? invoice.company.contactFirstName + " " + invoice.company.contactLastName : "Cant Reach";
Line 137:
Line 138:                return Populate(x =>
Line 139:                    {
Line 140:                        x.From = new     System.Net.Mail.MailAddress("Sales@Scheduler.com", "Scheduler");


Source File: e:\Website Projects\Scheduler\Solution\Scheduler\Mailers\UserMailer.cs        Line: 138

Stack Trace:

[ArgumentException: Value does not fall within the expected range.]
   System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) +0
   System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode) +10759150
   System.Web.Hosting.IIS7WorkerRequest.GetServerVariableInternal(String name) +40
   System.Web.Hosting.IIS7WorkerRequest.GetServerVariable(String name) +36
   System.Web.Hosting.IIS7WorkerRequest.GetRemoteAddress() +18
   System.Web.HttpWorkerRequest.IsLocal() +16
   System.Web.HttpRequestWrapper.get_IsLocal() +19
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +54
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +97
   System.Web.WebPages.StartPage.RunPage() +17
   System.Web.WebPages.StartPage.ExecutePageHierarchy() +62
   System.Web.WebPages.StartPage.RunPage() +17
   System.Web.WebPages.StartPage.ExecutePageHierarchy() +62
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +76
   System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +260
   System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +115
   Mvc.Mailer.StringResult.ExecuteResult(ControllerContext context) +538
   Mvc.Mailer.StringResult.ExecuteResult(ControllerContext context, String mailerName) +164
   Mvc.Mailer.MailerBase.EmailBody(String viewName, String masterName) +345
   Mvc.Mailer.MailerBase.PopulateHtmlBody(MailMessage mailMessage, String viewName, String masterName) +73
   Mvc.Mailer.MailerBase.PopulateBody(MailMessage mailMessage, String viewName, String masterName, Dictionary`2 linkedResources) +439
   Mvc.Mailer.MailerBase.Populate(Action`1 action) +171
   Scheduler.Mailers.UserMailer.EmailInvoice(Invoice invoice) in e:\Website Projects\Scheduler\Solution\Scheduler\Mailers\UserMailer.cs:138
   Scheduler.Helpers.EmailHelper.SendInvoice(Invoice invoice) in e:\Website Projects\Scheduler\Solution\Scheduler\Helpers\EmailHelper.cs:105
   Scheduler.Helpers.CreditCardHelper.ChargeCreditCardToUpgradeSubscription(CreditCardTransact    ionViewModel transaction, Invoice invoice, Boolean isScheduler, Boolean emailInvoice) in e:\Website Projects\Scheduler\Solution\Scheduler\Helpers\CreditCardHelper.cs:460
   Scheduler.Controllers.ManagerController.SubscriptionPlan(SubscriptionPlanViewModel model) in e:\Website Projects\Scheduler\Solution\Scheduler\Controllers\ManagerController.cs:2370
   lambda_method(Closure , ControllerBase , Object[] ) +180
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +211
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
   System.Web.Mvc.Async.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41() +28
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +48
   System.Web.Mvc.Async.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33() +57
   System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +223
   System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +48
   System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +24
   System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +102
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +43
   System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +14
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +57
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +47
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
   System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +25
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +47
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9628972
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

1 个答案:

答案 0 :(得分:2)

为每封电子邮件使用新的邮件程序实例。 https://github.com/smsohan/MvcMailer/issues/96