Related to this question: How to properly add .NET assemblies to Powershell session?
I used this code to likewise try to load a .NET Core 3.1 assembly into a PowerShell session.
I used this code:
# Load Assembly
Add-Type -Path "I:\DW\tools\bin\Release\netcoreapp3.1\win-x64\publish\DataTools.dll" -PassThru
if ($Error.Count -gt 0) {
Write-Host $Error[0].Exception.LoaderExceptions
}
and I got this error:
System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Vers ion=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependenc ies. The system cannot find the file specified.
Then I built my assembly with this command to make it "self-contained":
dotnet publish -r win-x64 -c Release --self-contained
However, now I am getting these LoaderExceptions
:
System.TypeLoadException: Could not load type 'System.Object' from assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' because the parent does not exist.
Am I missing something in my dotnet build
statement? or do I need to include an additional assembly?
NOTE: I also have dotnet 5 preview installed.