Loading assembly via reflection succeeds, Add-Type does not

4

I'm using a .net assembly in Powershell. This code works successfully:

[Reflection.Assembly]::LoadFile("E:\Workspaces\RTE\dh.PSP.Common\Mainline\Source\dh.Common.MetaData\bin\dh.Common.Metadata.dll")
$marketMetadataRepository = New-Object dh.Common.Metadata.MarketMetadataRepository

Result:

GAC Version Location

--- ------- -------- False v4.0.30319
E:\Workspaces\RTE\dh.PSP.Common\Mainline\Source\dh.Common.MetaData\bin\dh.Common.Metadata.dll

So one would think this would work successfully also:

Add-Type -AssemblyName
"E:\Workspaces\RTE\dh.PSP.Common\Mainline\Source\dh.Common.MetaData\bin\dh.Common.Metadata.dll"

but no:

Add-Type : Could not load file or assembly 'E:\Workspaces\RTE\dh.PSP.Common\Mainline\Source\dh.Common.MetaData\bin\dh.Common.Metadata.dll' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)

I'm confused as to why one method would work and another does not. Any ideas?

.net
powershell
asked on Stack Overflow Dec 10, 2014 by jamiet

1 Answer

4

The -assemblyname parameter of Add-Type expects an full or partial assembly name. Try using -path instead.

answered on Stack Overflow Dec 10, 2014 by Martin

User contributions licensed under CC BY-SA 3.0