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?
The -assemblyname
parameter of Add-Type expects an full or partial assembly name. Try using -path
instead.
User contributions licensed under CC BY-SA 3.0