.net6 ,How to use JsonSerializerContext in VB.net Project

Copper Contributor

In the C# project(.net6), I can run the following code and successfully output the serialized content.

 

 

 

    public class Test {
        public string AA { get; set; } = "A";
        public string BB { get; set; } = "B";
    }        

    [JsonSerializable(typeof(Test))]    
    public partial class TestContext : JsonSerializerContext
    {     
    }

var T = new Test();
var utf8Json = JsonSerializer.SerializeToUtf8Bytes(T, TestContext.Default.Test);
var s = Encoding.UTF8.GetString(utf8Json);
Console.WriteLine(s);
//{"AA":"A","BB":"B"}

 

 

 

But how can I achieve this in vb.net project(.net6/7)?

Please help me, please post the vb sample code. thanks!

1 Reply

Hi @Happymade,

Thanks for posting your issue here.

However this platform is used for how-to discussions and sharing best practices for building any app with .NET.Since your issue is a technical question, welcome to post it in Microsoft Q&A forum, the support team and communities on Microsoft Q&A will help you for any technical questions.
Besides, it will be appreciated if you can share it here once you post this technical question Microsoft Q&A.
Best Regards,
Lan Huang