.NET Framework 2.0 - first impressions

Today Microsoft released .NET Framework 2.0. I already managed to convert this site and homokaasu.org to run on it. I didn't yet install it on the server, though, but got it running on my home computer. It was quite easy, but not as fluent as it could have been. Here are the first problems I've encountered and their solutions.

Extension mapping with build providers

Definition for extension mappings seems to have changed. Fw 2.0 introduces a design called BuildProvider, which take care of compiling the source code for different purposes on a web site. There are build providers for normal pages, user controls, master pages, web services and so on (check the full list at the machine.config file).

In addition to IIS mapping and http handler definition, non-standard extensions must be defined in a third place: inside the compilation tag of the web.config file, like this.

<compilation debug="true" batch="true" batchTimeout="120">
  <buildProviders>
    <add extension=".gas" type="System.Web.Compilation.PageBuildProvider" />
  </buildProviders>
</compilation>

The System.Web.Compilation.PageBuildProvider is the default build provider for aspx files and is used here. In this case, gas files are treated exactly as aspx files.

Creating IHttpHandler instances

For some reason, when creating the pages on the fly for wildcard extensions in this blog application as I previously described, the PageParser class used to create the IHttpHandlers (Page objects) fails with a null reference exception. I tracked the problem with Reflector and it seems that this depends on a new HostingEnvironment class, which is null at this point of the page lifecycle in 2.0.

This could have become nasty, but luckily the solution is quite easy. I noticed that the BuildManager has a method called CreateInstanceFromVirtualPath which appears to be very promising. It has two parameters: string virtualpath and Type requiredBaseType, which sound good, but it returns an Object. I made a guess and replaced...

return PageParser.GetCompiledPageInstance("/scaffold.aspx", Context.Server.MapPath("/scaffold.aspx"), Context);

...with...

return BuildManager.CreateInstanceFromVirtualPath("/scaffold.aspx", typeof(Page)) as IHttpHandler;

...in my PageHandlerFactory class definition and w00t! We get signal!

A bit sloppy though

Technically the framework seems to work well, but the adjoining information (documentation, error messages, comments in config files) is somewhat slipshod. For example, when I heeded this error message...

There is no build provider registered for the extension '.gas'. You can register one in the <compilation><buildProviders> section in machine.config or web.config. Make sure is[sic] has a BuildProviderAppliesToAttribute attribute which includes the value 'Web' or 'All'

...by adding the definition and made very sure the appliesTo attribute was included, I was greeted with the following:

Unrecognized attribute 'appliesTo'. Note that attribute names are case-sensitive.

The end result was that the attribute wasn't needed, in fact, mustn't be there, although the error message and documentation told exactly the opposite.

The SDK documentation has dead links (and a very bland look).

Other noteworthy things

Aww... namespace attribute of @register directive is now case sensitive. Too bad for the sloppy developers who didn't notice the case inconsistency in namespaces and references before this...

MySql Connector/Net works (with MySql 5). Nant works but requires some directory name changes in it's config file. SharpDevelop works and recognizes the new framework automatically.

My multiuser game/chat server works perfectly. Unlike with the web apps, the complier didn't warn about anything obsolete. The server uses threading, xml and tcp-level network objects very extensively so it seems it is the web part of the framework that has experienced the biggest changes.

web.config can be at least partially edited using a new UI in IIS manager.

The only compilation errors I got were from Math.Floor and Math.Ceiling. The compiler could not decide whether the input parameter was a decimal or a double with lines like this: Math.Floor(a/3-1); in which a is an integer so it seems the methods are now more overloaded or the type handling of numbers has changes since this was fixed with return Math.Floor(a/3m-1m); (in which the m in 1m denotes a decimal value).

More experiences with .NET Framework 2.0 definitely coming up at some point - these were the results of the first hour of playing around or so.

Categories: Programming, Web
Posted by Matias at 07.11.2005 21:33 (2 years ago)

6 comments

From Willy Kreim () at 23.04.2006 02:55 (2 years ago)

You are against the copyright laws, and you use Microsoft's closed-source .net that locks people into Windows (no, don't even mention Mono, the .Net wannabes that are always chasing the 'moving target' Microsoft, and who need to call win32 emulator to run winforms....)

I think you need to re-examine your belief system. How about learning Java, and do cross-platform apps the right way?. And yes, there are open source java versions available....


From Matias () at 24.04.2006 20:43 (2 years ago)

I am not against copyright law - only some of the recent extensions and developments.

Sun screwed up the whole vendor lock-in attempt and only then "opened" up the environment - not that it has much to fear from .NET. Sun intends to do with Java exactly the same as what Microsoft with .NET (hint: the purposes are fiscal). Thus, disregarding .NET yet accepting Java based on these idealistic issues is a fallacy (as opposed to the case between, say, xhtml and html with Microsoft extensions).

GPL licensing, which incidentally uses the copyright law to a great extent to achieve it's purpose, is a vastly more efficient tool to create free software - and as a by-product, effect politically - than the selection of the programming framework.


From Fduch at 27.05.2007 09:32 (1 year ago)

YUO'RE THE BEST!
It was coding horror for me for the last 3 days. Interenet, Reflector, digging into source code generated by ASP.Net. NOTHING!
(I needed to get HTML from a page that had MasterPage. The problem was I couldn't "put" the page to it's master page's contentPlaceholder, so when I used RenderControl on my page, only masterpage was rendered)
No more pain...


From Buy Cialis () at 28.02.2008 13:26 (4 months ago)

Cialis Online


From Viagra () at 28.02.2008 16:18 (4 months ago)

http://www.pressbox.co.uk/detailed/Health/Humourous_Viagra_tutorial_and_the_Viagra_buying_process_38904.html


From PromoPharmacy () at 07.06.2008 00:03 (4 weeks ago)

http://medmaple.com http://1sw.info http://promopharmacy.com

Post a new comment

Will be displayed within an image file, undecipherable to address harvesters.
Verification code
Please enter the three characters you see at the right side of this form. This prevents automated submissions.


content licensed under Creative Commons - Valid XHTML 1.1