The problem is not related to the code provided. Other code calls System.Security.Permissions.dll. Make sure that System.Security.Permissions has been installed in NuGet. Before running the program, please check whether System.Security.Permissions.dll has been copied to the build directory of the project.
Also Check if Newtonsoft library is used in the project.
https://github.com/JamesNK/Newtonsoft.Json/issues/2621
Failed loading dump: System.IO.FileNotFoundException: Could not load
file or assembly ‘System.Security.Permissions, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51’. The system cannot
find the file specified.
The Newtonsoft.Json library comes in variants for .NET Standard 2.0,
the older .NET Famework 2, .NET Famework 3.5, .NET Famework 4, .NET
Famework 4.5, and for some other framework targets.The library trying to use System.Security.Permissions is an indication
that you use the Newtonsoft.Json library variant for .NET Framework
4.5 or older. Which is not the correct variant if your project targets .NET Core or .NET 5.To fix your problem, make sure your project is using the
Newtonsoft.Json library variant for .NET Standard 2.0.