MVC5 Microsoft.CSharp.RuntimeBinder.RuntimeBinderException [英] MVC5 Microsoft.CSharp.RuntimeBinder.RuntimeBinderException

查看:548
本文介绍了MVC5 Microsoft.CSharp.RuntimeBinder.RuntimeBinderException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直工作到MVC5一个MVC4项目转换。第一天,我遇到了一个'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException,但能够通过在开始我的转换来解决它。我不知道什么是修复这是一个令人失望的,因为它的再次发生。

当我加载页面Login.cshtml发生在_ExternalLoginsListPartial.cshtml的错误。该错误是扔在15行(串动= Model.Action;)

  @using Microsoft.Owin.Security@ {
    VAR loginProviders = Context.GetOwinContext()Authentication.GetExternalAuthenticationTypes()。
    VAR authenticationDescriptions = loginProviders作为AuthenticationDescription []? loginProviders.ToArray();
    如果(!authenticationDescriptions.Any())
    {
        < D​​IV>
            < P>有没有配置外部认证服务。见< A HREF =htt​​p://go.microsoft.com/fwlink/?LinkId=313242>这条< / A>
            关于设立这个ASP.NET应用程序的详细信息,以支持通过外部服务登录上述< / P>
        < / DIV>
    }
    其他
    {
        串动= Model.Action;
        字符串RETURNURL = Model.ReturnUrl;
        使用(Html.BeginForm(动作,帐户,新的{RETURNURL = RETURNURL}))
        {
            @ Html.AntiForgeryToken()
            < D​​IV ID =socialLoginList>
                &所述p为H.;
                @foreach(在authenticationDescriptions AuthenticationDescription P)
                {
                    <按钮式=提交级=BTN BTN-默认填充-8利润率-8ID =@ p.AuthenticationTypeNAME =提供者
                            在使用@ p.Caption帐号登录&GT值=@ p.AuthenticationType称号=;                        < IMG SRC =@ Url.Content(〜/内容/品牌/+ p.Caption +PNG),ALT =微软级=IMG响应/>
                        < BR />
                        < B> @ p.Caption< / B>
                    < /按钮>
                }
                &所述; / P>
            < / DIV>
        }
    }
}

引发的误差


  

类型'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException的异常出现在System.Core.dll但在用户code没有处理


  
  

更多信息:'对象'不包含定义'行动


快照说:


  

消息:对象'不包含定义'行动'
  来源:匿名运行DynamicMethods大会


现在,因为当我设置一个断点Model.Action不为空,这是双重怪异。我能看到的价值。

这是很无奈。该应用程序是工作5分钟前..我改变了HTML的非相关页面上..现在它不会工作。

hackish的修正
我宁愿知道为什么这个错误发生。这就是说,我的情况下,任何人速战速决遇到这种( 因为这是默认的解决方案的一部分一部分)。解决的办法是不使用动态。创建您自己的视图模型,并通过这一点。

 公共类ExternalLoginViewModel
{
    [显示(NAME =RETURNURL)]
    公共字符串RETURNURL {搞定;组; }    [需要]
    [显示(名称=行动)
    公共字符串操作{搞定;组; }
} @ Html.Partial(_ ExternalLoginsListPartial,新ExternalLoginViewModel {行动=ExternalLogin,RETURNURL = ViewBag.ReturnUrl})


解决方案

此错误是由微软证实,他们已进行修正工作。

因此​​,从未来的人谁读这一点:尝试更新的Visual Studio 2013年至少更新2

<一个href=\"https://connect.microsoft.com/VisualStudio/feedback/details/813133/bug-in-mvc-5-framework-asp-net-identity-modules\" rel=\"nofollow\">https://connect.microsoft.com/VisualStudio/feedback/details/813133/bug-in-mvc-5-framework-asp-net-identity-modules

Ive been working on converting a MVC4 project over to MVC5. The first day I ran into an 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' but was able to resolve it by starting my conversion over. I'm not sure what the fix was which is a bummer, because its happened again.

The Error occurs in _ExternalLoginsListPartial.cshtml when I load the Login.cshtml page. The error is thrown on line 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>
        }
    }
}

The error thrown is

An exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred in System.Core.dll but was not handled in user code

Additional information: 'object' does not contain a definition for 'Action'

The snapshot says

Message : object' does not contain a definition for 'Action' Source : Anonymously Hosted DynamicMethods Assembly

Now this is double weird because when I set a breakpoint Model.Action is not null. I can see the value.

This is really frustrating. The app was working 5 min ago.. I had changed the html on a non related page.. and now it wont work.

Hackish Fix I would rather know why this error is happening. That said, I have a quick fix in case anyone else comes across this (Because this is part of part of the default solution). The solution is to not use dynamics. Create your own viewmodel and pass that.

  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 })

解决方案

This bug is verified by Microsoft, and they are working on fixing it.

So anyone from the future who reads this: try updating visual studio 2013 to at least update 2.

https://connect.microsoft.com/VisualStudio/feedback/details/813133/bug-in-mvc-5-framework-asp-net-identity-modules

这篇关于MVC5 Microsoft.CSharp.RuntimeBinder.RuntimeBinderException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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