我一直致力于将一个MVC4项目转换为MVC5。第一天,我遇到了'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException‘,但通过重新开始转换可以解决它。我不确定修复是什么,这是一个令人沮丧的问题,因为它又发生了。
当我加载Login.cshtml页面时,_ExternalLoginsListPartial.cshtml中出现错误。错误在第15行抛出。(string action = Model.Action;)
@using Microsoft.Owin.Security
@{
var loginProviders = Context.GetOwinContext().Authentication.GetExternalAuthenticationTypes();
var authenticationDescriptions = loginProviders as AuthenticationDescription[] ?? loginProviders.ToArray();
if (!authenticationDescriptions.Any())
{
<div>
<p>There are no external authentication services configured. See <a href="http://go.microsoft.com/fwlink/?LinkId=313242">this article</a>
for details on setting up this ASP.NET application to support logging in via external services.</p>
</div>
}
else
{
string action = Model.Action;
string returnUrl = Model.ReturnUrl;
using (Html.BeginForm(action, "Account", new { ReturnUrl = returnUrl }))
{
@Html.AntiForgeryToken()
<div id="socialLoginList">
<p>
@foreach (AuthenticationDescription p in authenticationDescriptions)
{
<button type="submit" class="btn btn-default padded-8 margin-8" id="@p.AuthenticationType" name="provider"
value="@p.AuthenticationType" title="Log in using your @p.Caption account">
<img src="@Url.Content("~/Content/Brands/"+p.Caption+".png")" alt="Microsoft" class="img-responsive" />
<br/>
<b>@p.Caption</b>
</button>
}
</p>
</div>
}
}
}抛出的错误是
在System.Core.dll中发生了'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException‘类型的异常,但未在用户代码中进行处理
附加信息:'object‘不包含'Action’的定义
快照上写着
Message : object‘不包含'Action’的定义来源:匿名托管的DynamicMethods程序集
这很奇怪,因为当我设置一个断点时,Model.Action不是空的。我可以看到它的价值。
这真的很令人沮丧。应用程序在5分钟前还在运行..我在一个不相关的页面上更改了html。现在它不起作用了。
Hackish修复我宁愿知道为什么会发生这个错误。也就是说,我有一个快速解决方案,以防其他人遇到这个问题(,因为这是默认解决方案的一部分)。解决方案是不使用动态。创建你自己的视图模型并传递它。
public class ExternalLoginViewModel
{
[Display(Name = "ReturnUrl")]
public string ReturnUrl { get; set; }
[Required]
[Display(Name = "Action")]
public string Action { get; set; }
}
@Html.Partial("_ExternalLoginsListPartial", new ExternalLoginViewModel { Action = "ExternalLogin", ReturnUrl = ViewBag.ReturnUrl })发布于 2014-07-10 19:47:26
微软已经验证了这个错误,他们正在努力修复它。
因此,任何来自未来的人如果阅读了这篇文章:请尝试将visual studio 2013至少更新为update 2。
发布于 2013-11-06 14:22:12
检查Account文件夹中的视图,对于每个具有显式模型的视图,确保(视图)模型位于正确的名称空间中。将鼠标悬停在m参数(m => m.UserName ...等),并确保它引用了正确的(视图)模型。在我的例子中,我将AccountViewModels移到了一个不同的文件夹,应用程序崩溃了,如上所述。这些视图似乎在某种程度上“缓存”了原始名称空间中的模型。我使用了一个愚蠢的修复(注释掉了@model行,并取消了注释)。我得到警告,m是动态的,但当构建和运行它时,它是有效的。看起来像是VS 2013 RTM中的一个小故障。
发布于 2013-11-21 21:53:34
在一些实验之后,我找到了我自己的(mvc5)项目的解决方案。
我有一个_ExternalLoginsListShoppingCartPartial.cshtml (来自我的mvc4项目),@model ICollection<AuthenticationClientData>在顶部。我将其注释掉并重新构建了解决方案,突然它就起作用了。我甚至没有在任何视图中使用那个局部视图,所以这是一个非常糟糕的bug。
因此,请签入您的项目。你可能有一些mvc4/simplemembership之类的东西搞乱了你的mvc5项目。
https://stackoverflow.com/questions/19626425
复制相似问题