I am making a call to an API I am developing and I get an error: JsonTypeInfo metadata for type ‘BFNG_Library.Models.App_admin’ was not provided by TypeInfoResolver of type ‘[]’.
This is the class. And I added the JsonSerializable attribute:
public record App_admin
{
public string? Role { get; set; }
public string? Name { get; set; }
public string? Email { get; set; }
public int? ID { get; set; }
public bool? Active { get; set; }
}
[JsonSerializable(typeof(App_admin))]
[JsonSerializable(typeof(List<App_admin>))]
internal partial class AppJsonSerializerContext2 : JsonSerializerContext
{
}
and this is the API endpoint in my controller:
public class AdminController : Controller
{
[Route("api/admin/create")]
public string PostCreate([FromBody] App_admin Admin)
{
//Implementation Removed
}
}
Not sure if it makes a difference, but the class (App_admin) is in a different project (BFNG_Library) which I have added as a project dependency on the actual project (BFNG_Program).
I even changed the API signature to require a string instead of App_admin viz:
public string PostCreate([FromBody] string Admin)
When I do this, the error changes to JsonTypeInfo metadata for type ‘System.String’ was not provided by TypeInfoResolver of type ‘[]’.
I find it quite confusing as String is a base type. Is there some missing config I have not included?
Environment:
Windows, .Net 8
Any help will be appreciated
Custodly Innovations is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.