我正在尝试从我的代码('IntPub')中调用 Apache ActiveMQ NMS 版本 1.6.0,出于安全原因,该代码必须在 .NET 4.0 环境的沙箱中运行。创建沙箱的程序使我的代码“部分受信任”,因此“安全透明”,这似乎意味着它无法创建 ConnectionFactory(请参阅下面的错误日志),因为 NMS 似乎是“安全关键的”。这是导致此错误的代码:
connecturi = new Uri("tcp://my.server.com:61616");
var connectionFactory = new ConnectionFactory(connecturi);
我也尝试了这个,结果相似:
connecturi = new Uri("activemq:tcp://my.server.com:61616");
var connectionFactory = NMSConnectionFactory.CreateConnectionFactory(connecturi);
由于我无法更改程序集的安全级别(沙箱阻止它),有没有办法让 NMS 作为“安全关键”运行,以便可以通过“安全透明”代码调用?我是否必须重新编译它才能这样做,或者 NMS 是否会执行一些永远不会被视为“安全关键”的操作?
我感谢任何帮助或建议...
Assembly 'IntPub, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6fa620743b8dc60a' is partially trusted, which causes the CLR to make it entirely security transparent regardless of any transparency annotations in the assembly itself. In order to access security critical code, this assembly must be fully trusted.Detail:
<OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">
<ErrorCode>-2147220956</ErrorCode>
<ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
<Message>Unexpected exception from plug-in (Execute): Test.Client: System.MethodAccessException: Attempt by security transparent method 'Test.Client.Execute(System.IServiceProvider)' to access security critical method 'Apache.NMS.ActiveMQ.ConnectionFactory..ctor(System.Uri)' failed.