Import Namespace System.Query - asp.net

I am trying to load Linq on my .Net 3.5 enabled web server by adding the following to my .aspx page:
<%# Import Namespace="System.Query" %>
However, this fails and tells me it cannot find the namespace.
The type or namespace name 'Query' does not exist in the namespace 'System'
I have also tried with no luck:
System.Data.Linq
System.Linq
System.Xml.Linq
I believe that .Net 3.5 is working because var hello = "Hello World" seems to work.
Can anyone help please?
PS: I just want to clarify that I don't use Visual Studio, I simply have a Text Editor and write my code directly into .aspx files.

I have version 2 selected in IIS and I
Well, surely that's your problem? Select 3.5.
Actually, here's the real info:
http://www.hanselman.com/blog/HowToSetAnIISApplicationOrAppPoolToUseASPNET35RatherThan20.aspx

What does the part of your web.config file look like?
Here's what it looks like for a brand new ASP.NET 3.5 project made with Visual Studio 2008:
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>

I found the answer :) I needed to add the following to my web.config:
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
Then I could add the following to my code:
<%# Import Namespace="System.Linq" %>
#Will,
Thanks for your help. I have accepted one of your answers :)

Make sure your project is set to target 3.5, and not 2.0.
As others have said, your 'var' test is a test of C#3 (i.e. VS2008), not the 3.5 framework.
If you set the project framework target settings properly, you should not expect to need to manually add dll references at this point.

The var hello stuff is compiler magic and will work without Linq.
Try adding a reference to System.Core
Sorry, I wasn't clear. I meant add System.Core to the web project's references, not to the page.
The Import on the page are basically just using statements, allowing you to skip the namespace on the page.

The csproj file might be missing the System.Core reference.
Look for a line in the csproj file like this:
<Reference Include="System" />
And add a line below it like this:
<Reference Include="System.Core" />

Related

Error : The entry 'asp:System.Web.UI:System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' has already been added

We are working on a web application and the target deployment includes Windows 2003 64-bit. When we run the application on the 64-bit OS, it gives the following error:
The entry 'asp:System.Web.UI:System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' has already been added
The web.config file includes the following:
<pages validateRequest="false" enableEventValidation="false" viewStateEncryptionMode="Never" theme="esl_theme">
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</controls>
</pages>
And if we remove the line <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>, it seems to work.
Can somebody help to understand the problem and take corrective action? The application does not compile on 32-bit OS without this.
Is this the root web.config from your application or from a subfolder?
Looks like your application inherits that reference from some parent web.config.
Could be from:
Root web.config
Machine's web.config
For your 64-bit problem, check if that assembly is compiled/built for 64-bit or not. Not worked much with 64-bit, but that must be the problem. Try referencing the 64-bit version.

upgrading from asp.net mvc 2.0 to 3.0 issues

after upgrade, all the pages see Models as Object.
I've upgraded using migration guide here
basically just copying some scripts, and re-mapping mvc assembly reference to 3.0
For some reason, all of my controls are now not seeing any properties on my models.
here is how i define the model type:
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<WebMVC.Models.WeatherModel>" %>
usage:
<%: Html.TextBox("DateFromText", Model.DateFrom.ToShortDateString())%>
i now get compile errors that "object" does not contain definition for AnyProperty.
UPDATE
thanks to SLax i fixed the object issue. Now getting the following error:
The type 'System.Data.Objects.DataClasses.ComplexObject' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
ok.. fixed this by adding assembly reference in web.config:
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
You will want to enter the following into the web.config file:
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
</assemblies>
</compilation>
You probably have references to System.Web.Mvc.dll version 2 in one of the two Web.config files.

Where are components (dll) references stored in ASP.NET?

I have dlls in bin directory. I can't see where they are referenced in either solution or web.config files. So where are the references stored ?
The answer depends on if your project is a Web Site or a Web Application. In a Web Site all the assemblies in the bin directory are automatically referenced. A Web Application has the project references that you are looking for.
When working on a previously developed ASP.NET "WebSite" project in VS2012, I figured out how to find them (and thus add/remove/update them).
Over in the Solution Explorer, right-click the name of the project (the project will have the wire-frame globe icon next to it)
Click "Property Pages" (NOT Properties Window). It will appear in its own separate (floating) window frame.
Now just left-click the item "References" at the top of the list to the left. That's it! You can now add, delete, and update any reference(s) associated with your WebSite project.
If web app project or MVC, right-click and select unload project. Then right click again and select edit . If you dig through the XML, you will find the collection of project references and other DLL references to MS or other assemblies.
If you actually have them referenced, they should be "stored" in the project files (*.csproj for C#, *.vbproj for Visual Basic).
In the case of an ASP.NET web site, the references are stored in the web.config file.
I've removed most of the assemly references, but one of my old web sites has things like this:
<compilation debug="true">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Web.Extensions.Design, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</assemblies>
</compilation>

Defining tagPrefixes in Web.config help

I am having a little bit of trouble getting my aspx pages to recognize my tagPrefixes.
I have the standard ASP ones defined...
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
Then I have my custom controls defined below that but I do not think I am defining them properly because sometimes the page does not see any controls in the current context other times they work like a champ...
<add tagPrefix="mri" namespace="Mri.Controls" assembly="Mri.Controls"/>
<add tagPrefix="mri" namespace="Mri.Controls.Inputs" assembly="Mri.Controls"/>
<add tagPrefix="mri" namespace="Mri.Controls.Inputs.DropDowns" assembly="Mri.Controls"/>
<add tagPrefix="mri" namespace="Mri.Controls.Inputs.Search" assembly="Mri.Controls"/>
I have one namespace "Mri.Controls" and inside of that namespace I have several sub-folders, "Inputs" -> "DropDowns" etc...
What am I doing wrong? Currently the regular ASP controls are giving me an error: The name "blahBlah" does not exist in the current context.
The sub-folders may or maynot become part of the namespace. By default, Visual Studio does include them when creating new classes but that can be removed in the class. If you moved the controls to the sub-folders, then the folder's name is likely not part of the namespace.
Also, make sure you are referencing your controls assembly or project within Visual Studio.
Do you not also need the tagName attribute e.g.
<add tagPrefix="mri" tagName="Search" namespace="Mri.Controls.Inputs.Search" assembly="Mri.Controls"/>
<mri:Search ID="Search" runat="server"/>

VS2008 targeting ASP.net 2.0: Project-level imports warning

I have a web app built against asp.net 2.0, but keep getting the following warning:
Namespace or type specified in the project-level Imports 'System.Xml.Linq' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.
I cannot find anywhere that actually Linq is actually referenced. I've even opened up the .vbproj in a text editor, and it's not hidden in there either.
Any ideas where this is set?
Open your web.config and remove the reference to Linq in there. You should need to delete these lines from under the "assemblies" section:
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
Have you checked in your web.config file?
You also get this error if you have an older version of .Net Framework.
Go To Project->Properties->Advanced Compile Options->Target framework(all configurations)
If it is set to .NET Framework 2.0, try changing it to 3.5.
That fixed it for me.

Resources