2

Is it possible to load an dlls in "Powershell" with out the use of reflection.

I have loaded a .Net dll using

Add-Type -AssemblyName System.Web | Out-Null

I have my "Powershell" script in the same folder as the dlls. So I presumed the following would work .

Add-Type -AssemblyName Common.dll | Out-Null
Add-Type -AssemblyName 'Common.dll' | Out-Null

But I get the error "Cannot add type. The assembly 'Common.dll' could not be found."

or

Add-Type -AssemblyName .\Common.dll | Out-Null

Could not load file or assembly '.\Common.dll' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)

Can anyone please help?

Alan Mulligan
  • 1,107
  • 2
  • 16
  • 35
  • Add-Type : Unable to load one or more of the requested types – Alan Mulligan Nov 12 '15 at 13:58
  • Please provide full error message. Try to specify full path to assembly. Does you have all dependencies in place? What happens, when you load assembly thru reflection? – user4003407 Nov 12 '15 at 14:07
  • 1
    When you used Path, did you put fullname? There is a nice article on http://www.madwithpowershell.com/2013/10/add-type-vs-reflectionassembly-in.html – demokritos Nov 12 '15 at 14:14
  • 1
    Did you download the dll from the internet, or unpack it from a .zip file downloaded from the internet? If so, you might have to run `Unblock-File C:\path\to\Common.dll`, close and restart powershell.exe and then run `Add-Type -Path C:\path\to\Common.dll` – Mathias R. Jessen Nov 12 '15 at 15:31
  • Don't overlook the "restart powershell" part of @MathiasR.Jessen 's comment. .Net caches unsuccessful attempts at loading assemblies in much the same way that DNS caches NXDOMAIN replies. Restart powershell and start from a clean process before every attempt. – briantist Nov 12 '15 at 23:39
  • The 0x80131047 seems to be related to invalid characters in an assembly name. I can't find (with a couple of minutes of googling) a definitive definition of the error. But see [this](http://stackoverflow.com/questions/12520212/exception-from-hresult-0x80131047) on SO. Besides the accepted answer, also note the second reply with a pointer to a blog by Aaron Stebner. – Χpẘ Nov 17 '15 at 21:50
  • I found the error definition: `FUSION_E_INVALID_NAME 0x80131047 -2146234297` [here](http://blogs.msdn.com/b/eldar/archive/2007/04/03/a-lot-of-hresult-codes.aspx) – Χpẘ Nov 17 '15 at 21:57

0 Answers0