I'm trying to combine the new NET6 JSON source generation with minimal APIs to try and maximize performance. I have a Model I'm trying to use with Source Generation that must include a referenced property from this library: Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite
I'm getting this error from the Library:
Error CS0122 'Geometry.SortIndexValue' is inaccessible due to its protection level
I'd like to just ignore the entire property and not have it be included in the source generation. Is that possible?
My Minimal API code looks like the following: https://github.com/aherrick/Net6JsonSourceGenerator
using Microsoft.AspNetCore.Mvc;
using NetTopologySuite.Geometries;
using System.Text.Json.Serialization;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
var app = builder.Build();
builder.Services.Configure<JsonOptions>(options =>
{
options.JsonSerializerOptions.AddContext<VenueJsonContext>();
});
app.MapGet("GetVenues", () =>
{
var venues = new List<Venue>();
return venues;
});
app.Run();
public class Venue
{
public string Name { get; set; }
[JsonIgnore] // don't even include this property in source generation ideally.
public Geometry Location { get; set; }
}
[JsonSerializable(typeof(Venue[]))]
public partial class VenueJsonContext : JsonSerializerContext
{
}