Fabrice's weblog

Tools and Source

News


Read sample chapters or buy LINQ in Action now!
Our LINQ book is also available on AMAZON

.NET jobs

Emplois .NET

The views expressed on this weblog are mine alone and do not necessarily reflect the views of my employer. The content of this weblog is independent from Microsoft or any other company. transatlantys hot news

Contact

Me

Others

Selected content

August 2004 - Posts

Enthusiasm and laziness
Thought for the holidays: Two things that drive us, software development addicts: enthusiasm and laziness....
How to turn off/disable the .NET JIT Debugging Dialog
Just quoting Scott Hanselman for this tip:

A day may come when you want to turn off the Debug dialog that appears when a .NET program has an unhandled exception.

Option 1: Registry key from Enabling JIT Debugging

For an application that includes managed code, the common language runtime will present a similar dialog to JIT-attach a debugger. The registry key that controls this option is called HKEY_LOCAL_MACHINE\Software\Microsoft\.NETFramework\DbgJITDebugLaunchSetting.

  • If value = 0, prompt the user by means of a message box. The choices are:
    • Continue. This results in a stack dump and process termination.
    • Attach a debugger. In this case, the runtime spawns the debugger listed in the DbgManagedDebugger registry key. If none, control is returned, and the process is terminated.
  • If value = 1, simply return control. This results in a stack dump, after which the process is terminated.  (No more dialog)
  • If value = 2, spawn the debugger listed in the DbgManagedDebugger registry key.

Option 2: If you want to disable the JIT debug dialog, but still want an error dialog:

Visual Studio.NET|Tools|Options|Debugging|Just-In-Time and deselect "Common Language Runtime" and now you’ll get an OK/Cancel dialog instead of the select a Debugger Dialog.  Note: The registry entry from Option 1 above will need to be 0 for the dialog to show up.

Thanks to Eric Deslauriers of Corillian QA for these tips!


This dialog can be useful in some cases (mainly in development), but annoying in most cases. But, what if I want to disable this dialog per application?
Need an ASP.NET hoster? - webhost4life review
When I started SharpToolbox.com, I needed to select a hosting solution. I chose webhost4life, and this year I renewed my account with them because I think they have very goods hosting plans and I'm happy with them.

Here are a the main advantages you get with webhost4life:
  • Price: I chose the $9.95/month plan (Update: now $11.95), and I consider it a bargain. (this means a one time payment of  $140 for a year, one time setup fee included)
  • Bandwidth: unlimited! Now, try to find something close from the other hosters for that price. And gigabytes fly by quickly... Unlimited bandwith is invaluable if you plan to share pictures, videos, or even software.
  • Domains: you can create as many sub-domains as you wish for free, and host multiple domains on one account for $15 a year per additional domain
  • SQL Server and MySQL databases
  • ASP.NET 1.0, 1.1, 2.0
  • Mail: POP and IMAP, SSL, SPAM protection, virus protection, 100 accounts by domain...
  • Configuration: a control panel let's you setup your hosting
  • They currently have a special offer that includes shared 128bit SSL and doubled space for the same price. For the $9.95 per month plan (Update: now $11.95), that means you get 300MB on disk + 300MB for SQL Server + 300MB for MySQL. Update: the new offer gives you from 1000MB to 3000MB of disk space and from 2000MB to 3000MB of SQL Server space!
Of course, you can see the details on their web site.
Everything is not perfect though, and I had to contact the tech support a couple of times to fix a few things. But the good news is that the tech support is efficient and fast enough. I've been happy with the free online tech support. My problems were fixed quickly.

I don't usually advertise for others, but here I have three reasons:
  • people reading these weblogs may need a hosting solution,
  • I'm satisfied with webhost4life and don't mind spreading the word to thank them for the service,
  • I get a commision if you sign up with them and tell them madgeek sent you, or use this link to sign up :-)
RoundedCorners and StyledPanel web controls

Scott Mitchell created a WebControl named RoundedCorners. Its goal is to simplify the creation of rounded boxes in your dynamic web pages.
Let's quote Scott:

Creating a box with rounded corners isn't terribly difficult, and there's a myriad of ways for creating such design elements. Virtually all of the techniques, though, require using Photoshop or some other graphics editing program to create rounded corners of the appropriate color. For graphics designers, creating rounded corners must be extremely boring, and they likely hold as much interest in creating rounded corners as veteran ASP.NET developers do in creating a connection to a database. Been there, done that - thousands of times. But for non-graphics designers (like yours truly), creating these rounded corners can be frustratingly slow and annoying, especially if you're like me, and the only graphics editing program you have is Microsoft Paint.

To overcome this loathsome activity, I decided to create a custom ASP.NET server control that would utilize the dynamic image-creation capabilities of GDI+ to create the corner images for me. The result is an ASP.NET Web control, which I call RoundedCorners, that you can drop on an ASP.NET Web page, set a few properties, and be presented with a nifty box with rounded corners, as shown on the right.

The most up to date version of this control allows you to drag and drop controls into the control, just like with the standard Panel.

I recommand this control in case you want a simple rounded box. In cases where you want something more fancy and don't mind playing with a picture editor, you can use my old StyledPanel WebControl.
The source code is quite simple (one class, a few lines), and the control supports composition too, which means you can drag&drop controls from VS' ToolBox into the control.

Something you may want to do is upgrade this control to a templated one. This would let you specify separate content for the header of the control, and for the body, for example. Creating templated web controls is explained by Scott Mitchell himself.

Reporting spam
How do you report spam? I use SpamCop, and you, what is your preferred response to spam?
Posted: Aug 16 2004, 06:05 PM by Fabrice Marguerie | with 2 comment(s)
Filed under:
Correct exception handling

If you look at this post by SantoshZ of the C# team, you'll see code like this:

Connection conn = null;
try
{
  conn = new Connection();
  conn.Open();
}
catch
{
  if (conn != null) conn.Close();
}

Well, this is quite a strange code snippet coming from the C# team, I must say! It demonstrates bad exception handling.
Here is what this code should look like in my opinion:

Connection conn = new Connection();
conn.Open();
try
{
  ...
}
finally
{
  conn.Close();
}

Why is that?

  1. There is no need to call Close() if Open() was not previously executed.
  2. There is no need to call Close() if Open() failed.
  3. You probably want "finally" instead of "catch"

Too often do I see code all in a big try...catch block.

BTW, don't forget to use the using statement, which greatly simplifies code in a lot of cases.

Watch Anders Hejlsberg talk about C#

Watch Anders giving an informal talk in front of a whiteboard. He talks about C# features, present and to come. You'll learn what he thinks about AOP, dynamic languages, mixins, closures, iterators, nullables, and so on.

"The C# compiler won't let me do it" - answer
Drew knows his thing. He was the one who gave the right explaination for my quiz. I just copy it here:

DictionaryEntry is a structure and you're foreaching which means the instance is coming from IDictionaryEnumerator.Current therefore assigning to only the local copy. This would be a nasty problem if people forgot about the semantics of value types vs. ref. types, so the C# compiler prevents you from doing this.

However, I agree with Eric Newton that the message from the compiler should be clearer! The current one is very confusing.

Now, if you want something even more confusing, you can try the following code:

IDictionary dictionary = new Hashtable();
dictionary["dummy"] = "dumb";
IEnumerator enumerator = dictionary.GetEnumerator();
while (enumerator.MoveNext())
{
  DictionaryEntry entry;

  entry = (DictionaryEntry) enumerator.Current;
  entry.Value = 0; // no compiler error, but "error" nonetheless
}
Console.WriteLine(dictionary["dummy"]);

This one compiles, but doesn't do what you'd expect at first. Guess what the output will be... So yes, the compiler message is useful (even if not easy to understand), but doesn't fire in all the cases...
"Comments on this post are closed"
I would like to apologize to readers: you'll notice that posting comments on most of the posts of this weblog is currently disabled. You'll see "Comments on this post are closed" instead. I'm sorry about this, and I can't change anything about it right now :-( This is a new site-wide (weblogs.asp.net) setting.
I hope we'll be able to reactivate the comments soon! I don't like that setting at all. I appreciate comments much, and I do not consider that previous posts as obsolete.
Scott, please do something! I you want this feature to be disabled too, please say it.
"The C# compiler won't let me do it"

In the spirit of language quizes, you can try to find why the following code does not compile:

DictionaryEntry entry1 = new DictionaryEntry();
entry1.Value = 0; // OK

IDictionary dictionary = new Hashtable();
dictionary["dummy"] = "dumb";
foreach (DictionaryEntry entry2 in dictionary)
  entry2.Value = 0; // NOT OK : "The left-hand side of an assignment must be a variable, property or indexer"

More Posts Next page »