IDisposable for dummies #2 – A guide about ‘how to implement it’

IDisposable - How ?In my previous post, I classified the different memory resources available in the .NET CLR and I explained the role of the IDisposable interface as well as the use of the Finalize() method.

In this post, I am going to talk more about the implementation details of IDisposable and Finalize().

For reference, I have split this matter into two posts:

(more…)

IDisposable for dummies #1 – Why? What?

(IDisposable - What ? Why?It took me more than a year to finish writing this article – a “hot topic” and I wanted it to be clear, simple and right. Also, I was busy and did not want to publish anything “unfinished”. As usual, your feedback and comments are more than welcome. Thank you in advance)

Recently (February 2011), I had to review some .NET code and came across of some wrong implementations of IDisposable.

After discussing with the developers, there were many reasons for what I found, ranging from:

  • Not knowing the difference between a “CLR memory resource”, a “managed resource” and an “unmanaged resource”;
  • Not understanding “how and when”  resources are “released”;
  • Not knowing when to override the “Finalize()” method and what should be released by a finalizer?

(more…)

Exception – How to raise and retrieve error information whithout losing it?

Small icon All .NET applications at sometime will have to deal with an exception. It is just a matter of time. As application run longer in PRODUCTION phase than in development (unless it is a prototype ;)) the more information you can get out of the exception, the more likely you will be able to quickly pinpoint the root cause and resolve the issue.

I know, this might seem a little too basic, but there are still some misuses of Exception and misunderstanding about how to raise/re-raise exception without losing the original information. So here it is my contribution to help to improve the “good” use of Exception programming in .NET (samples are in C#, but the principles are valid for the .NET platform). (more…)

PerfView 1.0 – A new performance analysis tool

Microsoft has just released a new performance analysis tool, called PerfView (download here).

It can help to isolate CPU- and memory-related performance issues. As I do a few performance analysis per month, this is a very good news – something new to try. (more…)

ODP.NET – “Pooling” and “Connection request timed out”

Oracle - Pooling - smallRecently, I had to look at an issue in our code regarding “Connection request timed out”. Our Oracle connections are set to use the Pooling service offered by ODP.NET. Oracle documentation as the following description:

“The Max Pool Size attribute of the ConnectionString property sets the maximum number of connections for a connection pool. If a new connection is requested, but no connections are available and the limit for Max Pool Size has been reached, then the connection pooling service waits for the time defined by the Connection Timeout attribute. If the Connection Timeout time has been reached, and there are still no connections available in the pool, the connection pooling service raises an exception indicating that the connection pool request has timed-out.” [Ref-01, p3-6]

(more…)

WinDbg – Failed to load data access DLL

I recently had to look at the  memory consumption of a .NET process (running as a service). The process memory was growing up and we wanted to see how the memory was used  (on a Windows 2003 SP2-32 bits server machine).

Using WinDbg, we created a dump of the process memory. Then I tried to look at it on my development machine (Windows XP SP2, 32 bits) and I got the error message “Failed to load data access DLL, 0x80004005“. The error was about the version of “mscordacwks.dll“.

(more…)

Am I Admin?

This is a quick sample code that I used quite often on customer sites:

  1. To Check whether or not I am a local admin on my machine.
  2. To quickly list what Windows groups my user account is part of.

(more…)

Excel DNA

Recently I was looking at technologies for “Excel Addins” and come across “Excel DNA” (used by some of my colleagues). It is a free framework with a very permissive open-source license.

My need was to be able to consume a WCF service (.NET 3.0) from some VBA code in Excel 2007. Excel-DNA helped to make the final solution very easily. I did a prototype (more…)

How to Debug the Installation/Uninstallation of Windows Service (.NET)

(original blog entry)

Just setup in your “Debug” tab of your Visual Studio “Windows Service” project:

  • Select “Start external program” and find “InstallUtil.exe” (usually under <Windows>\Microsoft.NET)
  • Then as command line argument put the name of your executable
  • As a working directory, select the output folder of your project

It should look like this:

 

Setup the breakpoints and hit F5. The installation should start and stop at your breakpoint.

If you want to debug uninstallation of your Windows Service (.NET), use the “/u” argument of InstallUtil.exe.

If the debug session is aborted (because you stopped it in the middle or an error arose) , then the service might not be completely installed or removed. If that is the case, just open a command line window and type in:

>InstallUtil.exe /u <path:filename of your .NET executable>

Good debug session.

%d bloggers like this: