Error message 800704a6 as part of creating an instance of the COM component

This will be a very short post, and comes from rage against Windows Server and the Windows update system. Because there were outstanding Windows Updates requiring a reboot, a particular build script of ours was falling over without suitable information as to why exactly.

The cryptic error was:

Creating an instance of the COM component with CLSID {0002DF01-0000-0000-C000-000000000046} from the IClassFactory failed due to the following error: 800704a6.

The answer (at least for us):

Reboot!

There are windows updates getting in the way of instantiating new COM objects.

You’ll see a lot of people having a similar problem, not sure if reboot is the answer for them all, but make it your first step, and memorise the error code 800704a6. Unable to verify this but it looks to relate to the text code of ERROR_SHUTDOWN_IS_SCHEDULED.

The ServerFault post that helped most:
serverfault.com/q/ie8-script-error-800704a6

Stackoverflow Questions

stackoverflow.com/watin-nunit-and-cruisecontrol-net-error-message-800704a6
stackoverflow.com/tests-fail-sporadically-using-cruisecontrol-net-with-nunit-error-800704a6
stackoverflow.com/setup-method-failed-while-running-tests-from-teamcity
stackoverflow.com/tests-fail-sporadically-using-cruisecontrol-net-with-nunit-error-800704a6
stackoverflow.com/failed-due-to-the-following-error-800704a6-while-trying-to-read-data-from-a-text-file

Unit Testing JavaScript methods that contain jQuery ajax calls

Objective

Unit test a JavaScript method which contains a $.ajax() call. Using QUnit.

Details

This was supposed to be a simple task, and if I didn’t have a few (now) obvious faults in my JavaScript code, it would have been completed more quickly. I have gone through several answering my own StackOverflow questions on the next day here’s the one in question for the curious ones.

I will hide behind the excuse of it being the early days of the new year and still finding my coding groove after almost two weeks on holiday…

So in this post I’ll summarise the two approaches I came out with in the end. It’s two because neither worked for me first time, and in my attempt to solve the first discovered the second. In the end resolving both. I won’t bother going into much detail about QUnit, as there are many posts out there about it; here, and here and here and official documentation here, and other interesting things to do with it.

As a quick aside we use the NuGet package NQUnit.NUnit to help us integrate QUnit into our Visual Studio projects.

Basic Approach

Solution 1 – basic way as is shown on this StackOverflow answer

// Arrange
    var options,
        jsonText = '{"id": "123", "fieldName": "fbs", "data": "fbs-text"}',

// Set up to 'capture' the ajax call (this forms the mock)
$.ajax = function (param) {
    options = param;
};

// Act - call the method which is 'under test'
/* ... */

// Call the success (or failure) method to complete the mock of handling of the 'response'
options.success(expectedData);

// Assert - verify state of system is as expected
/* ... */

Alternate Approach MockJax

Solution 2 – using the MockJax library with a great walk-through on how to use it here.

There are several advantages in using MockJax, that can be summarised as just having more control over mocking the ajax portion of the method under test, including but not limited to; timeouts, introducing latency, returning HTTP status codes.

After having included MockJax in your project, the solution 1 code gets replaced with 1 method call to $.mockjax() and looks like this.


// Arrange 
    var jsonText = '{"id": "123", "fieldName": "fbs", "data": "fbs-text"}';

// The call to mockjax replaces the need to overwrite the jQuery ajax() method
$.mockjax({
    url: '/Your/Regular/Action',
    dataType: 'json',
    contentType: 'application/json',
    responseText: jsonText
    }
});

// Act - call the method which is 'under test'
/* ... */

//perform test assert state of system is as expected
/* ... */

Demonstration

Full QUnit test code is up as a Gist.

Find a working copy of the code here in it’s simplest form: jsfiddle.net/NickJosevski/9ZZmc/4/