6
votes

I get the following error below after opening and compiling my MVC4 project in VS 2010.

CS1705: Assembly 'SDEM, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'System.Web.Mvc, Version=4.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

In my web.config I have

    <add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

Anyone have some clue what I should do to solve this version problem?

3
I got the same error. It shows that the assembly you referenced in the project has 4.0.0.1 version but in web.config you have 4.0.0.0 version. Please check that the referenced assembly for System.Web.Mvc is the same as written in the web.config. If not then add reference to the appropriate assembly by Right click References -> Add Reference -> ...Sarim Javaid Khan
I have edited the comment please see it.Sarim Javaid Khan
Try to reference it to the MVC assembly present in the "Assemblies" folder in the root of the .net project.Sarim Javaid Khan
@SarimJavaidKhan Thank you soooo much! I have removed the previous System.Web.Mvc which shows a runtime version of 4.0.0.301 something like that, and then I added the System.Web.Mvc by " Right click References -> Add Reference ->" with version 4.0.0. Then it works like magic!!! Thank you so much Sarim, thank you.Mona
Your welcome. I am adding it as an answer . please select as answered.Sarim Javaid Khan

3 Answers

9
votes

It shows that the assembly you referenced in the project has different version(4.0.0.1) as what you have in web.config(4.0.0.0).

Please check that the referenced assembly for System.Web.Mvc is the same as written in the web.config.

If not then add reference to the appropriate assembly. Right click References -> Add Reference -> ...

8
votes

Install Nuget Package Microsoft.AspNet.Mvc for all the project referencing System.Web.Mvc dll

Example: Install-Package Microsoft.AspNet.Mvc

0
votes

Solution:

Don't refer Nuget package components directly from the cshtml code. Instead, write an adapter calling static HtmlHelper extension methods from your custom extension methods with the same signature.

This approach has two advantages:

  • First, it automatically suppresses CS1702.
  • Secondly and above all, when you change used NuGet package, the compiler will notify you of the necessary link fixes (consisting perhaps only in changing the using command at the beginning of the cs code), while if you use NuGet component references directly from the cshtml code, run-time issues will appear.

I just verified this migrating from PagedList/PagedList.MVC to X.PagedList/X.PagedList.MVC.

namespace MyMvcExtensions
{
    public static class MyHelperExtensions
    {
    ...
        public static HtmlString PagedListGoToPageForm(this HtmlHelper html, IPagedList list, string formAction)
        {
            return X.PagedList.Mvc.HtmlHelper.PagedListGoToPageForm(html, list, formAction);
        }
        public static HtmlString PagedListGoToPageForm(this HtmlHelper html, IPagedList list, string formAction, string inputFieldName)
        {
            return X.PagedList.Mvc.HtmlHelper.PagedListGoToPageForm(html, list, formAction, inputFieldName);
        }
        public static HtmlString PagedListGoToPageForm(this HtmlHelper html, IPagedList list, string formAction, X.PagedList.Mvc.Common.GoToFormRenderOptions options)
        {
            return X.PagedList.Mvc.HtmlHelper.PagedListGoToPageForm(html, list, formAction, options);
        }
        public static HtmlString PagedListPager(this System.Web.Mvc.HtmlHelper html, IPagedList list, Func<int, string> generatePageUrl)
        {
            return X.PagedList.Mvc.HtmlHelper.PagedListPager(html, list, generatePageUrl);
        }
        public static HtmlString PagedListPager(this HtmlHelper html, IPagedList list, Func<int, string> generatePageUrl, X.PagedList.Mvc.Common.PagedListRenderOptionsBase options)
        {
            return X.PagedList.Mvc.HtmlHelper.PagedListPager(html, list, generatePageUrl, options);
        }
    }
}

In your cshtml code write @using MyMvcExtensions instead of @using X.PagedList.Mvc.

If you will migrate to hypothetical Y.PagedList.MVC, compiler will alert you must do changes in your MyHelperExtensions class.