You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

迁移至Visual Studio 2017后ASP.NET MVC项目出现编译错误

Fixing the "Remote Attribute Not Found" Error When Migrating ASP.NET MVC from VS2013 to VS2017

Hey there, let's work through this Error CS0246 you're facing with the [Remote] attribute after moving your ASP.NET MVC project to Visual Studio 2017. This is a common migration hiccup, so here are the most effective fixes to try:

  • Verify the System.Web.Mvc Reference Details
    Even if you see the DLL in your references, double-check its properties:

    1. Right-click System.Web.Mvc in your project's References → Select Properties.
    2. Confirm the Version matches your project's MVC version (e.g., 5.x for MVC5).
    3. Set Copy Local to True—this ensures the project uses the local DLL instead of relying on a potentially mismatched GAC version in VS2017.
  • Ensure the Correct Using Directive is Present
    The [Remote] attribute lives in the System.Web.Mvc namespace. Make sure your code file has:

    using System.Web.Mvc;
    

    If you suspect a namespace conflict, test using the fully qualified name temporarily:

    [System.Web.Mvc.Remote("ActionName", "ControllerName")]
    
  • Clean and Rebuild the Project
    Visual Studio's cached build files can cause version conflicts. Do a full clean:

    1. Right-click your project → Select Clean.
    2. Manually delete the bin and obj folders from your project directory.
    3. Rebuild the entire solution.
  • Check the Target .NET Framework
    VS2017 might have adjusted your project's target framework during migration. Confirm it's compatible with your MVC version:

    1. Right-click your project → Select Properties.
    2. Go to the Application tab.
    3. Ensure the Target framework is .NET Framework 4.5 or higher (required for MVC5 and later).
  • Reinstall the MVC NuGet Package
    Migration can break NuGet package references. Use the Package Manager Console to reset the MVC package:

    1. Open Tools → NuGet Package Manager → Package Manager Console.
    2. Run this command to uninstall the existing package:
      Uninstall-Package Microsoft.AspNet.Mvc -Force
      
    3. Reinstall the correct version (replace 5.2.9 with your original MVC version if needed):
      Install-Package Microsoft.AspNet.Mvc -Version 5.2.9
      
  • Validate Web.Config Settings
    Both the root web.config and the Views/web.config need proper MVC configuration:

    • In the root web.config, check the <assemblies> section has an entry for System.Web.Mvc (match the version to your package):
      <add assembly="System.Web.Mvc, Version=5.2.9.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      
    • In Views/web.config, ensure the <pages/namespaces> section includes:
      <add namespace="System.Web.Mvc" />
      

Try these steps in order—most folks fix this with either the NuGet reinstall or adjusting the reference properties. Let me know if you hit any roadblocks!

内容的提问来源于stack exchange,提问作者Venkat. D

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:59:43