I'm trying to compile an application made in .NET Core 2.0 but every time I try to login the post method throws the following error:
System.PlatformNotSupportedException: Operation is not supported on this platform.
at System.Threading.ExecutionContext.GetObjectData(SerializationInfo info, StreamingContext context)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeISerializable(JsonWriter writer, ISerializable value, JsonISerializableContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
at Microsoft.AspNetCore.Mvc.Formatters.JsonOutputFormatter.WriteObject(TextWriter writer, Object value)
at Microsoft.AspNetCore.Mvc.Formatters.JsonOutputFormatter.WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultAsync(IActionResult result)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResultFilterAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResultExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.SpaServices.Webpack.ConditionalProxyMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.SpaServices.Webpack.ConditionalProxyMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
Could you guys help me to fix this error? I found out that multiple modifications were made in .NET Core 2.0 and maybe it doesn't support this method anymore, but it worked before. Is there anything that can be done to get it working again?
UPDATE
I added the code where the error is thrown, it happens when the Ok object is returned.
public async Task<IActionResult> Login([FromBody]AuthRequest itemRequest)
{
try
{
var result = await _manager.ValidateUserAsync(itemRequest.Email, itemRequest.Password);
if (result.Succeeded)
{
var user = await _manager.GetUserAsync(itemRequest.Email);
return Ok(new
{
name = user.name,
administrator = user.administrator,
permissions = _manager.GetUserPermissions(user.Email)
});
}
return Unauthorized();
}
catch (Exception e)
{
return StatusCode(500);
}
}
public async Task<IEnumerable<Permission>> GetUserPermissions(string value)
{
IEnumerable<Permission> permissions;
using (var connection = GetConnection())
{
var parameters = new DynamicParameters();
parameters.Add("@email", value);
permissions = await connection.QueryAsync<Permission>("[dbo].[GetUserPermissions]", parameters, null, null, CommandType.StoredProcedure);
}
return permissions;
}
public class Permission
{
public int module { get; set; }
public bool permission { get; set; }
}
CodePudding user response:
I managed to make the application work again by installing .Net Core 2.0.9!