I have this really strange error that appears when Creating / Editing users. The error looks like this:
Error getting value from 'ReadTimeout' on 'Microsoft.Owin.Host.SystemWeb.CallStreams.InputStream'.
The error in fiddler is:
{
"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)"
}
}
I have tried to figure out what is causing it, but I just can't find the issue. Here is my Create function:
/// <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>");
}
Has anyone had this error before or know what is causing it? I have googled this and all the errors seem to be tied to the UserManager which is strange, but no one has any answers.
This generally occurs when you're "double wrapping", or nesting, the result before finally returning through Web API, the exception you're seeing is JSON serialization hitting an unsupported property of the inner result.
To fix this, review all your methods that are returning IHttpActionResult. I'm confused why you included CreateUser method in your code as it doesn't appear to be used by your Save method, which is initially what I suspected to be your issue. If you had called CreateUser inside your Save method and tried to return the result of it, you'd be double wrapping.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With