程序集不允许部分信任的调用者

发布于 2024-09-15 02:28:55 字数 418 浏览 4 评论 0原文

如何更改我的库以允许部分信任的调用者?

我收到以下错误:

“/”应用程序中的服务器错误。

安全异常

描述:已尝试应用程序 执行不允许的操作 安全政策。为了授予此 申请所需的权限 请联系您的系统 管理员或更改 应用程序的信任级别 配置文件。

异常详细信息: 系统.安全.安全异常: 该大会不允许部分 值得信赖的来电者。

来源错误:[无相关来源 行]

源文件:App_Web_kzj7vfkn.2.cs
行:0

编辑

经过更多查看问题后,似乎是 System.Web.UI.ClientScriptManager 导致了问题

How do I change my library to allow partially trusted callers?

I get the following error:

Server Error in '/' Application.

Security Exception

Description: The application attempted
to perform an operation not allowed by
the security policy. To grant this
application the required permission
please contact your system
administrator or change the
application's trust level in the
configuration file.

Exception Details:
System.Security.SecurityException:
That assembly does not allow partially
trusted callers.

Source Error: [No relevant source
lines]

Source File: App_Web_kzj7vfkn.2.cs
Line: 0

Edit

After some more looking at the problem it seems like it's System.Web.UI.ClientScriptManager that causes the problem

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

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

发布评论

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

评论(6

幻梦 2024-09-22 02:28:55

假设您可以访问图书馆的资源。

此处给出了非常好的详细解释 另请阅读底部的链接以获得更好的理解。

有可能不是您的程序集有问题,而是您正在调用另一个不允许部分受信任的调用者的程序集。在运行时,您可以使用 fuslogvw 来查找装配给你带来了问题。如果这是问题所在,并且您拥有此程序集的源代码,则还需要应用 [程序集:AllowPartiallyTrustedCallers] 属性到该程序集,如果您没有源,我知道的唯一选择是替换麻烦的库。

Assuming you have access to the sources of your library.

A pretty good and detailed explanation is given here Also read the links at the bottom to get a better understanding.

There is a possibility that not your assembly is the problem but you are calling another assembly that does not allow partially trusted callers. At runtime you can use fuslogvw to find which assembly is giving you the problems. If this is the problem and you have the sources of this assembly you need to also apply the [assembly:AllowPartiallyTrustedCallers] attribute to that assembly, if you don't have the sources the only option I know of is to replace the troublesome library.

☆獨立☆ 2024-09-22 02:28:55

就我而言 -

这解决了类似的问题:

我必须转到我的 dll 属性,
然后按取消阻止按钮:
输入图像描述这里

In my case -

This solved a similar problem:

I had to go to my dll properties,
And press the Unblock button:
enter image description here

单身狗的梦 2024-09-22 02:28:55

我知道回答已经很晚了,但我想再添加一个答案,以帮助未来的访客。

我的场景

当我遇到此问题时,我正在我的 asp.net 应用程序中实现 CCavenue 支付网关,因为 CCavenue 加密 MCPG.CCA。 Util

请在web.config中添加以下行

<system.web>

  <trust level="Full" />

</system.web>

I know its quite late to answer, but I would like to add one more answer just to help future visitors.

My Scenario

I was implementing CCavenue Payment gateway in my asp.net application when I had this issue becuase CCavenue encryption MCPG.CCA.Util

Please add the following lines in web.config

<system.web>

  <trust level="Full" />

</system.web>
泡沫很甜 2024-09-22 02:28:55

我知道这是一个非常老的问题,但我刚刚遇到了这个问题,并且能够使用与接受的答案不同的方法来修复它,因为这是搜索错误消息时谷歌上的第一个结果,我认为这会很有用如果我分享我的解决方案给其他人。

当我尝试与硬件集成时,出现了我遇到的问题。硬件有自己的安装程序,可以将 DLL 注册到 GAC 中。它安装的 DLL 有 2 个依赖项 DLL,但由于某种原因,当安装程序运行时,它没有注册依赖项 DLL。

基本上情况是,Entry DLL 已在 GAC 中注册,而其两个依赖项 DLL 未在 GAC 中注册,但确实存在于可执行文件旁边。

当我运行我的程序并尝试使用该硬件时,程序正在寻找可执行文件旁边的入口 DLL,但它找不到。然后程序将进入 GAC,在那里找到入口 DLL。一旦进入硬件的 DLL,它最终会尝试使用不在 GAC 中但位于可执行文件旁边的依赖项 DLL。从 GAC 调用可执行文件旁边的 DLL 会引发部分受信任的调用者错误。

我通过将入口 DLL 的副本放在可执行文件旁边解决了这个问题。

我很好奇什么情况会起作用以及什么会导致安全错误,我发现这些情况按预期工作:

  1. 可执行文件旁边的所有三个 DLL。
  2. GAC 中的所有三个 DLL。

唯一始终失败的情况是任何层位于 GAC 内部且任何依赖项 DLL 位于 GAC 外部时。

失败场景 #1:

  1. GAC 中的入口 DLL
  2. Exe 旁边的 DLL #2 和 DLL #3

    • 无法将 DLL #2 定位为错误 DLL。

失败场景 #2:

  1. 在 GAC
  2. Exe 旁边的 DLL #3 中输入 DLL 和 DLL #2

    • 无法将 DLL #3 定位为错误 DLL。

失败场景 #3:

  1. 在 GAC
  2. exe 旁边的 DLL #2 中输入 DLL 和 DLL #3

    • (不出所料)无法将 DLL #2 定位为错误 DLL。

我没有测试它,但我认为这是一个安全的假设,如果条目 DLL 和 DLL #3 位于可执行文件旁边,并且 DLL #2 位于 GAC 中,那么它会因为 DLL #3 被定位为而出错问题。

I know this is a very old question but I just ran into this issue and was able to fix it using a different method than the accepted answer and since this is the first result on google when searching for the error message I think it will be useful to others if I share my solution.

The issue I was running into came about when I attempted to integrate with a piece of hardware. The hardware had its own installer which would register a DLL into the GAC. The DLL it installed had 2 dependency DLLs but for some reason when the installer was run it was not registering the dependency DLLs.

Basically the scenario was that the Entry DLL was registered in the GAC and its two dependency DLLs were not registered in the GAC but did exist next to the executable.

When I ran my program and attempted to use the piece of hardware, the program was looking for the entry DLL next to the executable, which it could not find. The program would then go to the GAC, where it would find the entry DLL. Once inside the DLL for the hardware it would eventually try to use the dependency DLLs which were not in the GAC but were next to the executable. Calling out of the GAC to the DLL that was next to the executable was throwing the partially trusted caller error.

I resolved this by placing a copy of the entry DLL next to the executable.

I was curious as to what scenarios would work and what would cause the security error and I've found these are the scenarios that worked as expected:

  1. All three of the DLLs next to the executable.
  2. All three DLLs in the GAC.

The only scenario that consistently failed was when any layer was inside the GAC and any of the dependency DLLs were outside the GAC.

Failed Scenario #1:

  1. Entry DLL in the GAC
  2. DLL #2 and DLL #3 next to the Exe

    • Fails siting DLL #2 as the faulting DLL.

Failed Scenario #2:

  1. Entry DLL and DLL #2 in the GAC
  2. DLL #3 next to the Exe

    • Fails siting DLL #3 as the faulting DLL.

Failed Scenario #3:

  1. Entry DLL and DLL #3 in the GAC
  2. DLL #2 next to the exe

    • (Predictably) Fails siting DLL #2 as the faulting DLL.

I did not test it but I think its a safe assumption to say that if the entry DLL and DLL #3 had been next to the executable and DLL #2 had been in the GAC then it would have faulted with DLL #3 being sited as the problem.

骑趴 2024-09-22 02:28:55

我也遇到了类似的问题,我尝试了上述所有答案,但没有一个对我有用。显然我的情况有所不同,在我的情况下,框架是 3.5。我将其更改为 4 或以上,它对我有用。

I also got the similar problem, I tried all the above answers but none worked for me. Apparently my case was different, In my case the framework was 3.5. I changed it to 4 or above and it worked for me.

漆黑的白昼 2024-09-22 02:28:55

这是另一个可能的解决方案,具体取决于您正在使用的库和您的设置: 确保您从“本地”驱动器运行程序。

当我在主机和来宾操作系统之间共享的文件夹中的虚拟机中运行程序时,我遇到了此错误消息,并且库 dll 位于 exe 旁边。将文件夹复制到来宾操作系统本地驱动器修复了该问题。

这会导致信任问题,这是有道理的,但如果能提供更有用的错误消息就更好了。

Here's yet another possible solution, depending on the library you're using and your setup: Make sure you're running your program from a "local" drive.

I ran into this error message when running my program in a VM in a folder shared between host and guest OS, with the library dll present beside the exe. Copying the folder to a drive local to the guest OS fixed the issue.

It makes sense that this would cause a trust issue, but a more helpful error message would be nice.

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