我創建/編輯用戶時出現了這個非常奇怪的錯誤。 錯誤是這樣的:從 'Microsoft.Owin.Host.SystemWeb.CallStreams.InputStream' ReadTimeout「創建用戶時讀取超時錯誤c#
錯誤獲取價值。
錯誤的提琴手是:
{
"message": "An error has occurred.",
"exceptionMessage": "Error getting value from 'ReadTimeout' on 'Microsoft.Owin.Host.SystemWeb.CallStreams.InputStream'.",
"exceptionType": "Newtonsoft.Json.JsonSerializationException",
"stackTrace": " at Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue(Object target)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues(JsonWriter writer, Object value, JsonContainerContract contract, JsonProperty member, JsonProperty property, JsonContract& memberContract, Object& memberValue)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeDictionary(JsonWriter writer, IDictionary values, JsonDictionaryContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeDictionary(JsonWriter writer, IDictionary values, JsonDictionaryContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)\r\n at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)\r\n at Newtonsoft.Json.JsonSerializer.Serialize(JsonWriter jsonWriter, Object value)\r\n at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding)\r\n at System.Net.Http.Formatting.JsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding)\r\n at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, HttpContent content)\r\n at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.GetResult()\r\n at System.Web.Http.Owin.HttpMessageHandlerAdapter.<BufferResponseContentAsync>d__13.MoveNext()",
"innerException": {
"message": "An error has occurred.",
"exceptionMessage": "Timeouts are not supported on this stream.",
"exceptionType": "System.InvalidOperationException",
"stackTrace": " at System.IO.Stream.get_ReadTimeout()\r\n at Microsoft.Owin.Host.SystemWeb.CallStreams.DelegatingStream.get_ReadTimeout()\r\n at GetReadTimeout(Object)\r\n at Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue(Object target)"
}
}
我試圖找出是什麼原因造成的,但我就是無法找到問題。 這裏是我的創建功能:
/// <summary>
/// Creates a user
/// </summary>
/// <param name="model">The bound user model</param>
/// <returns></returns>
[HttpPost]
[Route("")]
public async Task<IHttpActionResult> CreateUser(UserBindingModel model)
{
// Save our user to the database
return Ok(await Save(model));
}
/// <summary>
/// Used to save a user
/// </summary>
/// <param name="model">The model representing the user</param>
/// <returns></returns>
private async Task<IHttpActionResult> Save(UserBindingModel model)
{
// If our ModelState is invalid, return a bad request
if (!ModelState.IsValid)
return BadRequest(ModelState);
// Get the current userId and date
var userId = User.Identity.GetUserId();
var date = DateTime.UtcNow;
// Assign our binding model to a new model
var user = new User()
{
CompanyId = model.CompanyId,
UserName = model.Email,
Email = model.Email,
FirstName = model.FirstName,
LastName = model.LastName,
LastLoginDate = date,
Telephone = model.Telephone,
CreatedById = string.IsNullOrEmpty(model.CreatedById) ? userId : model.CreatedById,
DateCreated = string.IsNullOrEmpty(model.CreatedById) ? date : model.DateCreated,
ModifiedById = userId,
DateModified = date
};
// Create our result
var result = new IdentityResult();
// If we don't have a created by id
if (string.IsNullOrEmpty(model.CreatedById))
{
// Try to create the user
result = await this.UserService.CreateAsync(user);
// Send our the confirmation email
await SendConfirmationEmail(user.Id);
}
else // Else
{
// Try to update the user
result = await this.UserService.UpdateAsync(user);
}
// If the creation fails, return the error
if (!result.Succeeded)
return GetErrorResult(result);
// Return the result
return Ok(this.ModelFactory.Create(user));
}
/// <summary>
/// Used to send a confirmation email to the user specified
/// </summary>
/// <param name="userId">The id of the user we wish to send an email to</param>
/// <returns></returns>
private async Task SendConfirmationEmail(string userId)
{
// Generate our unique code
var code = await this.UserService.GenerateEmailConfirmationTokenAsync(userId);
// Create the callback url
var callbackUrl = new Uri(Url.Link("ConfirmEmailRoute", new { userId = userId, code = code }).Replace("api/users", "#/account"));
// Send the email
await this.UserService.SendEmailAsync(userId, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
}
有沒有人有在此之前的錯誤或不知道是什麼原因造成的呢? 我google了這個和所有的錯誤似乎綁在UserManager這是奇怪的,但沒有人有任何答案。
我們剛剛經歷了這個錯誤。它發生在我們試圖序列化一個異步任務時。這在我們的記錄機制中發生,記錄所有進出參數。 – sfs
嘗試序列化包含流的對象時發現了類似的錯誤。它看起來像是在內部序列化對象的方式。對不起,我不能提供更多的幫助,但我的錯誤是在一個非常不同的領域! –