The input string contains non-ASCII or null characters

时间:2016-12-23 09:32:34

标签: c# ascii nullreferenceexception kestrel-http-server kestrel

2016-12-02 02:54:39:180 [WARNING] Microsoft.AspNetCore.Server.Kestrel -    Connection processing ended abnormally
Microsoft.AspNetCore.Server.Kestrel.BadHttpRequestException: The input string contains non-ASCII or null characters.
at Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIteratorExtensions.GetAsciiString(MemoryPoolIterator start, MemoryPoolIterator end)
at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame.TakeStartLine(SocketInput input)
at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame`1.<RequestProcessingAsync>d__2.MoveNext()
2016-12-02 09:17:10:819 [ERROR] Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware - An unhandled exception has occurred: Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
at Gillie.JobCenter.Controllers.WebApi.QuestionnairesController.<SaveConsultant>d__7.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 System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.AspNetCore.Mvc.Internal.ObjectMethodExecutor.<CastToObject>d__40`1.MoveNext()

I've got this exception only once, and i can't reproduce. Maybe someone know situations when this error is appears and i will try to reproduce.

1 个答案:

答案 0 :(得分:6)

您可能应该使用HTTP日志文件来查看实际请求的样子,而不是试图猜测可能导致错误的输入。根据我的经验,在没有找到问题根源的真正线索的情况下盯着代码是徒劳的。如果你不能轻易地重现问题,那么对代码的任何猜测都不太可能有所帮助。您应该从另一端接近问题:尝试重现它。确定导致错误的输入。

编辑:您是否使用Google搜索此错误消息?由于来自客户端的一些错误的cookie,看起来其他人因为Kestrel发出此消息而遇到问题。它可能是cookie处理中的红隼错误。也许只记录有关cookie的信息就足以识别问题,您不需要记录所有POST数据。见https://github.com/aspnet/KestrelHttpServer/issues/949

您使用的是旧版本的Docker for Windows吗?