LegacyCasModel =“真”;和动态数据/操作
这类似于 MVC 3 项目中的奇怪异常。
我们有一个完全信任运行的 ASP.NET 4.0 应用程序。我们需要在 web.config 中包含以下行,否则我们正在使用的库之一将无法运行。 (因为它明确使用以前版本的 .NET 中现已过时的 CAS 模型)。
<trust legacyCasModel="true" />
鉴于此设置,我们无法使用动态关键字或依赖于它的 ASP.NET MVC 的某些功能。
例如,以下代码会导致异常:
dynamic d = new object();
d.test = "jason";
异常是:
Dynamic operations can only be performed in homogenous AppDomain.
如果legacyCasModel设置为true,有什么方法可以使dynamic关键字起作用吗? (如果设置为 false,则一切正常,除了需要它的库之外。)
想法:
鉴于我在完全信任的情况下运行,我假设 AppDomain 中的一个程序集正在利用减少的权限(因此非同质的) )。有没有一种方法可以简单地告诉它以完全信任模式运行,从而使 AppDomain 同构?
我是否应该能够以某种方式重构我的代码以将有问题的程序集加载到另一个 AppDomain 中?我不熟悉执行此操作的典型方法,但它看起来很复杂。
我可以启用其他一些神奇的配置设置来使其工作吗?
This is similar to Odd Exception in MVC 3 Project.
We have an ASP.NET 4.0 application running in full trust. We need to have the following line in our web.config, otherwise one of the libraries we are using does not function. (As it explicitly uses the now obsolete CAS model from previous versions of .NET).
<trust legacyCasModel="true" />
Given this setting, we are unable to use the dynamic keyword or certain features of ASP.NET MVC which rely on it.
As an example, the following code causes an exception:
dynamic d = new object();
d.test = "jason";
The exception is:
Dynamic operations can only be performed in homogenous AppDomain.
Is there any way I can make the dynamic keyword work if legacyCasModel is set to true? (If set to false, everything works fine, except the library that requires it.)
Ideas:
Given that I am running in full trust, I assume that one assembly in the AppDomain is utilizing reduced permissions (hence the non-homogeneous). Is there a way I can simply tell it to run in full trust mode, making the AppDomain homogeneous?
Should I be able to refactor my code somehow to load the problematic assembly in another AppDomain? I'm not familiar with typical ways of doing this, but it appears complex.
Is there some other magical configuration setting I can enable to make it work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有使用太多 DLR 的东西,但我只是尝试了一个快速测试。在控制台应用程序中,相当于您的命令失败了...
但这成功了...
当使用动态对象时,您可能需要使用 ExpandoObject 而不是普通的旧对象。
如果 ExpandoObject 不能满足您的需求,请使用更强大的工具,例如 http://clay.codeplex.com/
=== 编辑 ===
如果我完全阅读问题会有帮助...
添加
到混合中会导致两者失败提供的错误。“legacyCasModel”强制使用非同质域,因为它是 .net4 之前的处理方式。这意味着动态对象和旧的 CAS 库不兼容。
我能看到的唯一有效的解决方法是将旧的 CAS 库抽象为 在单独的应用程序域中运行。
I haven't used much DLR stuff but I just tried a quick test. In a console application the equivalent of your command fails ...
But this succeeds ...
When using dynamic objects you may need to use ExpandoObject rather than plain old object.
In cases where ExpandoObject doesn't meet your needs something more powerful like http://clay.codeplex.com/
=== EDIT ===
Helps if I read the question fully ...
Adding in
<trust legacyCasModel="true" level="Full" />
to the mix causes both to fail with the error provided."legacyCasModel" forces a non-homogeneous domain as it is the pre-.net4 way of doing things. This means that dynamic objects and your older CAS library are incompatible.
The only valid workaround that I can see would be to abstract that older CAS library to run in a seperate application domain.