In a .net 6.0 web api application I use smss. When I attempt to run the code I get this Im getting this error when I run the web application:
NotSupportedException: Serialization and deserialization of 'System.Type' instances are not supported. System.Text.Json.Serialization.Converters.UnsupportedTypeConverter.Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options) System.Text.Json.Serialization.JsonConverter.TryWrite(Utf8JsonWriter writer, ref T value, JsonSerializerOptions options, ref WriteStack state) System.Text.Json.Serialization.Metadata.JsonPropertyInfo.GetMemberAndWriteJson(object obj, ref WriteStack state, Utf8JsonWriter writer) System.Text.Json.Serialization.Converters.ObjectDefaultConverter.OnTryWrite(Utf8JsonWriter writer, T value, JsonSerializerOptions options, ref WriteStack state) System.Text.Json.Serialization.JsonConverter.TryWrite(Utf8JsonWriter writer, ref T value, JsonSerializerOptions options, ref WriteStack state) System.Text.Json.Serialization.JsonConverter.TryWriteAsObject(Utf8JsonWriter writer, object value, JsonSerializerOptions options, ref WriteStack state) System.Text.Json.Serialization.JsonConverter.TryWrite(Utf8JsonWriter writer, ref T value, JsonSerializerOptions options, ref WriteStack state) System.Text.Json.Serialization.Converters.IEnumerableConverter.OnWriteResume(Utf8JsonWriter writer, TCollection value, JsonSerializerOptions options, ref WriteStack state) System.Text.Json.Serialization.JsonCollectionConverter<TCollection, TElement>.OnTryWrite(Utf8JsonWriter writer, TCollection value, JsonSerializerOptions options, ref WriteStack state) System.Text.Json.Serialization.JsonConverter.TryWrite(Utf8JsonWriter writer, ref T value, JsonSerializerOptions options, ref WriteStack state) System.Text.Json.Serialization.Metadata.JsonPropertyInfo.GetMemberAndWriteJson(object obj, ref WriteStack state, Utf8JsonWriter writer) System.Text.Json.Serialization.Converters.ObjectDefaultConverter.OnTryWrite(Utf8JsonWriter writer, T value, JsonSerializerOptions options, ref WriteStack state) System.Text.Json.Serialization.JsonConverter.TryWrite(Utf8JsonWriter writer, ref T value, JsonSerializerOptions options, ref WriteStack state) System.Text.Json.Serialization.JsonConverter.WriteCore(Utf8JsonWriter writer, ref T value, JsonSerializerOptions options, ref WriteStack state)
What should I do to fix this?
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Extensions.Configuration;
using WebApplication1.Models;
namespace WebApplication1.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class DepartmentController : ControllerBase
{
private readonly IConfiguration _configuration;
public DepartmentController(IConfiguration configuration)
{
_configuration = configuration;
}
[HttpGet]
public JsonResult Get()
{
string query = @"
select DepartmentId, DepartmentName from
dbo.Department";
DataTable table = new DataTable();
string sqlDataSource = _configuration.GetConnectionString("EmployeeAppCon");
SqlDataReader myReader;
using(SqlConnection myCon = new SqlConnection(sqlDataSource))
{
myCon.Open();
using(SqlCommand myCommand = new SqlCommand(query, myCon))
{
myReader = myCommand.ExecuteReader();
table.Load(myReader);
myReader.Close();
myCon.Close();
}
}
return new JsonResult(table);
}
}
}