samples icon indicating copy to clipboard operation
samples copied to clipboard

Can't unload Assembly when using System.Text.Json.Jsonserializer

Open thanhnntq opened this issue 3 years ago • 1 comments

Following tutorial in "https://github.com/dotnet/samples/tree/main/core/tutorials/Unloading" The sample code will make .Unload can't work!

using System;
using System.IO;
using System.Text;
namespace Test {
public class TestClass{
    public string Run(string name, int iter){
var obj = new X{ Name= name, Age= iter }; 
    return obj.ToString();
}
}
public class X { 
public string Name{get;set;}
public int Age{get;set;}
public override string ToString(){
	        var p = Newtonsoft.Json.JsonSerializer.Create();
        string s;
        using (var mem = new MemoryStream())
        {
            using (var txt = new StreamWriter(mem))
            {
                p.Serialize(txt, this);
                txt.Close();
            }
            s = System.Text.Encoding.UTF8.GetString(mem.ToArray());
        }
return s;
}
 }
}

Tested with System.Text.Json.JsonSerializer and Newtonsoft.Json.JsonSerializer

thanhnntq avatar Feb 17 '22 09:02 thanhnntq

Have the same problem.

renping106 avatar Feb 27 '24 14:02 renping106