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'.”

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;
        }
    }
}
Was this page helpful?