首页 > 解决方案 > 打开 URL 抛出 String 未被识别为有效的 DateTime

问题描述

使用 AngleSharp v 0.9.9.0 这个:

var siteUrl = "https://richmond.csod.com/ats/careersite/search.aspx?site=1&c=richmond";

var configuration = Configuration.Default.WithDefaultLoader().WithCookies();
var currentContext = BrowsingContext.New(configuration);
var originalDoc = currentContext.OpenAsync(siteUrl).Result;

Console.WriteLine(originalDoc.DocumentElement.OuterHtml);

工作正常。但是如果我升级到 v 0.9.9.2,它会抛出这个:

Unhandled Exception: System.AggregateException: One or more errors occurred. ---> System.FormatException: String was not recognized as a valid DateTime.
   at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
   at AngleSharp.Services.Default.MemoryCookieProvider.Sanatize(String cookie)
   at AngleSharp.Services.Default.MemoryCookieProvider.SetCookie(String origin, String value)
   at AngleSharp.Dom.Document.set_Cookie(String value)
   at AngleSharp.Dom.Document.Setup(CreateDocumentOptions options)
   at AngleSharp.Dom.Html.HtmlDocument.<LoadAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at AngleSharp.BrowsingContextExtensions.<OpenAsync>d__2.MoveNext()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at System.Threading.Tasks.Task`1.get_Result()
   at AngleSharpTest.Program.Main(String[] args) in C:\Users\matt.burland\source\repos\AngleSharpTest\AngleSharpTest\Program.cs:line 21

它似乎来自 AngleSharp 内部,并且发生在几个不同的、完全不相关的 url 上。FWIW,我的文化设置是en-US,并且我尝试设置为不变的文化,但这似乎也无济于事。

有没有其他人看到这个问题?有解决办法吗?

标签: c#anglesharp

解决方案


推荐阅读