PowerShell + SharePoint 似乎无法添加程序集

发布于 2024-10-07 12:17:27 字数 452 浏览 0 评论 0原文

我在“使用”我创建的自定义字段时遇到问题。在 power shell 中,使用 LoadFrom 函数将程序集加载到脚本中,并且在加载程序集时不会引发错误,但它的行为就好像程序集未加载一样。

当尝试枚举字段时,我的自定义字段之一将收到“未正确安装”错误。当尝试通过 myListItem["myCustomField"] 访问自定义字段时,出现 CannotIndex 错误。

在使用 C# 在 Visual Studio 中编写确切的代码时,我遇到了这些相同的错误,但是,一旦我添加了对程序集的引用,它就可以正常工作。(这里的重要部分,这应该表明我不是在 power shell 中执行任何错误操作,即通过显示名称而不是内部名称访问字段等)。

如果我将程序集添加到 GAC,则在 power shell 中一切正常,但目前这不是我的选择。我需要能够从 dll 加载程序集。

有什么线索吗?

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 Studio 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白昼 2024-10-14 12:17:27

通过 LoadFrom 加载的程序集的行为方式与从 GAC 加载的程序集的行为方式不同。这不仅仅是信任问题。如果您有耐心,请从这里开始:

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

在Visual Studio中添加引用只是为了编译过程,不是运行时加载。在运行时,依赖程序集(引用)放置在与进程可执行文件相同的目录中(如果它们不是 GAC 引用)。在 powershell 情况下,依赖程序集与进程可执行文件 (powershell.h) 不在同一位置。 EXE文件)。这就是探测它们的依赖关系失败的原因。如果将它们复制到 $PSHOME 中,它可能会起作用,但这不是一个可行的解决方案,因为这是 system32 下的特权位置。

-奥辛

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

黎夕旧梦 2024-10-14 12:17:27

PowerShell 2:

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

PowerShell 1:

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

PowerShell 2:

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

PowerShell 1:

[Reflection.Assembly]::LoadFrom('C:\Path\To\Assembly.dll')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文