dotnet / dotnet/samples

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

Open
#5,016 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
C#
Stars
3.7k
Forks
5.1k
Avg merge
9h 11m
Merged PRs (30d)
1

Description

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.