.NET 4.0的AppDomain:废弃证据 [英] .NET 4.0 AppDomain: obsoleted Evidence

查看:331
本文介绍了.NET 4.0的AppDomain:废弃证据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个.NET的学生,目前我们正在学习有关应用程序域。 我们得到了下面的例子code(对于.NET 3.5)。正如预期的那样,它抛出一个SecurityException。 注:TestApp.exe添加为项目的参考

I am a .NET student and currently we are learning about Application Domains. We were given the following example code (for .NET 3.5). As expected, it throws a SecurityException. Note: TestApp.exe is added as a reference in the project.

Dim file As String = "TestApp.exe"
Dim hostEvidence As Object() = {New Zone(SecurityZone.Internet)}
Dim appDomainEvidence As Evidence = New Evidence(hostEvidence, Nothing)
Dim d As AppDomain = AppDomain.CreateDomain("MyDomain", appDomainEvidence)
d.ExecuteAssembly(file)

当试图在VS2010 .NET 4.0我遇到一个问题下运行这一点。 首先,它显示一个警告

When trying to run this in VS2010 under .NET 4.0 I run into a problem. First it shows a warning

的Public Sub New(hostEvidence()为对象,assemblyEvidence()作为对象)已过时:这种构造是过时的。请使用这需要EvidenceBase的阵列,而不是构造函数。

'Public Sub New(hostEvidence() As Object, assemblyEvidence() As Object)' is obsolete: 'This constructor is obsolete. Please use the constructor which takes arrays of EvidenceBase instead.'.

我改变hostEvidence到EvidenceBase类型(),并警告消失了。 但是,试图运行应用程序时,它给出了一个错误。

I change the type of hostEvidence to EvidenceBase() and the warning is gone. However, when trying to run the application it gives an error.

此方法隐式使用CAS策略,其已被废弃,.NET框架。为了使CAS策略兼容性的原因,请使用NetFx40_LegacySecurityPolicy配置开关。请参阅 http://go.microsoft.com/fwlink/?LinkID=155570 了解更多信息。

This method implicitly uses CAS policy, which has been obsoleted by the .NET Framework. In order to enable CAS policy for compatibility reasons, please use the NetFx40_LegacySecurityPolicy configuration switch. Please see http://go.microsoft.com/fwlink/?LinkID=155570 for more information.

我已经浏览的网页,然后链接到的如何:运行部分受信任的code在沙盒的和读<一href="http://blogs.msdn.com/shawnfa/archive/2009/05/27/coding-with-security-policy-in-net-4-0-implicit-uses-of-cas-policy.aspx" rel="nofollow">http://blogs.msdn.com/shawnfa/archive/2009/05/27/coding-with-security-policy-in-net-4-0-implicit-uses-of-cas-policy.aspx但我无法理解这一切。

I have viewed the page, followed the link to How to: Run Partially Trusted Code in a Sandbox and read http://blogs.msdn.com/shawnfa/archive/2009/05/27/coding-with-security-policy-in-net-4-0-implicit-uses-of-cas-policy.aspx but I'm having trouble understanding all of this.

相比,我现在有,所以任何帮助,改变了我的code所以它的工作原理无需添加其他的东西,会很美联社preciated MSDN上的code的例子是相当大的。

The code example on MSDN is quite big compared to what I currently have, so any help with changing my code so it works without adding other stuff, will be very appreciated.

推荐答案

因为它说,在你所提供的链接,.NET不再支持code接入安全框架的政策部分,为4.0版本。

As it says in the link you provided, .NET is no longer supporting the policy portion of the code access security framework, as of version 4.0.

换句话说,你的教训是有关.NET 3.5,并且不涉及到4.0框架。解决的办法是恢复到原来的code和 配置工程目标3.5框架 (你仍然可以使用Visual Studio 2010)。

In other words, your lesson is about .NET 3.5 and does not pertain to the 4.0 framework. The solution is to revert to your original code and configure your project to target the 3.5 framework (you can still use Visual Studio 2010).

这篇关于.NET 4.0的AppDomain:废弃证据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆