2
votes

For some reason when I try to post to one of the ActionMethods on the AccountController in my MVC4 application, it tells me that it failed to load System.Web.Mvc, Version=1.0.0.0 or one of its dependency. I'm not sure why it is trying to load this assembly when I'm actually using runtime version 4.

I suspected that one of the referenced assemblies could be causing this problem but I'm not really sure. My main suspect is DotNetOpenAuth.Core because of the following trace:

=== Pre-bind state information === LOG: User = NT AUTHORITY\NETWORK SERVICE LOG: DisplayName = System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 (Fully-specified) LOG: Appbase = file:///C:/tfs/AMS/Main/AMS/AuthServer/ LOG: Initial PrivatePath = C:\tfs\AMS\Main\AMS\AuthServer\bin Calling assembly : DotNetOpenAuth.Core, Version=4.2.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246. === LOG: This bind starts in default load context. LOG: Using application configuration file: C:\tfs\AMS\Main\AMS\AuthServer\web.config LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config. LOG: Post-policy reference: System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/d0b0b808/59620299/System.Web.Mvc.DLL. LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/d0b0b808/59620299/System.Web.Mvc/System.Web.Mvc.DLL. LOG: Attempting download of new URL file:///C:/tfs/AMS/Main/AMS/AuthServer/bin/System.Web.Mvc.DLL. WRN: Comparing the assembly name resulted in the mismatch: Major Version ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

The exception occurs when I try to post to the following method:

    [HttpPost]
    public ActionResult Login(String username, String password)
    {
        var request = Session[SESSION_KEY] as EndUserAuthorizationRequest;
        if (request != null)
        {
            Guid siteId = Guid.Parse(request.ClientIdentifier);
            Boolean isAuthenticated = this._identityProviderManager.Authenticate(siteId, "FA", username, password);
            if (isAuthenticated)
            {
                var serviceHost = new AuthorizationServerHost();
                var authorizationServer = new DotNetOpenAuth.OAuth2.AuthorizationServer(serviceHost);
                var approvalMessage = authorizationServer.PrepareApproveAuthorizationRequest(request, username, request.Scope);
                return authorizationServer.Channel.PrepareResponse(approvalMessage).AsActionResult();

            }
        }
        return View();
    }

Any ideas?

1
I've seen a similar error and it was because the web.config was referencing a different System.Web.Mvc. I fixed the reference and my project worked again. Hope this helps.lopezbertoni

1 Answers

4
votes

Ok I found the solution. Apparently I had to add the following to the web.config file.

  <runtime>
    <!-- This prevents the Windows Event Log from frequently logging that HMAC1 is being used (when the other party needs it). -->
    <legacyHMACWarning enabled="0" />
    <!-- When targeting ASP.NET MVC 3, this assemblyBinding makes MVC 1 and 2 references relink
             to MVC 3 so libraries such as DotNetOpenAuth that compile against MVC 1 will work with it.
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
                <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
            </dependentAssembly>
        </assemblyBinding>
         -->
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

Hopefully that will help other people who come across the same problem.