Add-Type : Unable to load one or more of the requested types

I have a .NET assembly (a dll) to load Sharepoint Online information. I am trying load this assembly in powershell using Add-Type command.

Add-Type -Path "C:\SharepointCSMOMicrosoft.SharePoint.Client.dll"

But, I am receiving the error ‘Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information‘.

Add-Type : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
At line:1 char:9
+ Add-Type <<<<  -Path "C:\SharepointCSMOMicrosoft.SharePoint.Client.dll"
+ CategoryInfo          : NotSpecified: (:) [Add-Type], ReflectionTypeLoadException
+ FullyQualifiedErrorId : System.Reflection.ReflectionTypeLoadException,Microsoft.PowerShell.Commands.AddTypeCommand
Add-Type : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

Solution

For me, I can able to load the same assembly using reflection:

[System.Reflection.Assembly]::LoadFrom("C:\SharepointCSMOMicrosoft.SharePoint.Client.dll")

If your assembly placed in Global Assembly Cache (GAC). You can use the method .LoadWithPartialName(), which allows you to use just that part of the “full name” that most of us would consider the name.

[System.Reflection.Assembly]::LoadWithPartialName("Windows.Forms")

For more details, you can also refer following articles:

http://www.madwithpowershell.com/2013/10/add-type-vs-reflectionassembly-in.html
http://serverfault.com/questions/455163/how-to-properly-add-net-assemblies-to-powershell-session 

http://stackoverflow.com/questions/24906392/issue-loading-in-different-assemblies-to-powershell

Advertisement

Leave a Comment