我正在开发 SSRS(SQL Server Reporting Services)交付扩展。其中一部分需要我对库文件进行强命名,以便在 rssrvpolicy.conf 中使用 FullTrust 权限加载它。
在部分代码中,我需要将一小部分 JSON 序列化为一个对象。所以我为此使用了 Newtonsoft Json.NET (13.0.1),效果很好。
为了将所有这些都放在一个易于交付的单个文件中(大多数情况下[配置文件也是]),我使用 Costura.Fody 将所有引用的库嵌入到单个 DLL 中。效果很好。
该库从各种 SSRS 进程中调用(我在日志中将 RSPortal 和 ReportingServicesService 视为父进程)。 这就是事情变得奇怪的地方。 当被 RSPortal 调用时,一切正常。但是,当由 ReportingServicesService 运行时,如果它尝试调用利用 Json.NET 的方法之一,我会收到如下错误:
System.MethodAccessException: Attempt by security transparent method 'Newtonsoft.Json.Utilities.LateBoundReflectionDelegateFactory+<>c__DisplayClass5_0`1<System.__Canon>.<CreateDefaultConstructor>b__1()' to access security critical method 'DeliveryExtension.Config..ctor()' failed.
Assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' 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.
问题是,我使用的是 Json.NET 13,而不是 12。SSRS bin 文件夹中包含一个 Newtonsoft.Json.dll (版本 12.0),该文件夹包含在默认 SSRS 安装中供他们自己使用,所以看起来这就是我在 ReportingServicesService 下执行时使用 Json.NET 时使用的内容。有什么办法可以“强制”我的代码使用嵌入式 Json.NET 13 库?
编辑 - 经过一些修补后,我确认它是正在使用的库文件......
目前,我可以通过在我的 AssemblyInfo.cs 中包含以下内容来抑制错误,并让它在某些情况下使用他们的 Json.NET 库,因为它工作正常。
[assembly: SecurityRules(SecurityRuleSet.Level1)]
[assembly: AllowPartiallyTrustedCallers]
我不确定这样做的安全隐患,我也想知道如何让它使用我的嵌入式库版本。
我试过包括这是我的 DeliveryExtension.dll.config 文件,但它似乎没有任何区别。
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
有人有任何想法/建议吗?