I'm using powershell core 7.4.2 to run an own .Net module
[Reflection.Assembly]::LoadFile("C:\test\test.dll")
[Some.NameSpace.ClassName]::DoSth('...')
If test.dll is compiled for .Net Framework 4.8 this works as expected.
If test.dll is compiled for .Net 8.0 this fails. Fiddling around with Add-Type reveals a ReflectionTypeLoadException. Some parts of the assembly are missing
try
{
Add-Type -Path "C:\test\test.dll"
}
catch [System.Reflection.ReflectionTypeLoadException]
{
$e = $PSItem.Exception
$e.LoaderExceptions
}
None of the listed assemblies in LoaderExceptions are used in my code (e.g. System.Text.RegularExpressions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a) but more of interest is "System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which indicates to me that basically .Net 8 is not loaded at all.
I did some more tests by adding the assemblies in question System.Runtime.dll, System.Private.CoreLib.dll, System.Text.RegularExpressions.dll but gave up after the error that "System.Object" of the assembly "System.Private.CoreLib" can not be found.
test.dll does not include fancy usings:
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Xml.XPath;
using Microsoft.Win32;
namespace Some.NameSpace
{
public static class ClassName
{
public static void DoSth(string fileName)
{
}
}
}
What am I doing wrong?
[System.IntPtr].Assembly.Location |Get-ItemPropertyValue -Name VersionInfo?powershell.exe(Windows PowerShell 5.1) instead ofpwsh.exe(PowerShell 7)?