By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,784 Members | 3,274 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,784 IT Pros & Developers. It's quick & easy.

Imported namespaces

P: n/a
What is the difference between importing a namespace at the:

1. Project level
2. web.config level
3. Page level

What are the requirements/benefits of each?

If I import a namespace such as System.Collections at the Project level and
the user calls a page that does not use that namespace, is that wasting
resources? Am I better off specifying namespaces for individual pages only?

When exactly are the namespaces in web.config used? Clearly if I do not
include a namespace for a page (or at the Project level) I will get a
compilation error. But why would a namespace ever have to be imported in
web.config? How is that used?
Aug 20 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Hi MCM,

As for the "project level" importing, do you mean the "Imported namespaces"
for visual basic projects? This is one facility provided by VB.NET project
so that you do not need to explcitly import those namespaces in each code
file. this just help add namespace import , but it still rely on those
assemblies you have "referenced", this is the ultimate things that will
affect your application's generated binary code.
For ASP.NET, the <assembliessection in web.config is not simply importing
namespace, but reference assemblies. For example, the following section
means the four assemblies will be automatically referenced when each of the
ASP.NET aspx page get dynamic compiled(ASP.NET use dynamic compilation)

============
<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.Data.DataSetExtensions, Version=3.5.0.0,
Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0,
Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
========================

Yes, if you add two much useless assemblies here, it will impact your page
assemblies(generated dynamically or via precompilation)'s size. And you can
manually customize the list to minimize it(If you're sure how many ones are
exact necessary).

For page level Import, it is just like code file level import. It make the
certain namespace visible in that page's aspx template scope.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/...tance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: =?Utf-8?B?TUNN?= <MC*@newsgroup.nospam>
Subject: Imported namespaces
Date: Wed, 20 Aug 2008 14:59:01 -0700

What is the difference between importing a namespace at the:

1. Project level
2. web.config level
3. Page level

What are the requirements/benefits of each?

If I import a namespace such as System.Collections at the Project level
and
>the user calls a page that does not use that namespace, is that wasting
resources? Am I better off specifying namespaces for individual pages only?

When exactly are the namespaces in web.config used? Clearly if I do not
include a namespace for a page (or at the Project level) I will get a
compilation error. But why would a namespace ever have to be imported in
web.config? How is that used?
Aug 21 '08 #2

P: n/a
As for the "project level" importing, do you mean the "Imported namespaces"
for visual basic projects?
Yes.

This is one facility provided by VB.NET project
so that you do not need to explcitly import those namespaces in each code
file.
But whch is better? Import at the project level or import at the page level?
If I have 10 pages and only 3 pages use a certain namespace, will I be
slowing down the other 7 pages by importing at the project level?

this just help add namespace import , but it still rely on those
assemblies you have "referenced", this is the ultimate things that will
affect your application's generated binary code.
Referenced at the project level or in web.config? They are different -
should I keep them syncronized?

For ASP.NET, the <assembliessection in web.config is not simply importing
namespace, but reference assemblies. For example, the following section
means the four assemblies will be automatically referenced when each of the
ASP.NET aspx page get dynamic compiled(ASP.NET use dynamic compilation)

============
<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.Data.DataSetExtensions, Version=3.5.0.0,
Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0,
Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
========================

Yes, if you add two much useless assemblies here, it will impact your page
assemblies(generated dynamically or via precompilation)'s size. And you can
manually customize the list to minimize it(If you're sure how many ones are
exact necessary).
Same question as above... What is the difference between assemblies
referenced at the project level and assemblies referenced in web.config?

Aug 21 '08 #3

P: n/a
Thanks for your reply MCM,

For your further questions, here is the answer inline:

But whch is better? Import at the project level or import at the page
level?
If I have 10 pages and only 3 pages use a certain namespace, will I be
slowing down the other 7 pages by importing at the project level?
===============================================
For your code behind page class/code, I suggest you use project level
imports since that can help you save the work to declare them in every code
file. However, sometimes (for ASP.NET app), you will write server-side code
in aspx template, in such cases, I think you should always explicitly
import namespace in aspx page, otherwise, you'll need to reference class
via full namespace+classname. Importing namespace will not make page
running slowly, it just help the compiler find classes at compile time(even
for dynamic compilation, its impact is negligible). It won't add assembly
size either.
Referenced at the project level or in web.config? They are different -
should I keep them syncronized?
=================================
For ASP.NET 2.0/vs 2005/2008, there are two web project type(web site
project and web application project). Project Level reference are useful
for web applicaiton project while for web site project, it is
projectless(no much project setting like normal .net project). I suggest
you have a look at this two different project types first:

http://msdn.microsoft.com/en-us/libr...80(VS.80).aspx

http://www.google.com/search?hl=en&q...ication+projec
t

http://webproject.scottgu.com/
As for "web site project", I suggest you always use web.config's reference
list while for "web application project", you can simply use project level
reference. BTW, if you're using Visual studio IDE, you simply use "Add
Reference" menu to reference assemblies and visual studio IDE will help you
do it correctly(according to different project model).

Same question as above... What is the difference between assemblies
referenced at the project level and assemblies referenced in web.config?
============================================
Same as above, the difference is due to the different project type.
Generally, project level reference is used when the certain project build
and generate assemblies at design-time(when you build the project). However
for ASP.NET 2.0 application, it by default use a "web site project" model
which use dynamic compilation(do not generate assembly when you build
project at design-time). Thus, it is necessary to tell the application
which assemblies to reference when it perform dynamic compilation at
runtime(and the web.config assemblies list is used to tell the compiler for
dynamic compilation at runtime).

Some other reference about ASP.NET 2.0 compilation:

http://www.west-wind.com/presentatio...tCompilation.a
sp

http://odetocode.com/blogs/scott/arc...1/15/2464.aspx

Hope this also helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.


--------------------
>From: =?Utf-8?B?TUNN?= <MC*@newsgroup.nospam>
References: <D4**********************************@microsoft.co m>
<lV**************@TK2MSFTNGHUB02.phx.gbl>
>Subject: RE: Imported namespaces
Date: Thu, 21 Aug 2008 11:39:00 -0700
>
>As for the "project level" importing, do you mean the "Imported
namespaces"
>for visual basic projects?

Yes.

>This is one facility provided by VB.NET project
so that you do not need to explcitly import those namespaces in each
code
>file.

But whch is better? Import at the project level or import at the page
level?
>If I have 10 pages and only 3 pages use a certain namespace, will I be
slowing down the other 7 pages by importing at the project level?

>this just help add namespace import , but it still rely on those
assemblies you have "referenced", this is the ultimate things that will
affect your application's generated binary code.

Referenced at the project level or in web.config? They are different -
should I keep them syncronized?

>For ASP.NET, the <assembliessection in web.config is not simply
importing
>namespace, but reference assemblies. For example, the following section
means the four assemblies will be automatically referenced when each of
the
>ASP.NET aspx page get dynamic compiled(ASP.NET use dynamic compilation)

============
<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.Data.DataSetExtensions,
Version=3.5.0.0,
>Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0,
Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
========================

Yes, if you add two much useless assemblies here, it will impact your
page
>assemblies(generated dynamically or via precompilation)'s size. And you
can
>manually customize the list to minimize it(If you're sure how many ones
are
>exact necessary).

Same question as above... What is the difference between assemblies
referenced at the project level and assemblies referenced in web.config?

Aug 22 '08 #4

P: n/a
To be clear, you are telling me that if I am using Web Application Project, I
do NOT need to specify any reference assemblies in web.config at all. Is that
correct?
"Steven Cheng [MSFT]" wrote:
Thanks for your reply MCM,

For your further questions, here is the answer inline:

But whch is better? Import at the project level or import at the page
level?
If I have 10 pages and only 3 pages use a certain namespace, will I be
slowing down the other 7 pages by importing at the project level?
===============================================
For your code behind page class/code, I suggest you use project level
imports since that can help you save the work to declare them in every code
file. However, sometimes (for ASP.NET app), you will write server-side code
in aspx template, in such cases, I think you should always explicitly
import namespace in aspx page, otherwise, you'll need to reference class
via full namespace+classname. Importing namespace will not make page
running slowly, it just help the compiler find classes at compile time(even
for dynamic compilation, its impact is negligible). It won't add assembly
size either.
Referenced at the project level or in web.config? They are different -
should I keep them syncronized?
=================================
For ASP.NET 2.0/vs 2005/2008, there are two web project type(web site
project and web application project). Project Level reference are useful
for web applicaiton project while for web site project, it is
projectless(no much project setting like normal .net project). I suggest
you have a look at this two different project types first:

http://msdn.microsoft.com/en-us/libr...80(VS.80).aspx

http://www.google.com/search?hl=en&q...ication+projec
t

http://webproject.scottgu.com/
As for "web site project", I suggest you always use web.config's reference
list while for "web application project", you can simply use project level
reference. BTW, if you're using Visual studio IDE, you simply use "Add
Reference" menu to reference assemblies and visual studio IDE will help you
do it correctly(according to different project model).

Same question as above... What is the difference between assemblies
referenced at the project level and assemblies referenced in web.config?
============================================
Same as above, the difference is due to the different project type.
Generally, project level reference is used when the certain project build
and generate assemblies at design-time(when you build the project). However
for ASP.NET 2.0 application, it by default use a "web site project" model
which use dynamic compilation(do not generate assembly when you build
project at design-time). Thus, it is necessary to tell the application
which assemblies to reference when it perform dynamic compilation at
runtime(and the web.config assemblies list is used to tell the compiler for
dynamic compilation at runtime).

Some other reference about ASP.NET 2.0 compilation:

http://www.west-wind.com/presentatio...tCompilation.a
sp

http://odetocode.com/blogs/scott/arc...1/15/2464.aspx

Hope this also helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.


--------------------
From: =?Utf-8?B?TUNN?= <MC*@newsgroup.nospam>
References: <D4**********************************@microsoft.co m>
<lV**************@TK2MSFTNGHUB02.phx.gbl>
Subject: RE: Imported namespaces
Date: Thu, 21 Aug 2008 11:39:00 -0700
As for the "project level" importing, do you mean the "Imported
namespaces"
for visual basic projects?
Yes.

This is one facility provided by VB.NET project
so that you do not need to explcitly import those namespaces in each
code
file.
But whch is better? Import at the project level or import at the page
level?
If I have 10 pages and only 3 pages use a certain namespace, will I be
slowing down the other 7 pages by importing at the project level?

this just help add namespace import , but it still rely on those
assemblies you have "referenced", this is the ultimate things that will
affect your application's generated binary code.
Referenced at the project level or in web.config? They are different -
should I keep them syncronized?

For ASP.NET, the <assembliessection in web.config is not simply
importing
namespace, but reference assemblies. For example, the following section
means the four assemblies will be automatically referenced when each of
the
ASP.NET aspx page get dynamic compiled(ASP.NET use dynamic compilation)

============
<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.Data.DataSetExtensions,
Version=3.5.0.0,
Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0,
Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
========================

Yes, if you add two much useless assemblies here, it will impact your
page
assemblies(generated dynamically or via precompilation)'s size. And you
can
manually customize the list to minimize it(If you're sure how many ones
are
exact necessary).
Same question as above... What is the difference between assemblies
referenced at the project level and assemblies referenced in web.config?

Aug 22 '08 #5

P: n/a
Thanks for your reply MCM,

That's correct if you haven't use server-side code in aspx template such as

<script runat="server" language="C#" >
....code here....

</script>

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

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

--------------------
>Thread-Topic: Imported namespaces
thread-index: AckEKQcTLuDbAWDrTa2R60D57qP+gA==
Subject: RE: Imported namespaces
Date: Fri, 22 Aug 2008 00:31:01 -0700
>
To be clear, you are telling me that if I am using Web Application
Project, I
>do NOT need to specify any reference assemblies in web.config at all. Is
that
>correct?
"Steven Cheng [MSFT]" wrote:
>Thanks for your reply MCM,

For your further questions, here is the answer inline:

But whch is better? Import at the project level or import at the page
level?
If I have 10 pages and only 3 pages use a certain namespace, will I be
slowing down the other 7 pages by importing at the project level?
===============================================
For your code behind page class/code, I suggest you use project level
imports since that can help you save the work to declare them in every
code
>file. However, sometimes (for ASP.NET app), you will write server-side
code
>in aspx template, in such cases, I think you should always explicitly
import namespace in aspx page, otherwise, you'll need to reference class
via full namespace+classname. Importing namespace will not make page
running slowly, it just help the compiler find classes at compile
time(even
>for dynamic compilation, its impact is negligible). It won't add
assembly
>size either.
Aug 25 '08 #6

P: n/a
Hi MCM,

Do you have any further questions on this?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

--------------------
>From: st*****@online.microsoft.com (Steven Cheng [MSFT])
Organization: Microsoft
Date: Mon, 25 Aug 2008 02:54:45 GMT
Subject: RE: Imported namespaces
>Thanks for your reply MCM,

That's correct if you haven't use server-side code in aspx template such
as
>
<script runat="server" language="C#" >
...code here....

</script>

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

================================================= =
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

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

--------------------
>>Thread-Topic: Imported namespaces
thread-index: AckEKQcTLuDbAWDrTa2R60D57qP+gA==
Subject: RE: Imported namespaces
Date: Fri, 22 Aug 2008 00:31:01 -0700
>>
To be clear, you are telling me that if I am using Web Application
Project, I
>>do NOT need to specify any reference assemblies in web.config at all. Is
that
>>correct?

Aug 27 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.