【问题标题】:"Dynamic operations can only be performed in homogenous AppDomain" error“动态操作只能在同构 AppDomain 中执行”错误
【发布时间】:2012-01-06 16:33:18
【问题描述】:

在我的本地主机上运行 MVC3 站点时出现此错误。这是一个刚刚创建的全新 MVC3 站点,HomeController Index 方法是从 ViewBag.Message 分配中抛出的。

public ActionResult Index()
{
    ViewBag.Message = "Welcome to ASP.NET MVC!";
    return View();
}

堆栈跟踪:

at System.Runtime.CompilerServices.CallSiteBinder.BindCore[T](CallSite`1 site, Object[] args)
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
at MVC3.Web.UI.Controllers.HomeController.Index() in C:\Users\mccarthy\Documents\Visual Studio 2010\Projects\MVC3\MVC3.Web.UI\Controllers\HomeController.cs:line 13
at lambda_method(Closure , ControllerBase , Object[] )
at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)

我不知道这个错误是什么,以前也没有见过。当我启动一个新的 MVC2 项目(到目前为止我一直在使用的项目)时,该站点运行良好。

Microsoft 在处理 MVC3 和 MVC2 框架之间的安全性方面是否存在一些差异?

【问题讨论】:

  • 这个related question 可能会有所启发
  • PHeiberg。感谢您将我指向该链接。我的修复有点不同。在我的 web.config 中没有明确设置&lt;trust legacyCasModel="true" level="Full" /&gt;。所以我查看了我的 machine.config 文件,你瞧,它就在那里!我将其注释掉,MVC3 应用程序现在运行。谢谢!

标签: asp.net asp.net-mvc-3 asp.net-mvc-2


【解决方案1】:

好的,看来如果您的 web.config 中有以下行:

&lt;trust legacyCasModel="true" level="Full" /&gt;

可能会发生这种类型的错误。然而,在 PHeiberg 提供给我的链接中,它说该行可能在 web.config 中。我的 web.config 没有。

于是我查看了 machine.config,发现了代码行!我将其注释掉了,现在我可以运行我的 MVC3 应用了。

我不太确定它是如何在 machine.config 中结束的,或者由于我将其注释掉而可能导致的其他问题,但这个直接的问题已得到解决。

【讨论】:

  • 如果您在基于 Windows 窗体的项目中遇到类似问题,请在 app.config 文件中注释此行:
猜你喜欢
  • 1970-01-01
  • 2013-04-15
  • 1970-01-01
  • 1970-01-01
  • 2014-07-25
  • 1970-01-01
  • 2017-06-15
  • 2015-07-10
  • 2017-12-21
相关资源
最近更新 更多