DotNetOpenAuth loading Exceptions with 4.5.4

Just upgraded from 4.5.0 to 4.5.4.

I have a service that uses DotNetOpenAuth.Ultimate and ServiceStack.Razor, and now getting runtime exceptions like this:

iisexpress.exe Error: 0 : 21:30:31 [Error] [] [RecorderLogger.Error] "Can't load assembly: Crib.Services.AuthZ.Services": ReflectionTypeLoadException { Types: [ThisAssembly, DotNetOpenAuth.ComponentModel.ConverterBase`1[T], DotNetOpenAuth.ComponentModel.SuggestedStringsConverter, DotNetOpenAuth.ComponentModel.ClaimTypeSuggestions, 
...
A bunch of DNOA types listed here
...
, LoaderExceptions: [FileNotFoundException { Message: "Could not load file or assembly 'System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.", FileName: "System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35", FusionLog: "Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  C:\Program Files\IIS Express\iisexpress.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
 (Fully-specified)
LOG: Appbase = file:///C:/Projects/github/mindkin/crib/src/Services.AuthZ/
LOG: Initial PrivatePath = C:\Projects\github\mindkin\crib\src\Services.AuthZ\bin
Calling assembly : DotNetOpenAuth, Version=4.3.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Projects\github\mindkin\crib\src\Services.AuthZ\web.config
LOG: Using host configuration file: C:\Program Files\IIS Express\config\templates\PersonalWebServer\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/552e94cf/8a029da/System.Web.Mvc.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/552e94cf/8a029da/System.Web.Mvc/System.Web.Mvc.DLL.
LOG: Attempting download of new URL file:///C:/Projects/github/mindkin/crib/src/Services.AuthZ/bin/System.Web.Mvc.DLL.
LOG: Attempting download of new URL file:///C:/Projects/github/mindkin/crib/src/Services.AuthZ/bin/System.Web.Mvc/System.Web.Mvc.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/552e94cf/8a029da/System.Web.Mvc.EXE.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/552e94cf/8a029da/System.Web.Mvc/System.Web.Mvc.EXE.
LOG: Attempting download of new URL file:///C:/Projects/github/mindkin/crib/src/Services.AuthZ/bin/System.Web.Mvc.EXE.
LOG: Attempting download of new URL file:///C:/Projects/github/mindkin/crib/src/Services.AuthZ/bin/System.Web.Mvc/System.Web.Mvc.EXE.
", Data: [], InnerException: null, TargetSite: null, StackTrace: null, HelpLink: null, Source: null, HResult: -2147024894 }, FileNotFoundException { Message: "Could not load file or assembly 'System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.", FileName: "System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35", FusionLog: "=== Pre-bind state information ===
LOG: DisplayName = System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
 (Fully-specified)
LOG: Appbase = file:///C:/Projects/github/mindkin/crib/src/Services.AuthZ/
LOG: Initial PrivatePath = C:\Projects\github\mindkin\crib\src\Services.AuthZ\bin
Calling assembly : DotNetOpenAuth, Version=4.3.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Projects\github\mindkin\crib\src\Services.AuthZ\web.config
LOG: Using host configuration file: C:\Program Files\IIS Express\config\templates\PersonalWebServer\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: The same bind was seen before, and was failed with hr = 0x80070002.
", Data: [], InnerException: null, TargetSite: null, StackTrace: null, HelpLink: null, Source: null, HResult: -2147024894 }], Message: "Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.", Data: [], InnerException: null, TargetSite: System.RuntimeType[] GetTypes(System.Reflection.RuntimeModule), StackTrace: "   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)

Any ideas why would we be getting this in 4.5.4 and not in 4.5.0?

The DotNetOpenAuth.Ultimate NuGet package hasn’t been changed since 2013 and none of our OAuth projects reference MVC so can’t think of anything there.

From ServiceStack.Razor v4.5.0 we started referencing the official Microsoft.AspNet.Razor package instead of bundling System.Web.Razor.dll but we haven’t made any structural changes since v4.5.0.

Maybe check if your Web.config matches the Razor config in? http://docs.servicestack.net/razor-notes#web-configuration-for-razor

Update; Just confirmed that we were actually getting this same exception with the 4.5.0 version.

So more accurately, problem was actually introduced somewhere between 4.0.56 and 4.5.0.

Which version of Microsoft.AspNet.Mvc package is installed in the project? Did you try to reinstall Microsoft.AspNet.Mvc package into the project which references DotNetOpenAuth? Do you have assembly binding redirect in your web.config similar to this one (version number and public key token depends on installed AspNet.Mvc package version)?

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
  </dependentAssembly>
</assemblyBinding>

Neither, I do not reference System.Web.Mvc at all.

Do you know, if that expected to be referenced in a ServiceStack.Razor project?
Or, is that expected to be referenced in a DotNetOpenAuth project?

I thought that MVC and ServiceStack.Razor do not play well together?

In your log there is a message that System.Web.Mvc is calling by DotNetOpenAuth.

Calling assembly : DotNetOpenAuth, Version=4.3.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246.

ServiceStack.Razor does not reference System.Web.Mvc assembly. Adding Mvc as just as assembly reference to the project should not break ServiceStack.Razor functionality.

Alright, so given that System.Web.Mvc is somehow a dependency of DotNetOpenAuth, we can think about if we want to add that or not to our project (and then what version and binding we need to have).