LINQ in Razor View Broken for VB - asp.net

I'm trying to use LINQ in a Razor view (VB syntax) and I have the following:
Model.TypeList.Select(Function(i) ...)
Syntactically, everything is correct; the statement is correct, and the Model types are defined correct. However, I get the following error within design-time:
Error 12 'Select' is not a member of 'System.Collections.Generic.List(Of TypeItem)'
Obviously Select is a LINQ extension method, but it's not supported in my view, even though the DLL reference is there, and I added it as a namespace to the web.config files... Why is this basic feature not working?
I am using ASP.NET MVC 5.0, and note I'm using a custom base page class. EDIT: In the view I am using, I have the following imports:
#Imports System.Linq
#Imports System.Collections.Generic
My root web.config file has the following:
<system.web>
<compilation debug="true" targetFramework="4.5.1" />
<httpRuntime targetFramework="4.5" />
<pages>
<namespaces>
<add namespace="System.Collections.Generic"/>
<add namespace="System.Linq"/>
<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.Optimization" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
My views wb.config has the following:
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="Custom.MvcViewPage">
<namespaces>
<add namespace="System.Collections.Generic"/>
<add namespace="System.Linq"/>
<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>
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
<system.web>
<httpHandlers>
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
<pages
validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="Custom.MvcViewPage"
userControlBaseType="Custom.MvcViewUserControl">
<controls>
<add assembly="System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
Note: the app works when it runs, so this is a design-time only error.

At the top of your view file, include:
#Imports System.Linq
Update:
On further inspection, System.Linq was properly included. However, I noticed that the Web.config had different values for the targetFramework attribute on the <httpRuntime> and <compilation> elements. Setting those to both be the same, namely 4.5.1, fixed the issue.
<httpRuntime targetFramework="4.5.1" />

Related

Are the .config files part of ASP.NET?

I'm programming a web with the MVC pattern, so I've created the Web.config files that I needed (~/Web.config and ~/Views/Web.config), but I want run my web in Apache.
I've heard .config files only run in IIS. What can I do?
What multiplatform solution I need?
Example of Web.config
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.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" />
<add namespace="Myweb" />
</namespaces>
</pages>
</system.web.webPages.razor>

mvc 4 razor view do not understand #Html.Kendo()

I am facing one problem with Kendo UI server wrappers in ASP.NET MVC 4
If I use .ASPX default view It understands the
<%: Html.Kendo().Grid() %>
But at the same time If I try to add Razor view
It do not understand
#(Html.Kendo() ) systax.
I have entry in web.config as well
<namespaces>
<add namespace="Kendo.Mvc.UI" />
<httpHandlers>
<add path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" verb="*" validate="false" />
</httpHandlers>
<handlers>
<add name="Telerik_Web_UI_WebResource_axd" verb="*" preCondition="integratedMode" path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" />
Pl tell me what I must be missing and where
Thanks and Regards,
Amit
To register Kendo UI using Razor templates make sure you have the below in your Views\Web.config.
Towards the bottom of the page also details the setup in telerik's documentation.
http://docs.telerik.com/kendo-ui/getting-started/using-kendo-with/aspnet-mvc/asp-net-mvc-4
<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="Kendo.Mvc"/>
<add namespace="Kendo.Mvc.UI"/>
</namespaces>
</pages>
</system.web.webPages.razor>
I also have the below in my main Web.config file.
<system.web>
<compilation debug="true" targetFramework="4.5">
<assemblies>
...
<add assembly="Kendo.Mvc"/>
</assemblies>
</compilation>
</system.web>
Adding #using Kendo.Mvc.UI at the top of the page and it worked for me
Check if your web.config settings is in the View Folder ( web.config files) not the root Web.config

Connection name 'SQL' was not found in the applications configuration or the connection string is empty

Please i have been seeing this error:
The connection name 'SQL' was not found in the applications
configuration or the connection string is empty. Description: An
unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the
error and where it originated in the code.
I know for a fact that the connection name "SQL" exists and it works properly on my local machine.
I started seeing this error after i fixed this other error on my deployment server:
Compiler Error Message: BC31007: Unable to open module file
'C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files
by setting up the access rights as suggested here
Please i would appreciate any help on this.
thanks!
Deployment Environment : Windows Server 2003, .net 4.0
Development Environment: Widows 7, .net 4.0
Please note: The deployed application has been working perfectly well on site, for over 3 months up till last Friday evening.
The client claims nothing on the server or in their environment has changed.
My Web Config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appSettings>
<add key="LoginMode" value="2" />
<add key="CustomeModules" value="True" />
<add key="TopCallersRefeshInterval" value="600" />
<add key="OperatorAccountName" value="" />
<add key="ChartImageHandler" value="storage=file;timeout=20;dir=C:\TempImageFiles\;"/>
</appSettings>
<connectionStrings>
<add name="SQL" connectionString="server=.\SQL2008;database=xxxxxx;uid=xxxxxx;pwd=xxxxxxxxxx;" providerName="System.Data.SqlClient" />
<add name="SQLCustom" connectionString="server=.\SQL2008;database=xxxxxx;uid=xxxxxx;pwd=xxxxxxxxxx;" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<httpHandlers>
<add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false" />
</httpHandlers>
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting" assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</controls>
</pages>
<compilation debug="true" targetFramework="4.0" explicit="true">
<assemblies>
<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.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /></assemblies>
</compilation>
</system.web>
<system.webServer>
<defaultDocument>
<files>
<remove value="login.aspx" />
<remove value="iisstart.htm" />
<remove value="default.aspx" />
<remove value="index.html" />
<remove value="index.htm" />
<remove value="Default.asp" />
<remove value="Default.htm" />
<add value="home.aspx" />
</files>
</defaultDocument>
<handlers>
<add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</handlers>
</system.webServer>
</configuration>
But, are you trying to connect to the remote database (i.e., the database on the deployment server) or to a local database.
Maybe somebody has touched the access privileges to the database...
By the way, how did you fixed the original error?
Delete every file(s) with .config format i.e. "web.user.config" but "web.config".
I hope it's help :)
Clear out the temp folder on your server. Recompile, redeploy and see if that fixes it for you. Also:
<connectionStrings>
<clear />
<remove name="SQL"/>
<add name="SQL"
connectionString="server=.\SQL2008;database=xxxxxx;uid=xxxxxx;pwd=xxxxxxxxxx;"
providerName="System.Data.SqlClient" />
.....
</connectionStrings>
If that does not work, try a remote debugging session:
How to: Set Up Remote Debugging
Try adding </clear> under your connection strings in web.config
connectionStrings>
<clear />
<add name="SQL" connectionString="server=.\SQL2008;database=xxxxxx;uid=xxxxxx;pwd=xxxxxxxxxx;" providerName="System.Data.SqlClient" />
.....
</connectionStrings>

How to keep clean ASP.NET web.config file for a new MVC3/Azure project using only <system.webServer>?

I just created a new project in MVC3 using EF4 code first deployed on Windows Azure.
I want to keep my "web.config" file as clean as possible because it's a little complicated to understand all tags it contains.
I notice two sections: <system.web> and <system.webServer>
The first is for IIS6 and the second for IIS7+
I do not need backward compatibility so want to delete the first.
I converted a good part of the first into the second, but I cannot find how to convert these sections:
<system.web>
<authentication mode="None" />
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Helpers, Version=2.0.0.0, Culture=neutral />
<add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral />
<add assembly="System.Web.WebPages, Version=2.0.0.0, Culture=neutral />
<add assembly="Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral />
</assemblies>
</compilation>
<pages validateRequest="false">
<namespaces>
<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.WebPages" />
</namespaces>
</pages>
</system.web>
How to do this so that I can delete the deprecated <system.web>?
Not all of the elements are deprecated. The two most important sections are /system.web/httpHandlers which has moved to /system.webServer/handlers and /system.web/httpModules which is now /system.webServer/modules. You shouldn't need to touch the above configuration any further as the elements within are still part of the system.web element even in IIS7. Have you tried running your site after your changes?

http error 500.19 - Internal server error

I am trying to get an application (that I didn't develop) running on a windows 2008 r2 64-bit server running IIS 7.5.
I am getting the above stated error - here are more details -
The requested page cannot be accessed because the related configuration data for the page is invalid
Error Code 0x8007007e
I know that the server can access the web.config, because if I make changes to it, the error code changes.
I also know that it is a correct web.config, because it is running successfully on a different server with the same file.
Does anyone have any idea what might be causing this. The error message I am getting really doesn't tell me anything.
I have tried using FailedRequestTracing, but either I don't know how to read those logs or there is no more information there. There are also no errors in the event logs on the server.
Where else can I look to get a better idea of what is happening?
Thanks for any thoughts....
EDIT - Here is the web.config. As I said earlier, it is strange that it is working on another server. I checked to ensure are referenced assemblies are available (as according to the page here, it appear that may be the problem) in the gac.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appSettings>
<add key="ChartImageHandler" value="storage=file;timeout=20;dir=c:\temp\;deleteAfterServicing=false;" />
</appSettings>
<connectionStrings>
<!-- removed for this post -->
</connectionStrings>
<system.data>
<DbProviderFactories>
<!--<add name="IBM Informix .NET Data Provider 3.0.0" invariant="IBM.Data.Informix.3.0.0" description="IBM Informix Data Provider 3.0.0 for .NET Framework 2.0" type="IBM.Data.Informix.IfxFactory, IBM.Data.Informix.3.0.0, Version=3.0.0.2, Culture=neutral, PublicKeyToken=7c307b91aa13d208"/>-->
</DbProviderFactories>
</system.data>
<system.web>
<httpRuntime maxRequestLength="8192" />
<customErrors mode="Off" />
<sessionState timeout="360" />
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
<namespaces>
<clear />
</namespaces>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting" assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</controls>
</pages>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /></assemblies></compilation>
<httpHandlers>
<add path="ChartImg.axd" verb="GET,HEAD" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false" />
</httpHandlers>
</system.web>
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="5000000" />
</webServices>
</scripting>
</system.web.extensions>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="ChartImageHandler" />
<add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</handlers>
<defaultDocument>
<files>
<add value="index.aspx" />
</files>
</defaultDocument>
<tracing>
<traceFailedRequests>
<add path="*.aspx">
<traceAreas>
<add provider="ASP" verbosity="Verbose" />
<add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Verbose" />
<add provider="ISAPI Extension" verbosity="Verbose" />
<add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,FastCGI" verbosity="Verbose" />
</traceAreas>
<failureDefinitions timeTaken="00:00:00" statusCodes="400-600" />
</add>
</traceFailedRequests>
</tracing>
</system.webServer>
</configuration>
It's a bit cheaty, but Microsoft has a page specifically about this problem ... and myriad suggestions for fixing it. Have you gone through it yet?
http://support.microsoft.com/kb/942055
Try this http://windowslivehelp.com/thread.aspx?threadid=3dd85141-a45d-44d9-a94c-3c7d13cfcd5c
I was able to get past this error by disabling compression that is applied by having wsus on the server.
See details here.
Thanks for everyone's help.

Resources