FF 3.5.3 crashed again

My Firefox 3.5.3 crashed again for the third time today:

Add-ons: {2B8EFF80-1240-11DB-BF6C-934CD2EFDFE8}:20080728.334,{CF40ACC5-E1BB-4aff-AC72-04C2F616BCA7}:1.5.2.35,toolbar@alexa.com:1.3.0,{2fa4ed95-0317-4c6a-a74c-5f3e3912c1f9}:2.1.062,firebug@software.joehewitt.com:1.4.2,{d37dc5d0-431d-44e5-8c91-49419370caa1}:2.5.35,{e4a8a97b-f2ed-450b-b12d-ee082ba24781}:0.8.20090123.1,{CAFEEFAC-0016-0000-0007-ABCDEFFEDCBA}:6.0.07,{CAFEEFAC-0016-0000-0011-ABCDEFFEDCBA}:6.0.11,{CAFEEFAC-0016-0000-0015-ABCDEFFEDCBA}:6.0.15,LogMeInClient@logmein.com:1.0.0.460,{B7082FAA-CB62-4872-9106-E42DD88EDE45}:3.0,{20a82645-c095-46ed-80e3-08825760534b}:1.1,pencil@evolus.vn:1.0.6,refractor@developer.mozilla.org:1.0b2,twitternotifier@naan.net:1.8.3,web@veoh.com:1.4,{972ce4c6-7e08-4474-a285-3208198ce6fd}:3.5.3
BuildID: 20090824101458
CrashTime: 1253813633
InstallTime: 1252611358
ProductName: Firefox
SecondsSinceLastCrash: 70976
StartupTime: 1253811215
Theme: classic/1.0
Throttleable: 1
URL: about:blank
Vendor: Mozilla
Version: 3.5.3

This happened while I was doing Google searches…probably one of the add-ons’ fault (probably the Alexa toolbar). 

Update 17:40 EDT: It’s not the Alexa toolbar. Next guess: McAfee SiteAdvisor 3.0

One of the design goals that one should aim to achieve, when building any plug-in architecture, is isolation, to the extent that  a crash in one of the  plug-ins should not bring down the entire application.

Somehow, that is very hard to do, isn’t it?

Guilty as charged.

COMException : Creating an instance of the COM component with CLSID {…}

I recently changed my NAnt build script, as part of its post-build cleanup step,  to unregister all .NET COM interop components after doing the build. Now my unit tests fails with this error:

System.Runtime.InteropServices.COMException : Creating an instance of the COM component with CLSID {596C3AA2-D5EC-4F86-85E3-7FAF86EC17A3} from the IClassFactory failed due to the following error: 800a005b.

What’s the cause?

Here are the facts: My .NET lib X depends on a  COM lib Y (596C3AA2-D5EC-4F86-85E3-7FAF86EC17A3), which depends on COM lib Z, which in turn invokes  .NET COM interop lib N.

It turns out that the real culprit was N, which wasn’t registered for some reason, even though I’ve told it to register via the regasm NAnt task.

Well, as it turned out, I needed to add the codebase=”true” attribute to the regasm task that registers N, which makes sense in hindsight, because my DLLs are not all in the same directory. Another “doh!” I suppose.

AccessViolationException in OpenFileDialog.ShowDialog()

Note to self:  Next time I get this error, when running in a 64-bit OS, make sure to specify x86 for Platform target in the Build options.

PageRequestManagerParserErrorException

Good tips from Eilon Lipton on this error:

Microsoft Internet Explorer
---------------------------
Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.

I suppose I fell into trap #5 listed on the article.  I was looking to do parameter passing from the current page to the redirected page. Basically, I had a general “catch all” event handler that catches unhandled exception, and forwards the detail to an error display page.  There doesn’t seem to be any direct way of passing parameters from one  .aspx page to another. So I stuffed this parameter into the HttpContext object.  The problem is: Reponse.Redirect() wipes out all parameters stored in the context. This problem doesn’t happen if I use Server.Transfer().

All of this was happening inside an UpdatePanel,  just as Eilon explained.  Hence, the PageRequestManagerParserErrorException. I looked in my ErrorStack, saw what the originating error was, fixed it, and the PageRequestManagerParserErrorException was gone.

I guess the next step would be to figure out how to display the error properly when invoked from an UpdatePanel, as it is working well everywhere else.

Wow!

I want a Mac for Christmas:


Just kidding.

Flight scheduling system test case: flight number re-use

Scenario:

  • Mom books a flight from airline X, gets assigned flight number 123, arriving at airport YYZ @ 5:45am
  • Mom tells son: “my flight #123 arrives tomorrow @ 5:45am”
  • “Tomorrow” comes. Son goes online and checks flight info, which states that flight 123 is on-time.
  • 6:15am: son arrives at YYZ to pick up mom.
  • Son checks the Arrivals Fight Info board, which says flight 123 has landed. Son waits at the Arrivals Area.
  • Three hours later. Mom was “no show”. Son calls mom, who says “oh, did I say ‘today’? I meant ‘tomorrow’. Tomorrow @ 5:45am.”

Why someone would design a flight number assignment algorithm such that any X flight departing XXX for YYZ at time hh:mm, on any day of the week, would get assigned the exact same flight number, is beyond me. Are flight numbers so scarce that they have to reuse the same numbers every day?

LINQ to Entities does not recognize the method 'Boolean Like(System.String, System.String)' method

I’ve been dabbling with the ADO.NET Entity Framework in .NET 3.5, was trying to convert this SQL WHERE clause, which uses the LIKE operator, into LINQ syntax:

String strWhereClause = String.Format(CultureInfo.CurrentCulture, "Type={0} AND Name LIKE '*{0}*'", orgType, orgName);

I read somewhere which suggested to use the SqlMethods helper class. So I tried:

var objQuery = repository.Organization.Where(vendor => vendor.Type == orgType && SqlMethods.Like(vendor.Name, "”%” + orgName + “%”));

The query is targeting an Organization table. repository is an instance of an ObjectContext subclass which has been  auto generated by Visual Studio’s ADO.NET Entity Data Model wizard.  orgType and orgName are passed-in parameters.

The above approach resulted in the following runtime error (notice the redundant occurrence of the word ‘method’ in the error message):

LINQ to Entities does not recognize the method 'Boolean Like(System.String, System.String)' method, and this method cannot be translated into a store expression

I then saw a post on stackoverflow which suggested to use Contains(), StartsWith(), or EndsWith() to mimick the LIKE operator. So I tried:

var objQuery = repository.Organization.Where(vendor => vendor.Type == orgType && vendor.Name.Contains(orgName));

This works, but if orgName.Length is zero, then the query returns zero rows.  So finally, a slight mod to the above query achieved the desired effect:

var objQuery = repository.Organization.Where(vendor => vendor.Type == orgType && (orgName.Length == 0 || vendor.Name.Contains(orgName)));

“The underlying provider failed on Open.”

I’m deploying my ASP.NET app to a brand new server with a fresh install of SQL Server 2008 Express. The db connection step failed with this error:

Message: The underlying provider failed on Open.
StackTrace:  at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) at System.Data.EntityClient.EntityConnection.Open() at System.Data.Objects.ObjectContext.EnsureConnection() at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)

I checked the connectionString, which uses Windows authentication, and it looked fine.

Somebody suggested to Allow Remote Clients in the Network DTC Access settings. That option is already enabled on my environment.

I looked at the Event Viewer, and noticed this entry:

Event Type:    Failure Audit
Event Source:    MSSQL$MSSQL
Event Category:    Logon
Event ID:    18456
User:        NT AUTHORITY\NETWORK SERVICE
Description:
Login failed for user 'NT AUTHORITY\NETWORK SERVICE'. Reason: Failed to open the explicitly specified database. [CLIENT: <local machine>]

So IIS is trying to access the database under the credential   'NT AUTHORITY\NETWORK SERVICE' .  I looked that the db settings via SQL Server Management Studio and, sure enough, that account is not listed as one of the users allowed to connect. So I added him. And the web app was able to connect successfully.

Which config file to put the db connectionString for ADO.NET (3.5) Entity Data Model?

Normally this goes in the App.config. VS2008 designer wizard automatically creates this file and puts it in the same location as the  assembly in which your database layer resides. But if you’re calling that assembly from an ASP.NET app, you’ll  need to move that connectionString to the Web.config.  Otherwise, you’ll get this error upon  instantiation of the ObjectContext:

The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.

Google Wave

Just watched the Google Wave demo, via @tylerwhitaker. Board game playing via email--I've thought of this before but seeing it implemented with Wave is so much cooler!


Appropriate levels of abstraction

I've learned over the years, through the many facets of my job, to don a different hat depending to whether I'm talking to a programmer, a business person, or an end user.

Which is why it always freaks me out when I see my fellow developers showing my CEO how to run regasm to get a particular new product feature to work. Good God!

I guess in some sense it's good, because now when something is not working quite right, my CEO would ask "Do I need to rerun regasm?"

Why does UnhookWindowsHookEx() fail?

I’m debugging a Windows hook DLL that’s misbehaving. Actually I’m still not sure whether it’s the hook DLL, or the C# library that calls it, that is the culprit. Here’s the problem symptom. My app DLL installs a mouse hook into a running application. The running app terminates. My app detects that it has terminated and attempts to remove the hook—this fails (1). On subsequent startup of the app in question, I try to re-install the hook onto it, and that fails (2). I’m actually more interested in failure #2 than failure #1, but the latter is probably a consequence of the former. So I needed to track down why #1 happened.

Side fact:

When you install a thread-specific Windows hook, your hook DLL is actually loaded in 2 places: one instance is loaded in your app's process space, and the other in the target app's.

At first, I thought that Windows was failing to do its DLL cleanup duties when the unhook step failed, so I was ready to look into manually forcing the unload and reload of the native DLL—often a bad idea to circumvent the garbage collector, but, hey, what else can you do?

Then I spotted the culprit:

DLLEXPORT HHOOK SetHook(HWND hWndTarget, HWND hWndListener) {
if(m_hWndListener != NULL) return NULL; // already hooked!
// install the hook via SetWindowsHookEx()


m_hWndListener = hWndListener;

}

DLLEXPORT BOOL ClearHook(HHOOK hook) {
BOOL unhooked = UnhookWindowsHookEx(hook);
if (unhooked) {
m_hWndListener = NULL;
// do other cleanup stuff
}
return unhooked;
}

It turned out: m_hWndListener was not being cleared when UnhookWindowsHookEx() failed.

Yet again, it goes to show that: just when I thought that the developers at Microsoft are a bunch of idiots who had no clue what they were doing when they invented the Windows API, it turns out that the idiot is me.

As to why UnhookWindowsHookEx() failed, my guess is that the hook was already being automatically removed by the OS when the target app terminated.

Adding custom properties to the MOSS2007 Advanced Search page

Recently, I’ve been playing a bit with MOSS2007. Actually I've dabbled with it a little bit when SharePoint 2003 came out, but not to the extent that I am now.

Installation was a bitch at the start, but thankfully there is a lot of useful resources out on the web this time around. I was looking to set up metadata (custom column) searching, and this article, Searching Custom Column Values in MOSS 2007  by Jonathon Frost, was extremely helpful. I did find, however, a couple of subtleties not mentioned in Jonathan's post.

For instance, I needed to add the corresponding PropertyRefs in the All Results ResultType section:

<PropertyDefs>

  <PropertyDef Name="Vendor" DataType="text" DisplayName="Vendor#"/>
  <PropertyDef Name="Invoice" DataType="text" DisplayName="Invoice#"/>
</PropertyDefs>

<ResultType DisplayName="All Results" Name="default">

    <PropertyRef Name="Vendor" />
     <PropertyRef Name="Invoice" />
</ResultType>

Originally, I mistakenly added my PropertyRefs in the “Word Documents” section, and was scratching my head for some time, wondering why my changes wouldn’t show up on the refresh of the Advanced Search page.

I also noted that I needed to manually run a Full Crawl for the custom properties to show up in the "”Mappings to crawled properties” section—which makes sense in hindsight.

Another thing I observed was that if I made changes to the Properties XML, I had to do an Incremental Crawl for it to take effect. For instance, I originally had the DisplayName for the “Vendor” property as simply “Vendor”. Later, I went back and changed this to Vendor#. The change would be reflected immediately on on the Advanced Search page, but the search was returning no results, until I manually ran the Incremental Crawl.

stdole 7.0.3300.0

When I first got this error during the initialization phase of my component:

Could not load file or assembly 'stdole, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

I thought that it wanted Interop.stdole.dll, which was sitting right there in the working directory. But as it turned out, it meant the Primary Interop Assembly called stdole.dll, which was indeed missing.  Duh!

Setting up a WIX 3.0 build environment

I recently encountered some problem with heat.exe with respect to COM registry harvesting, and wanted to step through the code in the debugger, to see what was the problem.

I had some initial trouble setting up a dev environment for WiX, have read Neil Sleightholm's post on  How To Create a WiX build machine, but it didn’t go so well for me.  The process is really simple, with the following commands:

  • do a cvs checkout per instruction here:
    • cvs -d:pserver:anonymous@wix.cvs.sourceforge.net:/cvsroot/wix login
    • cvs -z3 -d:pserver:anonymous@wix.cvs.sourceforge.net:/cvsroot/wix co -P wix
  • set WIX_ROOT environment variable
  • cd to %WIX_ROOT%
  • Run bin\wixenv.bat,
  • Run NAnt

Yet, when I ran the NAnt command, I kept getting this error:

Failed to initialize the 'Microsoft .NET Framework 2.0' (net-2.0) target
framework. Property evaluation failed.
Expression: ${path::combine(sdkInstallRoot, 'bin')}
^^^^^^^^^^^^^^
Property 'sdkInstallRoot' has not been set.

Part of the problem was that it needed a post-0.86-beta1 build of NAnt, which unfortunately, is not available on the NAnt project home page. I managed to find it by googling, leading to  this download link (the version I downloaded was 0.86.3317.0, 30/01/2009).  Once I got NAnt 0.86.3317.0 in place, the wix build finished without a hitch.

Vundo disabled Norton 360

I had a full day of battle with Vundo.H Trojan last Sunday trying to get my dad’s infected computer cleaned up.  The parasite was occasionally popping this message:

“Your system is infected with dangerous virus! Note: Strongly recommend to install antispyware program to clean your system and avoid total crash of your computer!”system-error

As well, it’s the root cause of a subsequent DoS (more later).

One of the registry keys that was infected was the  AppInit_DLLs key, which Raymond Chen once wrote about in a blog entry aptly entitled  AppInit_DLLs should be renamed Deadlock_Or_Crash_Randomly_DLLs.

Anyway,  kudos to Malwarebytes' Anti-Malware for being a very useful tool.  But for a while there, as I sat and watched explorer.exe puts back this registry value no sooner than I deleted it, I felt like I was in the late 80s, early 90s, where viruses freely infected MS-DOS in similar manners.  I finally woke up and demoted my dad to non-administrative user level, which brings me to the next point about  antivirus.

In addition to the annoying popup, Vundo also messed up the antivirus software.  My dad had Norton 360 installed on his system, with at least 30 days remaining in his update subscription.  Yet, Vundo managed to sneak through, and somehow confused it enough to DoS my attempt to access the Internet—not only port 80, but all ports were being blocked.  One note of interest: for a while there it was refusing Firefox but lets IE through, but after a while, even IE was returning the  “Web page cannot be found” message.  Anyway,  I uninstalled Norton after cleaning Vundo and was then able to surf the web again.

 

There seems to be some controversy about using antivirus software over running Windows under a  non-admin account.  Apparently, over 92% of Windows security vulnerabilities reported last year could have been prevented if users were not using admin accounts.

I know that for me, running as a non-admin user will probably never fly in a software development environment where running a build requires elevated privilege in order to do COM registrations. As for my dad, non-admin account might suffice for now, but I wonder if it will prevent him from inadvertently falling victim to  phishing scams, which some antivirus software is able to prevent.

Unable to cast COM object of type ‘X’ to interface type ‘_X’

I added a new property to my COM class and consequently bumped up its minor version by 1, did some testing with it, and then decided that I wanted to run a clean build.  Now my existing NUnit test cases that use this class are failing with the following message:

Unable to cast COM object of type MyLib.MyClass' to interface type MyLib._MyClass'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{…}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).,

The interesting thing is that everything compiled without a hitch.  Is this  .NET’s version of BadImplementsRefInCompatLib?

Looking that the COM library’s IDL info via oleview.exe , it turned out that the interop assembly was bound to version 1.3 of the COM library, whereas 1.2 was registered on my machine. I regenerated the COM interop assembly for 1.2, and the problem went away.

Bogus TBird error message on 64-bit Windows Vista

Thunderbird message:

Thunderbird is already running, but is not responding. To open a new window, you must first close the existing Thunderbird process, or restart your system.

At first, when I saw this message this morning, I thought: OMG, some Windows updates that I installed last Friday have actually gone and made TBird 2.0.0.19  incompatible with Vista 64! 

But then, as hinted from this forum post, this bogus error actually means that there’s something wrong with the user profile. In my case, the mail folder was sitting on a disk drive that was disconnected. I reconnected it and all was well as before.

The WPF UserControl experiment 1

Goal: 
To create a WPF user control that implements basic functionality from a  non-GUI interface, and delegating the rest through abstract methods.

Attempt 1:

  1. Defined a base WPF user control BaseWpfControl using XAML.
    public abstract partial class BaseWpfCustomPropertyEditor : UserControl, Interface1 { …}
  2. Then, extend BaseWpfControl, like so:
    <local:BaseWpfControl x:Class="MyNameSpace.LoginEditorControl"
       xmlns="
    http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="
    http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:MyNameSpace"
        Height="206" Width="595">
        <Grid Height="300" Width="418">
            <Grid Margin="10,10,-75,120">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="210*" />
                    <ColumnDefinition Width="118*" />
                    <ColumnDefinition Width="155*" />
                </Grid.ColumnDefinitions>
                <Label Height="33" Margin="6,-1,67,0" Name="label1" VerticalAlignment="Top">Host Name:</Label>
                <TextBox Height="23" Margin="12,25,23,0" Name="txtHostName" TextChanged="txtHostName_TextChanged" VerticalAlignment="Top" Grid.ColumnSpan="3" />
                <Label Height="29" Margin="6,47,88,0" Name="label2" VerticalAlignment="Top">User Name:</Label>
                <TextBox Height="23" Margin="12,71,23,0" Name="textBox1" VerticalAlignment="Top" Grid.ColumnSpan="3" TextChanged="textBox1_TextChanged" />
                <Label Height="25" Margin="6,102,94,0" Name="label3" VerticalAlignment="Top">Password:</Label>
                <PasswordBox Height="23" Margin="12,133,23,0" Name="passwordBox1" VerticalAlignment="Top" Grid.ColumnSpan="3" PasswordChanged="passwordBox1_PasswordChanged" />
            </Grid>
        </Grid>
    </local:BaseWpfCustomPropertyEditor>
  3. Got compile-time error: "cannot be the root of a XAML file because it was defined using XAML""

Conclusion: WPF user controls were designed for composition, not inheritance.

Attempt 2:

  1. Instead of using XAML, simply defined  BaseWpfControl as a class that extends System.Windows.Controls.UserControl
  2. Repeat Attempt 1.2
  3. Now compiles fine. But when trying to bring up LoginEditorControl, got error:
    Problem Loading … Could not create an instance of  type “BaseWpfControl…”
  4. Double-checked, BaseWpfControl did have a default constructor
  5. Removed abstract partial keyword in base class  Same problem
  6. Searched the web; found this https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=292693:
    ”Hello, if you mark your base generic class as abstract, the designer does not work. I understand this might not be a supported scenario and I'd live with this, if:
    1) it would not work with non-abstract classes as well,
    2) all the XAML code would not get underlined, that is really crazy.”

Sub-Goal 1.1:

  • how to make an abstract WPF base control editable in the UI designer?

Attempt 1.1.1:

  1. Per http://www.urbanpotato.net/default.aspx/document/2001, annotated BaseWpfControl with
    [TypeDescriptionProvider(typeof(GeneralConcreteClassProvider))]
    [ConcreteClass(typeof(UserControl))]
  2. didn’t help … same error “Could not create an instance of …”

Attempt 1.1.2:

  1. Removed abstract keyword from BaseWpfControl .
  2. Bring LoginEditorControl control back in the VS2008 Visual Designer. Got message:
    The document root element is not supported by the visual designer
  3. Changing base class for BaseWpfControl to ContentControl didn’t help.
  4. If we changed to using XAML for BaseWpfControl, then we’d be back to problem 1.3

Attempt 1.1.3: immediate work-around

  1. Remove abstract keyword from BaseWpfControl
  2. commented out the line:
    public partial class LoginEditorControl : UserControl, BaseWpfControl { 
  3. Replaced with:
    public partial class LoginEditorControl : UserControl {
  4. Replaced XAML declaration
    <local:BaseWpfControl  x:Class="MyLib1.LoginEditorControl " xmlns:local="clr-namespace:MyLib1"
    with
    <UserControl
  5. Edit the control in VS Visual Designer, then undo steps 1-4 prior to running.

Stopped experimenting here. If I had had more time, I would have liked to try these:

Attempt 1.1.4: better workaround – use XamlPad
Previous process was too cumbersome to undo. Use XamlPad to edit the control GUI, and then paste he result back to the VS project.

Attempt 1.1.5: How to overcome restriction of “multiple class inheritance”?
Use Events instead.

citizen journalism

Recently, I've come to realize how useful a tool like Twitter is, and then I read Jonathan Nguyen's post, claiming that citizen journalism is not journalism. I thought a journalist was simply someone who keeps a journal. :-)

All joking aside, as a user of software, I couldn't care less if the application, that I am using, has been written in VB, C#, or Python, so long as it gets the job done. The same goes for news: as a consumer of information, I just want to get up-to-the-minute information on the current issue, regardless of whether it was written in leet or in perfect English. In that respect, twitterers sometimes do a much better job at it than official news agencies.

The bottom line is: perhaps it is true that citizen journalism is not journalism, but as an end-user, I don't really care.

Twittered

As usual, it finally took a necessity like #darkTO for me to jump onto the latest techno bandwagon such as twitter.