Skip to content

Getting System.NotSupportedException on Azure App Service #80

Open
@Dre-Tas

Description

@Dre-Tas

Bug report

Describe the bug

In supabase have a Recipes table with 2 columns: id (int8 and primary key) and Name (text)

So in my C# code I have a Recipe class:

using Postgrest.Attributes;
using Postgrest.Models;

namespace Planner.Classes
{
    [Table("Recipes")]
    public class Recipe : BaseModel
    {
        [PrimaryKey("id")]
        public int Id { get; set; }
        [Column("Name")]
        public string Name { get; set; }
        [Reference(typeof(Ingredient))]
        public List<Ingredient> Ingredients { get; set; }
    }
}

where Ingredients is coming from a many-to-many join table (which I believe shouldn't be important now...I think)

In a separate project in the same solution I have created a .NET Core 6.0 API with a controller.
To make it extremely simple right now for reporting, the controller is this:

using Microsoft.AspNetCore.Mvc;
using WeeklyMealPlanner.Classes;

namespace PlannerApi.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class RecipesController : ControllerBase
    {
        [HttpGet(Name = "GetRecipes")]
        public List<Recipe> GetRecipes()
        {
            return new List<Recipe> { new Recipe { Name = "A" } };
        }
    }
}

When I test this locally with a console app, everything works normally and I get a list of all my recipes stored in supabase, their ingredients, etc.
But when I publish this to Azure App Service then I get a 500 error in the browser and if I check Application Insights I see that it's reporting a System.NotSupportedException at System.Text.Json.ThrowHelper.ThrowNotSupportedException_DictionaryKeyTypeNotSupported with this message:
"The type 'Postgrest.Attributes.PrimaryKeyAttribute' is not a supported dictionary key using converter of type 'System.Text.Json.Serialization.Converters.SmallObjectWithParameterizedConstructorConverter5[Postgrest.Attributes.PrimaryKeyAttribute,System.String,System.Boolean,System.Object,System.Object]'. Path: $.PrimaryKey. The type 'Postgrest.Attributes.PrimaryKeyAttribute' is not a supported dictionary key using converter of type 'System.Text.Json.Serialization.Converters.SmallObjectWithParameterizedConstructorConverter5[Postgrest.Attributes.PrimaryKeyAttribute,System.String,System.Boolean,System.Object,System.Object]'. "

I have upgraded all packages including supabase-csharp, postgrest-csharp and Newtonsoft.Json

I also tried to modify the Recipe class so that it doesn't use any postgrest or supabase library and my controller returns correctly a recipe of name "A" in Chrome.

namespace WeeklyMealPlanner.Classes
{
    public class Recipe
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public List<Ingredient> Ingredients { get; set; }
    }
}

I'm really out of ideas right now.

Am I doing something wrong??

PS. Thanks for supabase!!. I just recently discovered it and it awesome!! Keep up the good work!

System information

  • OS: Windows
  • Browser: chrome

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions