Russ Lewis's little corner of the digiverse
 Friday, February 23, 2007
VS2005 & ASP.NET on Vista

OK, so you’ve worked-out how to run VS2005 as an administrator (create a new shortcut to devenv.exe, and check the box in the Compatibility tab).

 

But you can’t browse the IIS metabase and you still can’t create or debug an IIS application. Worse, you get a spurious error message about missing FrontPage server extensions! Well, you’re right in thinking you don’t need FP server extensions. The thing you really want is called the IIS6 compatibility layer for IIS7. It’s configured via Control Panel | Programs & Features | Turn Windows features on or off. Then drill down into IIS as shown here.

 

 

Whilst there, you should make sure that you have ASP.NET enabled

 

And, if you want F5 debugging (which, of course you do,) you need Windows security too

 

Now, use IIS manager to configure your Web application. It should use the ASP.NET 2 Application pool

 

And you will need to enable Windows authentication for your Web:

 

There’s an excellent post which explains what’s going-on here: http://mvolo.com/blogs/serverside/archive/2006/12/28/Fix-problems-with-Visual-Studio-F5-debugging-of-ASP.NET-applications-on-IIS7-Vista.aspx

 


2/23/2007 9:02:46 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  

 Tuesday, November 28, 2006
Microsoft Empower
This looks good...

Microsoft Empower is a two-year initiative that helps turn your idea for a software application into a reality. For just £260 + VAT, the programme gives you a full range of development resources, MSDN subscriptions, software licences and technical support - all the tools you need without the cost!

http://go.microsoft.com/?linkid=5834397

 

11/28/2006 6:01:04 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  

 Tuesday, September 26, 2006
HTTP Pipeline in ASP.NET 2.0
Here is a quick reference for the steps in HTTP pipeline in ASP.NET 2.0. 
Some of the steps are internal (cannot be subscribed by HTTP modules or GLOBAL.ASAX):
  1. Internal step to validate request.  Protects against malicious attacks exploiting path canonicalization
  2. Internal step to perform URL mapping (if the URL mapping feature is enabled)
  3. Fire BeginRequest event
  4. Fire AuthenticateRequest event
  5. Fire DefaultAuthentication internal event
  6. Fire PostAuthenticateRequest event
  7. Fire AuthorizeRequest event
  8. Fire PostAuthorizeRequest event
  9. Fire ResolveRequestCache event
  10. Fire PostResolveRequestCache event
  11. Internal step to determine the IHttpHandler to process the current request (this is when the page compilation takes place)
  12. Fire PostMapRequestHandler event
  13. Fire AcquireRequestState event
  14. Fire PostAcquireRequestState event
  15. Fire PreRequestHandlerExecute event
  16. Internal step to execute the IHttpHandler (call its ProcessRequest method) for the current request. The handler is determined at step #11
  17. Fire PostRequestHandlerExecute event
  18. Fire ReleaseRequestState event
  19. Fire PostReleaseRequestState event
  20. Internal step to perform response filtering (only if HttpResponse.Filter is installed)
  21. Fire UpdateRequestCache event
  22. Fire PostUpdateRequestCache event
  23. Fire EndRequest event.  This is the only event that is guaranteed to be fired for each request
I came across this in Dmitry Robsman's blog. He has several excellent code projects there, two of which I have incorporated into production websites today!
 
 

9/26/2006 10:24:03 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]  

We have evolved -- or were created -- as a small hairless creature in a world of big hairy problems and predators.
I loved this quote from one of the keynote's in Waterfall 2006 - a conference dedicated to re-welcoming the waterfall method of software development.
 
Read all about it at www.waterfall2006.com and if you're doing nothing else on April 1st, maybe even go along! 
 

9/26/2006 10:24:03 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]  

GoogleClient Demo
Here's an updated version of the Google & Amazon Client demo from my course 508.
 
 

Download: GoogleClient.zip


9/26/2006 10:24:03 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]  

localhost, (local) and . fail with SQL Server 2005
If you've moved your databases from SQL 2000 to 2005 and tried to run them using a connection string which includes something like:
server=(local); or
server=localhost; or
server=.;
 
you will have surely noticed that it falls over when your .NET application tries to access the database with a "server not found" error.
 
The cause is that Microsoft have shipped the developer versions of SQL 2005 with local access only. This means that
server=YOUR MACHINE NAME;
 
will work, but that's really bad practice, because the application will certainly fail when you copy it to the deployment server, having forgotten to amend the machine name.
 
The solution in fact is to do this :
Start | All Programs | MS SQL Server 2005 | Configuration Tools | SQL Surface Area Config.
Follow Surface Area Config for Services and Connections, then click Remote Connections in the left hand pane.
On the right, select Local and Remote Connections | using TCP/IP only
 
The old, familiar monikers will now work once again :-)
 

9/26/2006 10:24:03 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]  

 Friday, December 16, 2005
It is not possible to run two versions of ASP.NET in the same process
Here's a problem that many people may encounter as they start deploying ASP.NET version 2 applications on servers running which have existing ASP.NET v.1 sites.
 
The first symptom is a Web page or Web service that sometimes works but at other times refuses to start debugging or yields a "Server Application Unavailable" error page. This page suggests looking in the event log for further information. If you do, you are told in the log that "It is not possible to run two versions of ASP.NET in the same process ..."
 
Further observation may lead you to realize that you have a .NET v.1 and a .NET v.2 website running on the same IIS Web Site (usually 'Default Web Site'). What's happening is that whichever site is being hit first is imposing it's ASP.NET version on the process which IIS creates for 'Default Web Site'. When a subsequent request is then made to the other application, it cannot load its version of ASP.NET, a fact which it notes in the event log.
 
So, how do you create a separate process for a Web?
 
Open Internet Information Services manager,
For Windows Server 2003, create a new Application pool, accepting the default settings.
Next, locate your Web (under Default Web Site), right-click to select Properties, and
Windows Server 2003: assign the newly-created pool to the Application Pool property
Windows XP and 2000: Change the Application Protection property to High (Isolated)
 
Not too obvious, but now you know :-)

12/16/2005 11:43:25 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]  

 Thursday, December 08, 2005
How to install Application Center Test without installing Visual Studio
D:\ENGLISH\VS.NET2003\setup\setup.exe /NO BSLN CHECK
 

12/8/2005 5:04:04 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  

 Tuesday, November 29, 2005
 Thursday, September 08, 2005
Writing C# .NET stored procedures
The 2005 release of SQL Server will allow developers to write their stored procedures in a .NET language, does that mean the end of T-SQL as we know it? Not at all. T-SQL 2005 is the workhorse for this database, it has been developed and modernised (slightly) from T-SQL classic, but it's the language database developers will use 95% of the time for writing stored procedures. .NET code allows you to bring .NET types directly into the database for manipulation. Because those types run in the CLR, so must the code you use. However, this is the "long way round", so you can't expect it to perform as well as the classic T-SQL route. You would use .NET code in the database when: - returning a .NET class (or type) is more useful than returning a SQL type - the processing is not SQL-like The advantage of writing CLR code in SQL Server, is the ability to populate a custom business class (a .NET type) inside the database, in order to more readily marshal it to the business layer. Architecturally, it simply means you have the same types in the data layer as in the business layer.
9/8/2005 9:43:09 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]  

 Friday, August 26, 2005
Current status of restoring my blog from Google
I've got all the pages - held open in about two dozen browsers, now I just have to do some copy and pasting ...
 
done... now, some removing of Google highlighter, and we're good to go :-)

8/26/2005 5:22:02 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  

 Thursday, August 25, 2005
Thank Blog for Google
So, the other day, I deleted this blog. I deleted it accidentally, thinking it was the blog engine I no longer used. I did it using Shift + Delete, so it wasn't moved into the Recycle bin. The blog is completely self-contained within one folder, so there was no database content. Neither did I have any form of back-up - whatsoever...typical IT professional I hear you say :-)
 
Once I'd had enough of kicking myself, I thought about how to restore the content of my blog. Since I use it as a personal journal, making notes to myself, I was pretty keen to do this. I'd noticed that the blog got a lot of hits from Google, so I tried a little Googling....
 
Within minutes, I had found all the textual content from Google's cached pages - thank-you Google :-)
 

8/25/2005 1:56:06 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  

 Monday, August 08, 2005
Do you get errors when generating a dataset from the designer?
I did. Here's the symptom. I was trying to recreate a sample of a typed DataSet for a course I'm writing. My original sample, which worked fine, was in a project called Junk. Call me old-fashioned, but I wanted to present it with a better name. I chose TypedDataSets since that was what we were going to be investigating.
 
Time after time, I found that I got the same error message - that there were problems generating the DataSet and I should build the project and fix any errors before trying again.
 
Here are the mental pictures I took with me to bed last night...wondering just what I was doing wrong..
 
 
 
 
 
This morning, I worked out the problem. It's frankly unbelievable, but I can assure you this is the case. It was because I was working on a project which was located in a path with and ampersand in its name! Yes, that's it. Strangely, none of the several dozen solutions I've built in that same path displayed any weird behaviour, although none of used typed DataSets of course!
 
I wonder if the same is true of .NET2 ?

8/8/2005 5:36:37 PM (GMT Standard Time, UTC+00:00)  #    Comments [3]  

SOAP formatting: RPC/Doc/Enc/Literal
If anyone is still having trouble remembering what the different SOAP styles are, here's a reminder of Yasser Shohoud's article that reviews the whole topic and also tells you why you shouldn't worry - just be happy you're a .NET developer.
 

8/8/2005 5:36:37 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  

P/Invoke - My version of the GetVersionEx / OSVERSIONINFO marshaling example
It's taken me a little while to unravel the example in MSDN, but I finally worked out what it was showing!
Here, in case it will help anyone else, is my version of the code, with altered names and some comments, that, I hope, will make it easier to understand.
 

//You need to put this bit in a form and place a button1 on that form!

private void button1 Click(object sender, System.EventArgs e)

{

OSVersionInfoClass osvi = new OSVersionInfoClass();

osvi.OSVersionInfoSize = Marshal.SizeOf( osvi );

LibWrap.GetVersionExClass( osvi );

label1.Text = "Class size: " + osvi.OSVersionInfoSize;

label1.Text += "\nMajor : " + osvi.MajorVersion;

label1.Text += "\nMinor : " + osvi.MinorVerision;

label1.Text += "\nBuild : " + osvi.BuildNumber;

label1.Text += "\nPlatformID : " + osvi.PlatformID;

label1.Text += "\nVersion : " + osvi.versionString;

OSVersionInfoStruct osvi2 = new OSVersionInfoStruct();

osvi2.OSVersionInfoSize = Marshal.SizeOf( osvi2 );

LibWrap.GetVersionExStruct( ref osvi2 );

label1.Text += "\n\nStruct size: " + osvi2.OSVersionInfoSize;

label1.Text += "\nMajor : " + osvi2.MajorVersion;

label1.Text += "\nMinor : " + osvi2.MinorVerision;

label1.Text += "\nBuild : " + osvi2.BuildNumber;

label1.Text += "\nPlatformID : " + osvi2.PlatformID;

label1.Text += "\nVersion : " + osvi2.versionString;

}

 

//This stuff goes outside the form class. Either in a separate .cs file or just outside the form class

//class demo

[ StructLayout( LayoutKind.Sequential )]

public class OSVersionInfoClass

{

public int OSVersionInfoSize;

public int MajorVersion;

public int MinorVerision;

public int BuildNumber;

public int PlatformID;

[ MarshalAs( UnmanagedType.ByValTStr, SizeConst=128 )]

public String versionString;

}

//struct demo

[ StructLayout( LayoutKind.Sequential )]

public struct OSVersionInfoStruct

{

public int OSVersionInfoSize;

public int MajorVersion;

public int MinorVerision;

public int BuildNumber;

public int PlatformID;

[ MarshalAs( UnmanagedType.ByValTStr, SizeConst=128 )]

public String versionString;

}

// This class just hides the externs

// note they both map to the same function in the API, but I'm giving them a more useful name within .NET

public class LibWrap

{

[ DllImport( "kernel32", EntryPoint="GetVersionEx" )]

public static extern bool GetVersionExClass( [In, Out] OSVersionInfoClass osvi );

[ DllImport( "kernel32", EntryPoint="GetVersionEx" )]

public static extern bool GetVersionExStruct( ref OSVersionInfoStruct osvi );

}


8/8/2005 5:36:37 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  

 Monday, March 14, 2005
http://www.connectionstrings.com/

How great is this?

A simple site with a simple purpose and exactly the right name!

Well done, those folk at http://www.connectionstrings.com/ 


3/14/2005 6:33:27 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  

Use Starter kits in your organisation
OK, so I'm a believer in mentoring and learning by example. This feature of Whidbey is such a good idea: (copied from the What's new page) Starter Kits A starter kit is essentially an enhanced project template that can be shared with other members of the community. A starter kit includes code samples that compile, documentation, and other helpful resources to enable you to learn new tools and programming techniques while building useful, real world applications. For more information, see How to: Create a Starter Kit.

3/14/2005 6:33:27 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  

UDDI Server in Windows 2003 Server (Part 1 of 3)

I have been trying for nearly a year to get W2k3's UDDI server to do a couple of neat tricks for me. I've seen both done in demonstrations, but had been unable to recreate the steps in one case and in the other, was unable to track down the demo movie (even the project manager at Microsoft was unable to find it again.) Then a colleague located something that looked very much like the same demonstration on a Microsoft Webcast page, but when I ran it, the commentary talked about doing the fail-over I was hoping for, but the picture had frozen. Tantalizingly, I knew it was there but couldn't actually see it!

Anyway, that spurred me on to have another go at getting it to work, and this time I was more successful, finding Karsten Januszewski's blog and returning to his articles (about the only ones published on coding UDDI in W2k3) and also finding the code file archives for the Webcast.

It turns out that there are a couple of unexpected issues that I can pass on to anyone hoping to program UDDI that will be helpful.

The tasks that I will document are:

1. Adding services into UDDI so they can be discovered from Visual Studio's Add Web Reference wizard

2. Writing (.NET) client code that connects to an UDDI server, locates  service, then retrieves the bindings (endpoints) for that service. The idea is that it can be used for fail-over.


3/14/2005 6:33:27 PM (GMT Standard Time, UTC+00:00)  #    Comments [1]  

Get hold of great .NET Samples

This looks like a useful set of links and recommendations: (Just noticed the hyperlinks didn't make it via email, so will add them in later - Russ)

Adding Oomph With Samples by Mike Taulty

There are a whole host of resources that can help you learn about developer technologies. You can read books, check out magazine articles, attend conferences, watch online sessions, hang around in newsgroups and so on, but I think it's rare that any of these options give the same amount of pure oomph <http://go.microsoft.com/?linkid=1510970> as a good sample. With that in mind, I thought I'd use this article to list some oomph-packed samples of .NET applications that will potentially speed up your own development with (or conversion to) .NET. Here's the shortlist of three sites that I'd recommend:

Windows Forms.NET Sample Applications: <http://go.microsoft.com/?linkid=1510971> If you're looking at Smart Client applications then you need to take a look at samples such as FotoVision <http://go.microsoft.com/?linkid=1510972> and IssueVision <http://go.microsoft.com/?linkid=1510973>. The new Infragistics Tracker application <http://go.microsoft.com/?linkid=1510974> which makes use of the patterns & practices <http://go.microsoft.com/?linkid=1510975> code blocks and comes with documentation detailing the design and implementation decisions made during implementation is particularly useful.

The ASP.NET Starter Kits: <http://go.microsoft.com/?linkid=1510976> If you're building a web-site with ASP.NET then you need to take a look at these six applications that provide a fantastic starting point to get you going. Download them, install them, play with them and then discuss them in the ASP.NET Forums <http://go.microsoft.com/?linkid=1510977>.

Learn247.NET <http://go.microsoft.com/?linkid=1510978> - The WeRock 247 <http://go.microsoft.com/?linkid=1510979> & Football 247 <http://go.microsoft.com/?linkid=1510980> Samples:These go way beyond just being 'samples'. Both applications come with training materials that lead you through building the applications from scratch. Introductions are given to the technologies involved which span Smart Client, Web Client, Mobile Client and Web Services and the materials are available online or for order on DVD.

From

***************************************** MSDN Flash ***************************************** 22 November 2004


3/14/2005 6:33:27 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  

MSDN Nuggets
This promises to be a great mini series - 10 minute nuggets of technical knowledge. Great idea, great presentations
Go along to http://www.microsoft.com/uk/msdn/events/nuggets.aspx and see what there is to tempt you

3/14/2005 6:33:27 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  

Show(owner) is so neat
I was building a simple menu system from LinkLabels and wanted this behaviour: when the user chose a link, to minimise the menu form, show the chosen form, then restore the menu form when the user closed their chosen form.
 
Here's the code:

//minimize this window, and show another

this.WindowState = FormWindowState.Minimized;

frmDemo f = new frmDemo();

f.ShowDialog(this); //this form *owns* f

}

// in frmDemo, control the calling (owner) form!

private void Form1 Closed(object sender, System.EventArgs e)

{  //restore parent

    this.Owner.WindowState = FormWindowState.Normal;

}

 
 
It happens that I was investigating .NET 2, but actually this is a .NET 1 feature, although in .NET 1 it is only available for modal forms (ShowDialog method) and in .NET 2 it's available for both Show and ShowDialog methods.

3/14/2005 6:33:27 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  

 Sunday, November 21, 2004
Connection String testing tool
 

I wanted to experiment with the different forms of referencing the local machine's database localhost, (local), ., 127.0.0.1, etc., so I built this little tool.

Warning - the tool uses sa & no password - I dont! And neither should you!!!

Source available here

Exe from here

BTW - the “.” seems to work well


11/21/2004 6:30:28 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  

Micro(soft) Speak

I loved the lingo glossary that Robert McLaws found, offering such gems as:

Percussive Maintenance: The fine art of whacking the crap out of an electronic device to get it to work again.

Salmon Day: The experience of spending an entire day swimming upstream only to get screwed in the end

Crapplet: A badly written or profoundly useless applet. "I just wasted 30 minutes downloading this stinkin’ crapplet!"  

Brain Fart: A by-product of a bloated mind producing information effortlessly. A burst of useful information.


11/21/2004 6:30:28 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  

VB.NET, option strict on
 

This morning I read with glee, Rob Chartier's mini rant about VB.NET's option strict. I say “mini rant” in the hope of encouraging Rob to rant some more, but first I wanted to rush to the defence of the VB .NET team on one point.

I'm a VB programmer who moved to C#, so I also had a phase of damning the team for not adopting a consistent set of keywords across the two languages. Rob cites static (C#) and Shared (VB) as an example and asks why not just adopt one or the other. It would certainly make life easier for me. Actually, the benefits are even greater when you consider override (C#) and Overrides (VB) or new (C#) and Shadows (VB).

By now I've mentioned enough examples to set out the arguments against such a move. If C# and VB.NET had the same keywords:

  • Which case would you adopt, lower case throughout as in C, or Icapped as in VB?
    • Perhaps we could have a set of aliases like we do for the primitive types so that a C# programmer can type new and a VBer New
  • Which set of keywords do you choose?
    • The C# set are good because C, C++ and Java people are all familiar with them
    • The VB ones are good because they often describe the functionality far better (isn't Shadows a nice way of describing the effect achieved by adding a function in a derived class that eclipses the function of the same name in the base class?)
    • Maybe you decide each on its merit and produce a mixed ancestry. Yet sometimes the words are equally meritorious. Static variables are both static in memory and shared between instances.

VB .NET developers, in the main come from VB developers. I've not yet heard of people moving into .NET as their first programming experience (although a couple of Universities have started exactly such programs.) When they do start learning programming by learning .NET, I guess they are more likely to choose C# as the language - I would certainly advise them so to do.

So, VB .NET is there to allow millions of VB 3/5/6 programmers to move into OO and for them to stay up to date with the MS environment. Consequently VB .NET has to keep it's existing set of keywords for those people. But VB .NET introduced several keywords that did not exist in VB to allow for inheritance. And they chose descriptive words as is the tradition of VB because there was no reason to maintain a tradition with C. Interestingly, many of these VB developers have found the move to VB .NET too tough, but that's another story!

So, if the decision was to produce a single keyword set that was mixed, they would alienate both sets of developers. If they chose the C keywords, as they did for C#, they would alienate the oft-mentioned “millions of VB developers”. And if they went mixed, they would upset everybody!

IMHO, what the VB .NET team have done (or were told to do) is to “dumb down” VB .NET to the point where it is no longer the language of choice for serious, knowledgeable VB developers. I read sometimes that they are trying to re-introduce the RAD into VB, yet I don't think there's much difference in the number of keystrokes taken to type VB and C# code. Where it will make a difference is when wizards and helpers start to generate code. But frankly, that code could be in any language.

I do a lot of training and am involved in writing courses, where VB .NET has its place. For example, it's easy for the wider audience to read 5 lines of VB code that demonstrate some point, than it would be to read C#. Whether the audience chooses to write VB or C# is another matter, but I'm sure the C# writers can read both languages with ease.

However, I do agree with Rob and many others who have made the point about Option Strict - it was madness of them to default that to Off. Especially when you consider the rationale was to make VB .NET more like VB and to allow VB6 code and coding practises to be supported in .NET.


11/21/2004 6:30:28 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  

Visual Studio Tools for Office 2003 Training Available on MSDN
 

Sushila Patel announced a series of training / labs for Office 2003 at

http://weblogs.asp.net/SushilaSB/archive/2004/03/26/96760.aspx


11/21/2004 6:30:28 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  

What is WSE?

Since I've added WSE to the Web Services course, I was please to discover this 'positioning piece' from Omri Gazitt. The full version is here, but this extract describes WSE nicely:

So what is WSE?  WSE is a different kind of release.  It is a platform enhancement technology.  Shipping major platforms every few years is a fact of life, but some technologies move so quickly that customers need updates well before the next platform comes out.  Web services is one of those technologies.  So we created a new model for getting enhanced platform technology to our customers - and thus WSE was born.

WSE is a supported product in the same way that any Microsoft platform is - you can deploy on it, and we support it via Microsoft's Product Support Services.  But there are a few important differences.  First, each WSE release is supported for 2 years + 1 year of extended support (compared with the 5+2 model for major platform releases).  This is because we anticipate doing releases on around a yearly schedule, and our goal is to have at most 2-3 versions to support at any given time, so we can deliver on our goal to ship on the order of once a year.  Of course when the major platform comes out, we encourage developers to move to that platform, which is supported at 5+2.  Another difference is that WSE is not necessarily integrated with anything - there are no complex technology interdependencies - WSE is a standalone product and can therefore ship on a faster schedule.  Yet another difference is that we don't guarantee compatibility between releases - Web services are evolving quickly, and we often implement early versions of the specs which get superseded by the final versions (e.g. WS-Security getting superseded by OASIS WSS-Security).  Finally, while WSE is also "hardened" from a functional quality, security, and stress point of view, there are things that we don't do with WSE that we do for major releases - for example, we don't localize WSE.  For all of these reasons we are able to create new versions of WSE faster than we can roll out major platform releases.


11/21/2004 6:30:28 PM (GMT Standard Time, UTC+00:00)  #    Comments [4]  

Catch-all exception handler for desktop apps

Trapping Application.Run(new Form1()) exceptions works great in the debugger, but not at all in release mode:

   try
   {
    Application.Run(new Form1());
   }
   catch (Exception ex)
   {
    MessageBox.Show("Error: " + ex.Message);
   }

Turns out that Application is running your form on a different thread than the one you are catching, so you have to trap that thread instead:

    // Creates an instance of the methods that will handle the exception.
    CustomExceptionHandler eh = new CustomExceptionHandler();
 
    // Adds the event handler to to the event.
    Application.ThreadException += new ThreadExceptionEventHandler(eh.OnThreadException);
    Application.Run(new Form1());

You will also need the class that handles the event: 

  internal class CustomExceptionHandler
  {
 
   // Handles the exception event.
   public void OnThreadException(object sender, ThreadExceptionEventArgs t)
   {
    DialogResult result = DialogResult.Cancel;
    try
    {
     result = this.ShowThreadExceptionDialog(t.Exception);
    }
    catch
    {
     try
     {
      MessageBox.Show("Fatal Error", "Fatal Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop);
     }
     finally
     {
      Application.Exit();
     }
    }

    // Exits the program when the user clicks Abort.
    if (result == DialogResult.Abort)
     Application.Exit();
   }
 
   // Creates the error message and displays it.
   private DialogResult ShowThreadExceptionDialog(Exception e)
   {
    string errorMsg = "An error occurred please contact the adminstrator with the following information:\n\n";
    errorMsg = errorMsg + e.Message + "\n\nStack Trace:\n" + e.StackTrace;
    return MessageBox.Show(errorMsg, "Application Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop);
   }
  }

My thanks to Mark Conboy for providing this code (he found it on Technet)


11/21/2004 6:27:13 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  

101 things you always wanted to do in C# (and VB .NET)

If you're one of those people who prefer to copy and paste rather than originate (I know I am!) then this is for you: http://www.microsoft.com/downloads/details.aspx?familyid=08e3d5f8-033d-420b-a3b1-3074505c03f3&amp;displaylang=en">http://www.microsoft.com/downloads/details.aspx?familyid=08e3d5f8-033d-420b-a3b1-3074505c03f3&amp;displaylang=en

It's an installation of various self-contained VB and C# projects. Go on, you know you should!

BTW - 101 is American for basic/preparatory!


11/21/2004 6:27:13 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  

C# Specification documents

The ECMA Draft version (which I used to learn C# and found it to be very useful) can be found at http://www.stormsoftware.net/resources/Csharp ECMA Draft.doc

The official 1.2 version is at http://www.stormsoftware.net/resources/Csharp12.doc

And, the draft for the Whibey version is http://www.stormsoftware.net/resources/Csharp2.doc

This post is really a reminder to myself so that I can easily find them again!


11/21/2004 6:27:13 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]