December 2003 - Posts

Resources & the SR type in Whidbey

Note: this entry has moved.

Sometime ago I posted this and this about how the .NET framework itself and lots of Microsoft applications use the same approach for handling resource localization.

 

Both posts were commented by Sebastien Lambla and Daniel Cazzulino pointing out a few “issues” found in the Everett implementation of the SR type. At that moment, although I knew these “issues” were already fixed in the Whidbey bits I was testing, I wasn’t allowed to post about it until after the PDC03 because of NDA matters (although something may have slipped through a comment…).

 

But the big news is not about minor fixes… Let’s see what Whidbey brings so you don’t have any excuses now to not follow the SR type approach:

 

Great News #1: An updated resgen.exe

 

The days of coding your own SR type are gone. The resgen.exe utility was updated to support the generation of a strongly typed resource class (/str option) through the use of CodeDOM. This means that you can feed it a .resx file with the following:

 

<data name="NotEnoughMemory">

   <value>There is not enough memory to complete the requested operation.</value>

</data>

<data name="FileNotFound">

   <value>The specified file was not found.</value>

</data>

 

And you will get back a class definition like this:

 

public sealed class RssControl {

       

        private static System.Resources.ResourceManager _resMgr;

       

        public static System.Resources.ResourceManager ResourceManager {

            get {

                if ((_resMgr == null)) {

                    System.Resources.ResourceManager temp = new System.Resources.ResourceManager(typeof(ControlA));

                    System.Threading.Thread.MemoryBarrier();

                    _resMgr = temp;

                }

                return _resMgr;

            }

        }

       

        public static string FileNotFound {

            get {

                return ResourceManager.GetString("FileNotFound");

            }

        }

       

        public static string NotEnoughMemory {

            get {

                return ResourceManager.GetString("NotEnoughMemory");

            }

        }

    }

 

Then you could use it from your code like this:

 

    throw new Exception (RssControl.FileNotFound);

 

This sounds pretty cool but you still have some chores to perform by hand: run the command line utility resgen.exe, add the generated code file to your project, compile it and repeat this process every time the .resx file is modified.

 

Great News #2: Whidbey can do the work for you

 

For all lazy developers out there: good news is you don’t have to perform the above mentioned tasks in order to get your strongly typed resource class. You only drop your .resx file into the \Code folder and you’re ready to go. Whidbey will generate the resource class for you plus something definitively cool: VS.NET will automatically support intellisense for it. Want to modify the existing .resx? Just go ahead, save it, and the class (and intellisense support) will be updated accordingly. I believe this is as lazy as it can get.

 

What’s the magic behind all this?

 

Build Providers. You can now (in Whidbey, that’s it) participate in the build process of your application. You code a type that implements IBuildProvider and you register it in web/machine.config against the file extension you’re interested in handling (i.e.: System.Web.Compilation.ResXBuildProvider is the one in charge of .resx files). I promise I’ll posting more on build providers in the next days.

 

Lastly, just be aware that because of a few bugs in the current PDC03 build you may not get a totally friendly experience, i.e. you may notice that your app doesn’t automatically pick up changes made to files (.resx or any other type) located in the \Code folder thus requiring an additional application restart until that happen. I found about this the hard way :-( but thanks to a quickly follow up with the ASP.NET team this was traced down and should be already fixed.

Posted by vga with 7 comment(s)
Filed under:

Will the monkey ever catch up?

Note: this entry has moved.

Disclaimer (as if I need it): Although the following may sound like a rant, it is *not* a rant.

A few weeks ago I heard that Mono’s ASP.NET implementation is considered feature complete, which is great news. But Microsoft’s ASP.NET implementation is out since Feb. 2002, which means the ASP.NET team is working on v2.0 since -approximately- two years now. This looks like a considerable gap to me. I mean… while coding M1 of Mono’s ASP.NET Whidbey has just started, Microsoft is about to publicly launch Whidbey first beta; can you see the gap now?

While I was writing an article about ASP.NET Whidbey’s WebResource feature I decided to take a quick look at Mono’s Whidbey code to see how they were implementing this feature and possibly comment about it in the article. Nothing ever made into it because there was only a skeleton AssemblyResourceLoader.cs file with an ultrasimple implementation that wasn’t worth mentioning (it was missing key features like caching, security, ect). This, by the way, is totally understandable as Mono work on Whidbey has just started but I’m citing this just as practical example that a (considerable) gap exists.

To get an idea of when the Mono team plans to release an ASP.NET Whidbey implementation you can look at their roadmap. Scrolling down to title “Mono 1.2” you can read things like “…ASP.NET 2.0 improvements…” and “…This release will by default provide .NET 1.2 APIs...”. It is pretty clear by now that the next Mono version (v1.2) will try to provide the same feature set as Microsoft’s Whidbey (currently named version 1.2 and probably renamed to version 2.0).

No very big surprises up to here. When this Mono v1.2 will be available? The roadmap says “…Release target: Q4/2004…”. Ex-cu-se me?!, do you mean the fourth quarter of 2004?!, one year or less from now?! Wow… now that’s just sounds like an impossible goal. Want to bet?

And lastly… why in the world isn’t the Mono Official Website running on Mono’s ASP.NET? Is it just that they don’t like to eat their own dog food?

 

Posted by vga with 6 comment(s)
Filed under:

The new WebResource handler

Note: this entry has moved.

No one was talking about this new ASP.NET 2.0 feature until Jesse posted this today (actually yesterday) and then Nikhil replied back.

Having spent some time looking at the internals of the AssemblyResourceLoader type (the type that implements WebResource’s functionality) the reason why I haven’t posted about it before is because I’m waiting for my article (title is *not* final) “Handling client files in ASP.NET Whidbey” (where I detail WebResource internals and develop a custom control that uses it) to show up at MSDN, but now that the ball has started rolling I just can’t remain in silence :-)

While I don’t fully agree with Jesse about the actual problems of using WebResourceAttribute I do have my own concerns, the main one based on the fact that a malicious user can fake a WebResource URL and cause any well-known GAC assembly to be loaded up by your application; not really nice ugh?. I’m confident the current security scheme will suffer some changes down the road.

Also, if you are intrigued (and I’m sure you are) about the example given at the end of Nikhil’s post and you’re trying to make it work using the PDC bits you may stop smashing your head against the monitor :-) Because of a minor bug (detailed in my article) in the implementation of this substitution feature you need to make sure the size of the embedded resource help.htm is larger than 1024 bytes by filling it with blank spaces or your favorite dummy character.

In short, I definitively believe this is a really cool feature that will greatly simplify deployment of client files.

Posted by vga with 3 comment(s)
Filed under:
More Posts