You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
Not sure off the cuff, but a few ideas off the top of my head:
check to see if the .net versions match
check to see if there are any constraints on reflection on the Azure service
check to see if there is a tweaked version of NewtonSoft for Azure (on the one hand I'd be surprised, but this is true for Unity)
I also popped your Q into an LLM to see what it would suggest and it came back with these two ideas...
To resolve this issue, you can try the following steps:
Use the [JsonProperty] attribute from Newtonsoft.Json:
Replace the Postgrest-specific attributes with [JsonProperty] attributes from the Newtonsoft.Json library. This will ensure that the JSON serialization process is consistent across different environments.
Here's an example of how you can modify your Recipe class:
using Newtonsoft.Json;publicclassRecipe{[JsonProperty("id")]publicintId{get;set;}[JsonProperty("Name")]publicstringName{get;set;}publicList<Ingredient> Ingredients {get;set;}}
Check JSON Serialization Settings:
Make sure that your JSON serialization settings are consistent between your local environment and Azure App Service. You can configure JSON serialization settings in your Startup.cs or wherever you configure your JSON serialization. Ensure that you are using Newtonsoft.Json as the JSON serializer and that the settings are the same in both places.
// In Startup.cs or your configuration file
services.AddControllers().AddNewtonsoftJson(options =>{ options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;// This may be needed for your relationships.});
I didn't try using the [JsonProperty] attribute as I first tried adding the Newtonsoft options to Program.cs and that did the trick (also adding the Microsoft.AspNetCore.Mvc.NewtonsoftJson) as required in order to have the AddNewtonsoftJson method).
Would you be able to explain why that fixed it though? I'd be curious to understand.
Bug report
Describe the bug
In supabase have a
Recipes
table with 2 columns:id
(int8 and primary key) andName
(text)So in my C# code I have a
Recipe
class: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:
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
atSystem.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.SmallObjectWithParameterizedConstructorConverter
5[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.SmallObjectWithParameterizedConstructorConverter
5[Postgrest.Attributes.PrimaryKeyAttribute,System.String,System.Boolean,System.Object,System.Object]'. "I have upgraded all packages including
supabase-csharp
,postgrest-csharp
andNewtonsoft.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.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
The text was updated successfully, but these errors were encountered: