How do I using Roslyn with correct version of .net

How do I using Roslyn with correct version of .net Hello I'm new to C# and roslyn usage, I'm trying to use roslyn's code analysis functionality to open a .sln file, I'm using code like below, however when I run it to open this .sln, it pop up a strange error like this:
System.TypeLoadException:“Could not load type 'System.Runtime.Remoting.RemotingServices' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.”
System.TypeLoadException:“Could not load type 'System.Runtime.Remoting.RemotingServices' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.”
However, if I use my code to open itself's .sln file everything seems to be fine, so I suspect it's a .Net Version problem, but with my limited experience, I have no idea how to get it right, is there some version number I need to set right in .sln? I attach my .sln and .csproj files in attach zip file, where "Migration" is my own project's sln file and "Wpf" is the project I try to open with my code below
C#
using Migration.CodeExtraction;
using Microsoft.Build.Locator;
using Microsoft.CodeAnalysis.MSBuild;

namespace Migration{
static class Program {
public static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
String p = "D:\\repos\\wpf\\lepoco-wpfui\\Wpf.Ui.sln";

MSBuildLocator.RegisterMSBuildPath("C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Msbuild\\Current\\Bin");
var msWorkspace = MSBuildWorkspace.Create();

var solution = msWorkspace.OpenSolutionAsync(p).Result;
return;
}
}
}
C#
using Migration.CodeExtraction;
using Microsoft.Build.Locator;
using Microsoft.CodeAnalysis.MSBuild;

namespace Migration{
static class Program {
public static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
String p = "D:\\repos\\wpf\\lepoco-wpfui\\Wpf.Ui.sln";

MSBuildLocator.RegisterMSBuildPath("C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Msbuild\\Current\\Bin");
var msWorkspace = MSBuildWorkspace.Create();

var solution = msWorkspace.OpenSolutionAsync(p).Result;
return;
}
}
}
2 Replies
Thinker
Thinker12mo ago
Ask in #roslyn
9drocsid_emoJ1
9drocsid_emoJ1OP12mo ago
Thank you, didn't realize there is one before
Want results from more Discord servers?
Add your server