开发者

PowerShell + SharePoint cannot seem to add an assembly

开发者 https://www.devze.com 2023-01-30 07:53 出处:网络
I am having an issue \'using\' a custom field I have created.In power shell, the assembly is being loaded into the script using the LoadFrom function, and it throws no errors in loading the assembly,

I am having an issue 'using' a custom field I have created. In power shell, the assembly is being loaded into the script using the LoadFrom function, and it throws no errors in loading the assembly, yet it acts as if the assembly wasn't loaded.

When trying to enumerate fields, I will get a 'not installed properly' error on one of my custom fields. When trying to access a custom field via myListItem["myCustomField"] I get a CannotIndex error.

I get these same errors when writing the exact code in Visual Studi开发者_Go百科o with C#, however, once I add the reference to my assembly it works fine there. (Important part here, this should indicate that I am not doing anything incorrectly in power shell, i.e. accessing the field by its display name rather than internal name etc).

If I add my assembly to the GAC, everything works fine in power shell, but this is not an option for me at the moment. I need to be able to load the assembly from the dll.

Any clues?


An assembly loaded via LoadFrom does not behave the same way as one loaded from the GAC. It's more than just trust issues. If you have the patience, start here:

http://blogs.msdn.com/b/suzcook/archive/2003/05/29/choosing-a-binding-context.aspx

Adding a reference in visual studio is just for the compilation process, not the runtime loading. At runtime, the the dependent assemblies (references) are placed in the same directory as the process executable (if they were not GAC references.) In the powershell case, your dependent assemblies are not in the same location as the process executable (powershell.exe). This is why probing for their dependencies fails. If you copied them into $PSHOME it would probably work, but this is not a workable solution as this is a privileged location under system32.

-Oisin


PowerShell 2:

Add-Type -Path C:\Path\To\Assembly.dll

PowerShell 1:

[Reflection.Assembly]::LoadFrom('C:\Path\To\Assembly.dll')
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号