ASP.NET 2.0 Web Config (vb to c#)

S

sck10

Hello,

I am migrating a small site from vb to c# (learning process). I created a
default page with code behind. I copied a web.config file and just changed
the reference from vb to c#. In my vb application, I removed the "using
System" references because I have them in my web.config file. However, when
I removed the "using System" references in my c# page, I got the following
error: The type or namespace name 'EventArgs' could not be found (are you
missing a using directive or an assembly reference?

My question is what is the assembly reference for c#?

Thanks, sck10


c# references that were removed from the code behind page
------------------------------------------------------------
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


New Web.config page using c#
---------------------------------
<compilation defaultLanguage="c#" debug="true">
<assemblies>
<add assembly="System.DirectoryServices, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=B03F5F7F11D50A3A"/></assemblies>
</compilation>

<pages>
<namespaces>
<clear />
<add namespace="System" />
<add namespace="System.Collections" />
<add namespace="System.Collections.Specialized" />
<add namespace="System.Configuration" />
<add namespace="System.Data" />
<add namespace="System.Data.OleDb" />
<add namespace="System.IO" />
<add namespace="System.Text" />
<add namespace="System.Text.RegularExpressions" />
<add namespace="System.Web" />
<add namespace="System.Web.Caching" />
<add namespace="System.Net.Mail" />
<add namespace="System.Web.SessionState" />
<add namespace="System.Web.Security" />
<add namespace="System.Web.Profile" />
<add namespace="System.Web.UI" />
<add namespace="System.Web.UI.WebControls" />
<add namespace="System.Web.UI.WebControls.WebParts" />
<add namespace="System.Web.UI.HtmlControls" />
</namespaces>
</pages>
 
W

Walter Wang [MSFT]

Hi,

Thank you for your post.

This is indeed a very good question. I've reproduced the issue you're
experiencing.

From the MSDN Library:
=====
#namespaces Element for pages (ASP.NET Settings Schema)
http://msdn2.microsoft.com/en-us/library/ms164642.aspx

The namespaces element defines a collection of import directives to use
during assembly pre-compilation. This attribute corresponds to the @ Import
directive on an ASP.NET page. The @ Import directive allows you to specify
namespaces that are automatically imported into all pages of an application.
=====

Based on my understanding, this should only works for the ASPX pages
themselves, not the code behind partial class code, where you still have to
declare the namespaces explicitly. Essentially the ASP.NET page compiler
automatically injects these namespace declarations into the generated ASPX
class code.

However, from your description and my test using VB.NET, the imported
namespaces in web.config are also used in VB.NET code-behind class. I think
this is one of many differences between VB.NET and C# page compiler for
ASP.NET 2.0.

For now, you will have to use explicit using of namespaces in C#
code-behind class.

Hope this helps. Please feel free to post here if anything is unclear.



Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
W

Walter Wang [MSFT]

Appreciate your update and response.

If you have any other questions or concerns, please do not hesitate to
contact us. It is always our pleasure to be of assistance.

Have a nice day!

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top