Pickup assembly through reflection succeeds, Add-Type fails
I am using .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 \ Trunk \ Source \ dh.Common.MetaData \ Bin \ dh.Common .Metadata.dll
So one would think that this would work successfully too:
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 \ Trunk \ Source \ dh.Common.MetaData \ Bin \ dh.Common.Metadata.dll' or one of its dependencies. The given assembly name or codebase is invalid. (Exception from HRESULT: 0x80131047)
I'm confused as to why one method works and the other doesn't. Any ideas?
+3
source to share