Debug Error in ".NET 6.0"

上仲 紳介(Shinsuke KAMINAKA) 21 Reputation points

I have 1 issue.

I want to use ".NET 6.0" dll file correctly.
To speaking exactly, this following problem.
I use Visual Studio 2022, and created project. I configed followings.
(1) Project.Property."Target Framework" = .NET 6.0
(2) Project.Property."Platform Target" = x64
(3) Solution.Build."Configuration Manager".Configuration = Debug
(4) Solution.Build."Configuration Manager".Platform = Any CPU
(5) Solution.Test."Processor Architecture for AnyCPU projects" = x64
Then, I used System.Reflection.Assembly. Result, it caused error "System.Reflection.TargetInvocationException (Exception has been thrown by the target of an invocation)" and "System.TypeLoadException (Could not load type 'System.Reflection.Assembly' from assembly 'System.Runtime, Version=, Culture=neutral, PublicKyToken=b03f5f7f11d50a3a')".

Dll file directory.
(a) .NET 6.0 : C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\6.0.7\ref\net6.0\System.Runtime.dll
(b) .NET Framework 4.8 : C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.8\mscorlib.dll
Because of the fact error dll version is, I except Visual Studio 2022 read the modules of ".NET Framework 4.8".

I don't know what's wrong.

.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,101 questions
0 comments No comments
{count} votes

1 additional answer

Sort by: Most helpful
  1. 上仲 紳介(Shinsuke KAMINAKA) 21 Reputation points

    Thank you for answering this issue!
    This is solved.

    This cause is the fact that I selected project type "WPF User Control Library" incorrectly(, because I couldn't select ".NET Framework 4.8" as Target Framework). Therefore, I reselected project type "WPF User Control Library (.NET Framework)".
    Originally, I shouldn't select .NET 6.0(, because Target Framework of my created API is .NET Framework 4.x).

    0 comments No comments