Add-Type -Assembly -PassThru is expected to list all types loaded from the assembly (even if the assembly has already been loaded).
Currently, this fails quietly with some assemblies.
This is a regression from Windows PowerShell.
On macOS or Windows (haven't tried on Linux):
Add-Type -AssemblyName System.Numerics -PassThru | Should -Not -BeNullOrEmpty
Note that when you inspect one of the types supposedly from this assembly with .AssemblyName - e.g., [bigint].AssemblyName - it points to a _different_ assembly, System.Runtime.Numerics.dll, and using the above command with _that_ works, so the problem perhaps relates to "stub"(?) assemblies such as System.Numerics.dll?
_Update_: See @0xd4d's comment below
The test should succeed.
The test fails, because the command produces no output
PowerShell Core 7.0.0-preview.4 on macOS 10.15
PowerShell Core 7.0.0-preview.4 on Microsoft Windows 10.0.17763
c#
private void WriteTypes(Assembly assembly)
{
WriteObject(assembly.GetTypes(), true);
}
In the code we have the assembly and assembly.GetTypes() returns {System.RuntimeType[0]} (debugger view) that is empty.
I think it is the same as our Microsoft.PowerShell.SDK.dll #3401
System.Numerics (on .NET Core at least) is an assembly that only has types forwarded to other assemblies.
The types are forwarded to System.Numerics.Vectors and System.Runtime.Numerics, although that is most likely an implementation detail you shouldn't depend on.
You can get the forwarded types by calling GetForwardedTypes() instead of GetTypes().
$asm = [reflection.assembly]::Load('System.Numerics')
# empty
$asm.GetTypes()
# returns all types
$asm.GetForwardedTypes()
# Show assemblies
$asm.GetForwardedTypes() | ForEach-Object { $_.Assembly.Location }
/cc @SteveL-MSFT @daxian-dbw Should we passthru forwarded types too?
Most helpful comment
System.Numerics (on .NET Core at least) is an assembly that only has types forwarded to other assemblies.
The types are forwarded to System.Numerics.Vectors and System.Runtime.Numerics, although that is most likely an implementation detail you shouldn't depend on.
You can get the forwarded types by calling
GetForwardedTypes()instead ofGetTypes().