Razor - unable to add System.Core to Web.Config - razor

I am using ServiceStack (self hosted) with Razor.
I have an issue trying to add System.Core to the namespaces in the web.config file.
Specifically, I get a compilation error if I include System.Core in the web.config.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0234: The type or namespace name 'Core' does not exist in the namespace 'System' (are you missing an assembly reference?)
Source Error:
Line 12: using System;
Line 13: using System.Collections.Generic;
Line 14: using System.Core;
Line 15: using System.Data;
Line 16: using System.IO;
Extract of Web.config file:
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc" />
<pages pageBaseType="ServiceStack.Razor.ViewPage">
<namespaces>
<add namespace="System" />
<add namespace="System.Core" /> **-> THIS GIVES AN ERROR**
<add namespace="System.Data" />
<add namespace="System.Linq" />
<add namespace="ServiceStack" />
<add namespace="ServiceStack.Html" />
<add namespace="ServiceStack.Razor" />
<add namespace="ServiceStack.Text" />
<add namespace="ServiceStack.OrmLite" />
<add namespace="Classifieds" />
<add namespace="Classifieds.ServiceModel" />
<add namespace="Classifieds.ServiceInterface" />
</namespaces>
</pages>

System.Core is not a namespace its is an assembly

Related

SSRS Web Application Error. Having version issues

Here is what I have and I'm sure it is versioning but I can't seem to figure it out.
Visual Studio 2019
Framework : 4.7.2
This was Framework 3.5 and I upgraded to version 4.7.2. It was working until I open a report to edit and then it wants to edit the Report (RDLC).
Error1: Severity Code Description Project File Line Suppression State
Error The type 'Microsoft.Reporting.WebForms.ReportViewer' exists in both 'c:\Windows\assembly\GAC_MSIL\Microsoft.ReportViewer.WebForms\9.0.0.0__b03f5f7f11d50a3a\Microsoft.ReportViewer.WebForms.dll' and 'c:\Windows\assembly\GAC_MSIL\Microsoft.ReportViewer.WebForms\10.0.0.0__b03f5f7f11d50a3a\Microsoft.ReportViewer.WebForms.dll' D:\Development\Work\asedra\Website\Reports\RptViolation.aspx 44
Error 2 : ASP.NET session has expired
Web.config:
<buildProviders>
<add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
</buildProviders>
<assemblies>
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="Microsoft.ReportViewer.DataVisualization, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="Microsoft.ReportViewer.ProcessingObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="Microsoft.SqlServer.Types, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
</assemblies>
rdlc
<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
the web page (.aspx)
<%# Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>[![enter image description here][1]][1]
Error1: Register ReportViewer on .aspx like this
<%# Register assembly="Microsoft.ReportViewer.WebForms" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>
Add to web.config this line
<system.webServer>
<handlers>
<add name="ReportHandler" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</handlers>
</system.webServer>
Error2: Store session state on SQL server. Here's a guide: HOW TO: Configure SQL Server to Store ASP.NET Session State.
Basically, you need to create ASPState database, activate ASP.NET State Service and add this line to the web.config:
<sessionState
mode="SQLServer"
sqlConnectionString="data source=127.0.0.1;user id=<username>;password=<strongpassword>"
cookieless="false"
timeout="20"
/>

ERROR AFTER CHANGING NAMESPACE OF ASP.net MVC PROJECT

Recently i have changed the namespace using the project properties. After that, application was compiling successfully, but at run-time it throws error "The type or namespace name ‘sample’ could not be found (are you missing a using directive or an assembly reference?)".
Error:
Line 23: using System.Web.Routing;
Line 24: using Sample;
Source File: c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files......\App_Web_index.cs Line:
I tried to locate the string “using Sample” and didn’t find anywhere in my solution.
Tried removing the temporary files from framework folder but no luck.
The problem was with my Web.config file
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization"/>
<add namespace="System.Web.Routing" />
<add namespace="Sample" />
</namespaces>
</pages>
I just replaced the old value "Sample" with new namespace name, and everything starts working again.
Answering so that anyone else has the same issue. There another web.config file under views. please change it there too.

ASP.NET <asp:> not recognized?

I'm trying to catch a variable from a textbox in ASP.NET (can that be done through regular < input > boxes?). But with every tutorial they're using the < asp :> tag. When I try to use it, Intellisense doesn't recognize it, and when I try to compile the whole textbox dissapears.
I try to add it through the web.config file by adding <pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting" assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</controls>
</pages>
but then I get an compile error:
Server Error in '/' Application.
Configuration Error
Description: An error occurred during the processing of a
configuration file required to service this request. Please review the
specific error details below and modify your configuration file
appropriately.
Parser Error Message: Unrecognized configuration section pages.
Source Error:
Line 34: Line 35: Line 36: Line 37:
Line 38:
Source File: c:\users\mitchell\documents\visual studio
2017\Projects\WebApp_ProjectManager\WebApp_ProjectManager\views\web.config
Line: 36
Any suggestions?
I'm trying to catch variables from these textboxes:
Benodigdheden: <br />< input id="project_benodigdheden" type="text" />
<br />
Locatie van benodigdheden: <br /> < input id="project_benodigdheden_locatie" type="text" />

Failed to generate code. Could not load file or assembly 'MySql.Data, Version=6.6.5.0

I'm getting the following error on all of my website's pages:
Server Error in '/' Application.
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Failed to generate code. Could not load file or assembly 'MySql.Data, Version=6.6.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Source Error:
Line 1: <?xml version="1.0" encoding="utf-8"?>
Line 2: <xs:schema id="newsarticles" targetNamespace="http://tempuri.org/news.xsd" xmlns:mstns="http://tempuri.org/news.xsd" xmlns="http://tempuri.org/news.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:msprop="urn:schemas-microsoft-com:xml-msprop" attributeFormDefault="qualified" elementFormDefault="qualified">
Line 3: <xs:annotation>
Source File: /App_Code/news.xsd Line: 1
Assembly Load Trace: The following information can be helpful to determine why the assembly 'MySql.Data, Version=6.6.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' could not be loaded.
I checked the assemblies in my web.config, but no references to MySQL are there:
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0">
<assemblies>
<clear />
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Data.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Data.Services.Client, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /></assemblies>
</compilation>
I then checked the references of my website project. There I noticed a lot of different MySQL versions are referenced. I tried to delete all references but version 6.7.4.0, however, I can't even delete the references (see screenshot).
I have these files in my bin folder, both of version 6.7.4.0:
MySql.Data.dll and MySql.Data.Entity.dll
How to fix this error?
try to add this to your web.config:
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description="Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data" />
</DbProviderFactories>
</system.data>
Also, you don't need to reference any dlls from GAC. Just use nuget packages (MySQL.Data, MySQL.Web)

System.Web.Optimization cannot be used in a razor view file in a Class Library project

I am working in a modularized asp.net mvc4 project. Some views are located in a Class Library project. I already set the web.config to enable the intelligence in razor views. The #model, #Html.* and others are all working well. But when I try to reference a js file in my view by using the #Scripts.Render(). It says cannot find "Scripts". I checked the web.config file. The System.Web.Optimization is in the // node. I also installed Microsoft.AspNet.Web.Optimization package by Nuget.
I tried to type the code in a .cs file to use the System.Web.Optimization members, it works. But I cannot do same thing in the .cshtml file. Even when I typing #using System.Web.Optimization, it prompt me the Optimization cannot be found.
I am not sure what else I can do to resolve this issue. Any clues are very appreciated.
If you have a Web.config at the root of the class library, confirm it contains the following: <add namespace="System.Web.Optimization"/>
If you do not, trick Visual Studio into thinking that it is a web project and enable Intellisense and resolve your issue by adding a web.config file to the root of your class library project (the one that contains the Razor views) with the following contents (taken from this blog post) :
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization"/>
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
</system.web.webPages.razor>
<system.web>
<compilation targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</assemblies>
</compilation>
</system.web>
</configuration>
The above is what worked for me when I faced this issue, but here are more links:
http://forums.asp.net/t/1812274.aspx/1
Getting System.Web.Optimization to work in a razor view within a class library