N
Natan
Juan said:Natan,
Could you let me know how you determined that
Really, I don't remember. Probably i just figured out. But it's just how
asp.net works. It parses the ASPX page and creates a class.
Where did you find the list of Imports statements you quoted ? ....
I did that and got this list of compiled page resources
in the "Complete Compilation Source" :
System.EnterpriseServices.dll
acme.dll
global.asaxxi3ltqav.dll
System.Web.Services.dll
System.dll
System.Drawing.dll
System.Web.dll
System.Data.dll
mscorlib.dll
System.Web.Mobile.dll
System.Xml.dll
i8fuexe.dll
i8fuexe.0.cs
i8fuexe.1.cs
Close! Very close
There are two links in the error page. You probably opened the first,
and those are the assemblies your page is linked against. In case you
don't find it, run some aspx files in your IIS, then take a look at your
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files
ASP.NET should keep cache of compiled pages in that directory. (you can
find this dir in the end of the compilation line you got this
assemblies). Enter any application folder, then there are some folders
with random names. Open them, you will end up in a directory with lots
of files, some of them are .CS.
Open any CS, you will see that it is the class ASP.NET parser generates
for every ASPX page. There are some .cmdline that are the command line
used to compile the class. After compiling the page, asp.net uses the
compiled assembly to show the page. (even though you compiled your
webapp with code behind, aspx pages are still compilled individually
when they run, extending the base class)
See, there is a difference in linking libraries and importing
namespaces. The reason you didn't see difference in the reference list
is because System.Diagnostic namespace is half in mscorlib.dll and half
in System.dll, that are already included in the list of references.
Namespaces do not map to assemblies directly. e.g. most of "System"
namespace is in mscorlib.dll, not in System.dll. All the namespaces in
..NET BCL are included in something like 8 DLLs.
using directive only tell the compiler what namespaces to look for
types, linking libraries tell in what assemblies he should look for
namespaces.
@ Import directive is just a way to include another "using" in the
generated class, because every "script runat='server' block is put
inside the page class where you can't insert any using directive. e.g.,
if you have an @Import directive to a namespace, but the assembly you
are linking to is neither in bin nor in GAC, the compiler will raise an
error that it cannot load the namespace.
To explain my point, I must tell you why it is important to me to
automatically import namespaces in aspx files. I prefer to work with
"script runat='server'" and not code behind because:
1. VS.NET html editor sucks in a way i can't even describe it
2. VS.NET is against XHTML
3. VS.NET and most of WebControls are against CSS and "tableless"
standards and principles
4. It is much easier to work with code and html in the same page. I can
control how things are done and it's much easier than old asp (in
vs.net, everything must be done twice with code behind and even though
it generates the code, you must use the designer to create everything,
what is less productive if you know html and know what you are doing)
5. I don't have to use most of WebControls since HtmlControls work
perfectly fine and are much better to create cross browser applications.
You will notice 70% of webcontrols were created to make vs.net work in
design time, but they are not needed at all.
6. I don't have to worry about design time support. I worked with html
my entire life and it is much easier to write
<div id='div' runat='server'></div> than drag and dropping aspanels
that render divs anyway.
7. I don't have to deal with front page extensions, my directory tree is
always clean and have only what it needs, no need to export to another
directory.
So, the fact is that i hardly use code behind. I like my UltraEdit or
dreamweaver for pages, and keep VS to create the libraries. That's why I
need to <%@ Import %> one or two namespaces in my class. At least the
business logic and entities namespace must be available to pages since
they call methods to databind and other stuff. All the heavy logic are
stored in dlls, so i don't need to worry about people looking at my code.
Well... back to the subject.
I attached to this post the output generated by asp.net parser, cached
in Temporary ASP.NET Files, and the command line used to compile, so if
you don't find it, here is your reference.
Note the "public class bla_aspx : System.Web.UI.Page" because the page
is named "bla.aspx", and the "script runat='server'" in the middle of
the class, where the parses puts it. If you use code behind, what
happens is that this class uses your class as base class, not Page.
I suggest you to put some html, some runat='server' controls and see
what is the output in the class. It's good to understand how it really
works.
If I did *not* understand what you said, please detail the method(s)
you used to determine which dll's are included in the compiled aspx page,
and how/when/where another namespace, added via <%@ Import Namespace
="Bla.Bla" %>
to the page, is added to the compiled list of resources for that page.
This will make your position a bit easier to understand.
Please take the time to document this, as I have done.
Don't take offense. Just prove your point.
This is extremely interesting, and I'd like to know
if you are actually right, because it would certainly
change the way I've understood, up until now,
the .NET Framework and ASP.NET's inner workings.
I'm not an MVP... but this is just how it works. take a tour in
system.web.dll, in System.Web.Compilation through ildasm and you will
see some classes that does the parsing and compiling. probably there is
something in MSDN about this stuff.
I hope it helps to prove my point.
You can send me an email if you want. Just take the "-list" part off my
email.
[]'s
//------------------------------------------------------------------------------
// <autogenerated>
// This code was generated by a tool.
// Runtime Version: 1.1.4322.2032
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </autogenerated>
//------------------------------------------------------------------------------
namespace ASP {
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Configuration;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Caching;
using System.Web.SessionState;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
[System.Runtime.CompilerServices.CompilerGlobalScopeAttribute()]
public class bla_aspx : System.Web.UI.Page, System.Web.SessionState.IRequiresSessionState {
private static int __autoHandlers;
private static bool __initialized = false;
private static System.Collections.ArrayList __fileDependencies;
#line 2 "D:\Root\bla.aspx"
void Page_Load(object sender, EventArgs e)
{
bla
}
#line default
#line hidden
public bla_aspx() {
System.Collections.ArrayList dependencies;
if ((ASP.bla_aspx.__initialized == false)) {
dependencies = new System.Collections.ArrayList();
dependencies.Add("D:\\Root\\bla.aspx");
ASP.bla_aspx.__fileDependencies = dependencies;
ASP.bla_aspx.__initialized = true;
}
this.Server.ScriptTimeout = 30000000;
}
protected override int AutoHandlers {
get {
return ASP.bla_aspx.__autoHandlers;
}
set {
ASP.bla_aspx.__autoHandlers = value;
}
}
protected System.Web.HttpApplication ApplicationInstance {
get {
return ((System.Web.HttpApplication)(this.Context.ApplicationInstance));
}
}
public override string TemplateSourceDirectory {
get {
return "/";
}
}
private void __BuildControlTree(System.Web.UI.Control __ctrl) {
}
protected override void FrameworkInitialize() {
this.__BuildControlTree(this);
this.FileDependencies = ASP.bla_aspx.__fileDependencies;
this.EnableViewStateMac = true;
this.Request.ValidateInput();
}
public override int GetTypeHashCode() {
return 5381;
}
}
}
/t:library /utf8output /R:"c:\windows\microsoft.net\framework\v1.1.4322\mscorlib.dll" /R:"c:\windows\assembly\gac\system.enterpriseservices\1.0.5000.0__b03f5f7f11d50a3a\system.enterpriseservices.dll" /R:"c:\windows\microsoft.net\framework\v1.1.4322\temporary asp.net files\root\78f3146f\a4b7e5c9\assembly\dl2\d7d24fd5\102994f1_06a6c401\chat2.dll" /R:"c:\windows\assembly\gac\system.data\1.0.5000.0__b77a5c561934e089\system.data.dll" /R:"c:\windows\assembly\gac\system.web.mobile\1.0.5000.0__b03f5f7f11d50a3a\system.web.mobile.dll" /R:"c:\windows\assembly\gac\system.drawing\1.0.5000.0__b03f5f7f11d50a3a\system.drawing.dll" /R:"c:\windows\assembly\gac\system.xml\1.0.5000.0__b77a5c561934e089\system.xml.dll" /R:"c:\windows\assembly\gac\system.web.services\1.0.5000.0__b03f5f7f11d50a3a\system.web.services.dll" /R:"c:\windows\assembly\gac\system\1.0.5000.0__b77a5c561934e089\system.dll" /R:"c:\windows\assembly\gac\system.web\1.0.5000.0__b03f5f7f11d50a3a\system.web.dll" /out:"C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\root\78f3146f\a4b7e5c9\djudr-s0.dll" /DEBUG /debug+ /optimize- /warnaserror /w:1 "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\root\78f3146f\a4b7e5c9\djudr-s0.0.cs"