jamiet
jamiet

Reputation: 12254

Loading assembly via reflection succeeds, Add-Type does not

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?

Upvotes: 5

Views: 2035

Answers (1)

Martin
Martin

Reputation: 951

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

Upvotes: 7

Related Questions