简体   繁体   English

为什么我收到“价值未在预期范围内”?

[英]Why I receive “Value does not fall within the expected range”?

I have an asp.net mvc web application and some external cron job is calling a specific url from my CronJobController and execute a specific method like: 我有一个asp.net mvc Web应用程序,一些外部cron作业正在从我的CronJobController调用特定的url并执行一个特定的方法,例如:

/// <summary>
    /// Will be called externally by www.setcronjob.com.
    /// </summary>
    /// <returns></returns>
    public async Task<ActionResult> Index()
    {
        RunTwitterSearchQuery();
        RunFacebookSearchQuery();
        return new ContentResult { Content = "Ok" };
    }

in RunTwitterSearchQuery, I want to send some emails and I tried with both MvcMailer and ActionMailer , for instance (with ActionMailer): 在RunTwitterSearchQuery中,我想发送一些电子邮件,例如,我尝试同时使用MvcMailerActionMailer (使用ActionMailer):

var mailController = new MailController();
mailController.HttpContextBase = this.HttpContext;
mailController.MoreThanXFollowersEmail(alertEmailModel).Deliver();

Because the http context is null I have to set it in this way to avoid NPE but after that I receive a very strange exception (in both MvcMailer and ActionMailer): 因为http上下文为null,所以我必须以这种方式设置它以避免NPE,但是此后,我收到一个非常奇怪的异常(在MvcMailer和ActionMailer中):

    System.ArgumentException: Value does not fall within the expected range.
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
       at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
       at System.Web.Hosting.IIS7WorkerRequest.GetUserAgentInternal()
       at System.Web.Hosting.IIS7WorkerRequest.GetKnownRequestHeader(Int32 index)
       at System.Web.HttpRequest.get_UserAgent()
       at System.Web.HttpRequestWrapper.get_UserAgent()
       at System.Web.WebPages.BrowserHelpers.GetOverriddenUserAgent(HttpContextBase httpContext)
       at System.Web.WebPages.BrowserHelpers.GetOverriddenBrowser(HttpContextBase httpContext, Func`2 createBrowser)
       at System.Web.WebPages.BrowserHelpers.GetOverriddenBrowser(HttpContextBase httpContext)
       at System.Web.WebPages.DisplayModeProvider.<.ctor>b__2(HttpContextBase context)
       at System.Web.WebPages.DefaultDisplayMode.CanHandleContext(HttpContextBase httpContext)
       at System.Web.WebPages.DisplayModeProvider.<>c__DisplayClass6.<GetAvailableDisplayModesForContext>b__5(IDisplayMode mode)
       at System.Linq.Enumerable.WhereListIterator`1.MoveNext()
       at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
       at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
       at System.Web.Mvc.VirtualPathProviderViewEngine.GetPath(ControllerContext controllerContext, String[] locations, String[] areaLocations, String locationsPropertyName, String name, String controllerName, String cacheKeyPrefix, Boolean useCache, String[]& searchedLocations)
       at System.Web.Mvc.VirtualPathProviderViewEngine.FindView(ControllerContext controllerContext, String viewName, String masterName, Boolean useCache)
       at System.Web.Mvc.ViewEngineCollection.<>c__DisplayClassc.<FindView>b__a(IViewEngine e)
       at System.Web.Mvc.ViewEngineCollection.Find(Func`2 lookup, Boolean trackSearchedPaths)
       at System.Web.Mvc.ViewEngineCollection.FindView(ControllerContext controllerContext, String viewName, String masterName)
       at ActionMailer.Net.Mvc.EmailResult.LocateViews(ControllerContext context) in c:\Dev\actionmailer\src\ActionMailer.Net.Mvc\EmailResult.cs:line 127
       at ActionMailer.Net.Mvc.EmailResult.AddMessageViews(ControllerContext context) in c:\Dev\actionmailer\src\ActionMailer.Net.Mvc\EmailResult.cs:line 155
       at ActionMailer.Net.Mvc.EmailResult.ExecuteResult(ControllerContext context) in c:\Dev\actionmailer\src\ActionMailer.Net.Mvc\EmailResult.cs:line 98
       at ActionMailer.Net.Mvc.MailerBase.Email(String viewName, Object model, String masterName, Boolean trimBody) in c:\Dev\actionmailer\src\ActionMailer.Net.Mvc\MailerBase.cs:line 166
       at SocialCrm.Controllers.MailController.MoreThanXFollowersEmail(AlertEmailModel model) in c:\dev\palminfo\SocialCrm\SocialCrm\Controllers\MailController.cs:line 18
       at SocialCrm.Controllers.CronJobController.SendAlertEmail(SearchResultModel searchResultModel, Int32 searchQueryId, List`1 alerts, String emailTo, String streamName) in c:\dev\palminfo\SocialCrm\SocialCrm\Controllers\Batch\CronJobController.cs:line 146
       at SocialCrm.Controllers.CronJobController.<RunTwitterSearchQuery>b__3() in c:\dev\palminfo\SocialCrm\SocialCrm\Controllers\Batch\CronJobController.cs:line 83

This is very ugly and I would really appreciate any help on this issue. 这是非常丑陋的,我非常感谢您在此问题上的任何帮助。

Update : when using MvcMailer this is the error I receive. 更新 :使用MvcMailer时, 是我收到的错误。

Try the solution posted on github for a very similar looking issue if you are using MvcMailer. 如果您使用的是MvcMailer,请尝试在github上发布的解决方案,以解决非常相似的问题。 The solution was to create a new UserMailer every time an email is sent: Github Answer 解决方案是每次发送电子邮件时都创建一个新的UserMailer: Github Answer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM