How to fix error The type or namespace name 'Linq' does not exist in the namespace 'System'
Try add System.Linq namespace in your default controller.
Andrus
Updated on July 21, 2022Comments
-
Andrus almost 2 years
ASP.NET MVC4 application contains Helper.chtml file in App_Code folder containing Razor helpers. After upgrading to Visual Studio Communitity edition compile error
Error CS0234 The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?) C:\Users\user\AppData\Local\Temp\Temporary ASP.NET Files\admin\e209c0e0\c74032ba\Sources_App_Code\helper.cshtml.72cecc2a.cs 16
Starts to occur. Generated code contains:
namespace ASP { using System; using System.Collections.Generic; using System.IO; using System.Linq; // Error occurs in this line using System.Net; using System.Web; using System.Web.Helpers; using System.Web.Security; using System.Web.UI; using System.Web.WebPages; using System.Web.WebPages.Html; #line 1 "C:\Web\Erp\App_Code\Helper.cshtml" using System.Web.Mvc; #line default #line hidden #line 2 "C:\Web\Erp\App_Code\Helper.cshtml" using System.Threading; #line default #line hidden #line 3 "C:\Web\Erp\App_Code\Helper.cshtml" using MyApp.Business; #line default #line hidden public class Helper : System.Web.WebPages.HelperPage {
Error points to
using System.Linq;
line.How to fix this ? Using ASP.NET4
I tried to add reference to System.Core to project but got error that it is already referenced. web.confing contains
<compilation debug="true"> </compilation>
I changed it to
<compilation debug="true" targetFramework="4.0"> </compilation>
according The type or namespace name 'Linq' does not exist in the namespace 'System' and https://social.msdn.microsoft.com/Forums/en-US/c970ea3d-5238-4ec7-8859-e16b40dccd3d/the-type-or-namespace-name-linq-does-not-exist-in-the-namespace-systemare-you-missing-an?forum=linqprojectgeneral
but after that compile error changes to
Error CS0234 The type or namespace name 'global_asax' does not exist in the namespace 'ASP' (are you missing an assembly reference?)
which points to code
protected static ASP.global_asax ApplicationInstance { get { return ((ASP.global_asax)(Context.ApplicationInstance)); } }
in generated helper.cshtml.72cecc2a.cs file.
How to fix this error ?
Update
Relevant parts of web.config are:
<?xml version="1.0" encoding="utf-8"?> <configuration> <system.data> <DbProviderFactories> <clear /> <add name="Npgsql Data Provider" invariant="Npgsql" support="FF" description=".Net Framework Data Provider for Postgresql Server" type="Npgsql.NpgsqlFactory, Npgsql" /> </DbProviderFactories> </system.data> <system.web> <httpModules> <remove name="RoleManager" /> </httpModules> <compilation debug="true"> </compilation> <customErrors mode="Off" /> <globalization uiCulture="auto" culture="auto" enableClientBasedCulture="true" /> <pages> <namespaces> <add namespace="MYApp.Business" /> <add namespace="System.Web.Helpers" /> <add namespace="System.Web.Mvc" /> <add namespace="System.Web.Mvc.Ajax" /> <add namespace="System.Web.Mvc.Html" /> <add namespace="System.Web.Routing" /> <add namespace="System.Web.Optimization" /> <add namespace="System.Web.WebPages" /> </namespaces> </pages> </system.web> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration>
-
Andrus about 8 yearsWhat is default controller ? App has common base class for controllers, shoult it added there ?
-
joint_ops about 8 yearsit's this one which controls Your action. For e.g. by default Action Controller controls Yours login & register actions.
-
joint_ops about 8 yearsalso please check this post and comment section it might be helpful. stackoverflow.com/a/22873162/5600402 it appears that some of Your references didn't updated while updating VS.
-
Christian about 3 yearsThis is not a matter of a missing using file or a missing reference - I've been battling this problem for months now on my development machine. I ended up using a clean Windows machine, with nothing else than a VS pro 2019 installed and here the project compiles. This is not a viable solution as all other team members keep getting this error in their development machine. The underlying problem is much deeper than a silly syntax problem.
-
Christian about 3 yearsI even get this problem creating an entirely new project, in a clean solution from the VS add new project guide. Same error error message on every view.