Posts Tagged ‘Exception’

Office automation doesn’t work between different users – gives error Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005.

Thursday, August 26th, 2010

Yesterday, I was using an existing program on a new Windows 7 computer and when it was trying to send an email through Outlook, I was receiving the following error

Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005.

I tried it on my development machine (also Windows 7), and found that it worked fine.  Then I noticed that if I didn’t have Outlook loaded before trying to send the email, it seemed to work.  I realised that I was running my program as Administrator to temporarily work around some permissions problems, and that when Outlook was loaded normally, it was running as the normal logged in user.  I tried loading Outlook as Administrator and it worked fine, so I sorted out the permissions problem and turned off “run as Administrator” in the compatibility section of the program’s shortcut properties.  It still worked fine.  It looks like COM can’t operate between different users, which I suppose makes sense.

There may be other problems that can cause this same exception though – a quick search gave me a few other possible problems and solutions.

Unhandled exception clr20r3 mxyabj2rsfg4uknkgmspj2kfpmzxhcc5

Tuesday, August 3rd, 2010

A few weeks ago, I hit a problem that an application that I wrote suddenly started randomly dropping out with an unhandled exception. I can’t remember all the specifics anymore, but I do remember that the event that was written to the logs (that can be viewed in Event Viewer in Administrative Tools in Control Panel): –

EventType : clr20r3
P9 : mxyabj2rsfg4uknkgmspj2kfpmzxhcc5

The most confusing thing about this was that I have a system built in to the application to catch unhandled exceptions, and this had been working fine in the past for a few years. I couldn’t understand why it wasn’t catching this exception.

What was even more confusing was that it was randomly affecting several machines in different sets of circumstances. I eventually managed to find something that would reliably reproduce the problem, but when I tried it on my development PC in the debugger, it worked fine (I still haven’t worked out why this is).

I initially thought that maybe it was because I had just upgraded to Visual Studio 2010 and tried to back-convert my application back to Visual Studio 2008, but the problem continued. I also tried using remote debugging to track down the problem, which also caused a lot of problems as the application still seemed to be dropping out even with the remote debugger running!

I eventually tracked down the problem using a Try, Catch clause around code which I knew would reproduce the problem. The exception was about a missing resource file. I hunted around and eventually found that the resx file for the error handling dialogue window seemed to have been excluded from the project, presumably due to some bug while it was being upgrade to Visual Studio 2010.

After I put the resx file back, I was able to see that the application was throwing an exception. My code for dealing with the unhandled exception had caught it and been throwing the other exception, which didn’t have anything to catch it, so the Common Language Runtime (or Windows?) killed it.

Edit: The actual exception type that was being thrown was System.Resources.MissingManifestResourceException

Windows Forms controls and the red X

Thursday, December 17th, 2009

I have been working on a project where certain controls randomly seem to come up with a red X and a red border around it.  I wasn’t sure what was causing it, but it turns out it is when an exception is thrown by code in the paint event.  For more details, see the following blog from  WinForms controls and the red X.

Exceptions Explained: NullReferenceException

Sunday, November 8th, 2009

This is the first on a new series of posts that I’m going to be doing on explaining various different exceptions, what they mean, when you might get them and how to avoid them.

The first one is the NullReferenceException, which usually comes with the message “Object reference not set to an instance of an object.”. This Exception occurs when you try to access an object reference which is set to Nothing.

First of all, you need to understand the difference between value types and reference types in .NET. With a value type, we only care about what data is stored within it. With a reference type, the actual instance of the type is important in itself. For example, we may have an Integer, which contains 10. Integers are value types, and there is generally nothing particularly different between one number 10 and another number 10 if they are both Integers, so they are effectively identical.

Reference types on the other hand are different. If we have two customers, and both of them happen to be called “John Smith”, we don’t want to treat them as being the same thing just because they have the same name. The other difference with reference types is that we can have an empty reference – Nothing (or null in c#).

In fact, behind the scenes, reference types store a location in memory of the instance. In older programming languages, such as C/C++, these were known as pointers, and you could actually access them just like a number and change the item that they were pointing to with arithmetic operators (+/-/increment/decrement etc.) This created a number of potential problems and so references were created to protect pointers from causing too much damage. References also the garbage collector to keep track of what is referencing an object instance so that the instance can be cleared up when it is no longer in use.

The NullReferenceException is thrown when you attempt to access an object reference which is set to Nothing. This can easily happen because as mentioned above, all variables of a reference type will be initialised to Nothing by the .NET framework if they have not been explicity set to something else.

For example,

        Dim c As Customer
        c.Name = "John Smith"

The second line in the above piece of code will throw a NullReferenceException as the variable c is still set to Nothing, and when the .NET framework attempts to access the Name field, it will find that the object does not exist.

This is easily resolved by setting c to whatever Customer you wish to use, or to a New Customer.