Bug 23772 - Microsoft.AspNet.Mvc version not automatically updated in web.config after package update
Summary: Microsoft.AspNet.Mvc version not automatically updated in web.config after pa...
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Web (show other bugs)
Version: 3.12.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
: 35542 (view as bug list)
Depends on:
Blocks:
 
Reported: 2014-10-13 03:50 UTC by meng.wang
Modified: 2016-02-27 04:17 UTC (History)
7 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Solutions Tree (12.07 KB, image/png)
2015-03-02 00:12 UTC, doubledevwp
Details
Error Received (313.49 KB, image/png)
2015-03-02 00:13 UTC, doubledevwp
Details

Description meng.wang 2014-10-13 03:50:34 UTC
Description of Problem:


Steps to reproduce the problem:
1. Create a new solution and the Studio hints 3 updates beside "Packages" in solution explorer
2. Right click on "Packages" and select "Update"
3. After update is finished, start debugging the solution and an application exception occurs with the following exception information:
    System.InvalidOperationException
    Could not locate Razor Host Factory type: System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.0.0,
    Culture=neutral, PublicKeyToken=31BF3856AD364E35


Actual Results:
System.InvalidOperationException raised

Expected Results:
Website started with no problem

How often does this happen? 
Every time after updating the Microsoft.AspNet.Mvc package

Additional Information:
Root of problem discovered so far, MVC version in both web.config (the root one and the one under views/shared) is not automatically updated to the latest number. Once updated manually, the problem is eliminated.
Comment 1 Lluis Sanchez 2014-10-14 07:13:56 UTC
Matt, is this something the NuGet update should have fixed?
Comment 2 Matt Ward 2014-10-14 08:09:14 UTC
The MVC version is updated in the root Web.config but not the views/shared/Web.config. I see the binding redirect updated:

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

The only thing I needed to fix was the version in the views/shared/Web.config for the host factoryType:

    	<system.web.webPages.razor>
		<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

On Windows you do not need to fix the above, but on the Mac with Mono you do. Ideally it would work on Mono the same way. I am guessing that the host factory type is being redirected on Windows to the correct assembly but this is not happening on Mono.

The NuGet package will not update the views/shared/Web.config file. NuGet only supports updating the Web.config file in the project's root directory.

I cannot reproduce the Web.config file in the project's root directory not being updated. The views/shared/Web.config file will not be updated by NuGet. So NuGet is working as expected on my machine for both Mac and Windows.

My test steps:

1) Create new ASP.NET MVC Razor Project.
2) Update all the NuGet packages.
3) Run the project.
4) See error "Could not locate Razor Host Factory type..."
5) Edit views/shared/Web.config file and update <host factoryType...> to the correct assembly version.
6) Run the project again and see the web page opened with the welcome message displayed.
Comment 3 doubledevwp 2015-03-02 00:11:24 UTC
Hello,

I was wondering if this issue has ever been resolved?

I tried to add it in like Mr. Ward had mentioned, but it is not working for my project.

I started up a brand new project and was able to get it running.  I saw that there were some updates, so I updated them.  Two are still currently saying that they need updated and I am receiving the aforementioned issue.

I will attach a screen shot of the results after I updated.

Thank you,
DD
Comment 4 doubledevwp 2015-03-02 00:12:38 UTC
Created attachment 10104 [details]
Solutions Tree
Comment 5 doubledevwp 2015-03-02 00:13:20 UTC
Created attachment 10105 [details]
Error Received
Comment 6 Matt Ward 2015-03-02 05:02:30 UTC
With Xamarin Studio 5.7 after updating all the NuGet packages in the ASP.NET Razor project the only change I made to get it to run on the Mac without the "Could not locate Razor Host Factory" error was to update the version in the views/shared/Web.config
for the host factoryType:

        <system.web.webPages.razor>
        <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory,
System.Web.Mvc, Version=5.2.3.0, Culture=neutral,
PublicKeyToken=31BF3856AD364E35" />
Comment 7 Lluis Sanchez 2015-03-16 08:32:54 UTC
Can this be closed?
Comment 8 Mikayla Hutchinson [MSFT] 2015-03-16 17:35:15 UTC
I don't think so, I suspect it's a bug that Mono is not respecting the binding redirects.
Comment 9 Matt Ward 2015-11-10 04:47:43 UTC
*** Bug 35542 has been marked as a duplicate of this bug. ***

Note You need to log in before you can comment on or make changes to this bug.