samples
samples copied to clipboard
Can't unload Assembly when using System.Text.Json.Jsonserializer
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
Have the same problem.