Asp.net MVC 5.2.2 on Azure

ぐ巨炮叔叔 提交于 2019-12-10 20:34:21

问题


After upgrading mvc nuget package from version 5.1.0 to 5.2.2 our machine (webrole) on Azure refuses to start the web role. It was in recycling state. I found an error in event log :

    The description for Event ID 1007 from source Windows Azure Runtime 2.4.0.0 cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.

If the event originated on another computer, the display information had to be saved with the event.

The following information was included with the event: 

820
WaIISHost
Role entrypoint could not be created: System.TypeLoadException: Unable to load the role entry point due to the following exceptions:
-- System.IO.FileLoadException: Could not load file or assembly 'System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

 ---> System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.RuntimeModule.GetTypes()
   at System.Reflection.Assembly.GetTypes()
   at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetRoleEntryPoint(Assembly entryPointAssembly)
   --- End of inner exception stack trace ---
   at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetRoleEntryPoint(Assembly entryPointAssembly)
   at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.CreateRoleEntryPoint(RoleType roleTypeEnum)
   at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.InitializeRoleInternal(RoleType roleTypeEnum) 
the message resource is present but the message is not found in the string/message table

I tried to search over the internet, but with no useful answer. I wasn't able to solve it otherwise than downgrade. Luckily package version 5.1.1 is working.

Update 1: After some trial and error I found, that asp.net mvc packages are OK up to version 5.1.3 It looks like packages from 5.2.0 upwards are not supported.

Update 2: We have decided to split our web and web.api, so I didn't have this problem anymore. My best guess is, that there was indeed nuget, which was referencing older asp.net mvc package.


回答1:


I had a similar problem. We inherited a project and updated the ASPNET MVC version to 5.2.2.0. We couldn't deploy to Azure. The only error we could find was the one you mentioned here.

We corrected every web.config file so older versions were redirected to a newer version but we still had the same problem.

Then we wrote a small test method that iterated over every Assembly and we saw that one NuGet package was still using Asp.net MVC 4.0. This package was an old version and hadn't been updated for a while. I downloaded the source, updated the Mvc Nuget and manually inserted the dll.

We deployed again and everything went flawless.

Here is are test method.

 private void TestAssemblies()
    {
        var allAssemblies = AppDomain.CurrentDomain.GetAssemblies();
        foreach (Assembly item in allAssemblies)
        {
            PrintAssembly(item);
        }
    }
    private void PrintAssembly(Assembly assembly)
    {
        foreach (var item in assembly.GetReferencedAssemblies())
        {
            if (item.FullName.Contains("System.Web.Mvc"))
            {

                Debug.WriteLine(item);
                Debug.WriteLine("Parent: " + assembly.FullName);
                Debug.WriteLine("------------------------------------------------------------");
            }
        }
    }



回答2:


MVC 5.2.2 works perfectly fine in Azure. Your role recycling is most likely an indication that either you have not properly deployed your application properly or that you have a hidden dependency on an older version of MVC that a binding redirect may not handle.

I would strongly suggest that you read all of the entries in Kevin Williamson's great series on trouble shooting Azure deployments.

There are a ton of things that can go wrong, so rather than try to create a generic one-size-fits-all list, review the blog posts and then post a comment if you are unable to figure out what specifically is happening.

Given the error that you did post, assuming you have the proper binding redirect that @Yishai Galatzer mentions, you might have a DLL in your deployment that has a hidden dependency on MVC 5.1.0.0. I would suggest using a program like Jetbrains DotPeek to inspect all of your DLLs in your package and look at their references. I suspect you'll find one that itself depends on 5.1.0.0.




回答3:


I have also face similar problem with mvc5.2.2 azure deployment..

the ultimate solution is we need to add this web.config

<dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
</dependentAssembly>``



回答4:


From the looks of it, looks like you are missing a binding redirect to MVC 5.2.2 in your web.config. This should just work.

We are working on verifying this scenario. But let us know if this works for you. In your web.config please take a look at the following section, and makes sure it matches with this xml below:

<dependentAssembly> <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-5.2.2.0" newVersion="5.2.2.0" /> </dependentAssembly>




回答5:


I had exactly similar problem couple of days back. Please refer to this post. You need to add <dependentAssembly> section to WaIISHost.exe.config which is generally @ 'E:\base\x64' on your VM.




回答6:


Many times I've found the problem to be in the ~\Views\Web.config file. It keeps a reference to the old MVC version. Just manually update it.

If that doesn't work do a full text search of your solution in Sublime Text or some other tool outside of VS and search for the version string causing you issues.




回答7:


I had the same issue, where it worked fine on my Dev machine, but when deployed I was getting the assembly error. To resolve this, I had to change the "oldVersion" from version 0.0.0.0 to version 1.0.0.0

<dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
</dependentAssembly>

To

<dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
</dependentAssembly>


来源:https://stackoverflow.com/questions/26490505/asp-net-mvc-5-2-2-on-azure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!