Side-by-Side Problems

Published 28 March 07 02:05 PM | john 

If you still write C++ code on Windows then sooner or later you are going to run into SxS configuration problems on Windows.  At work we tend to run into them more frequently because the C runtime version is changing all the time (because we're building it).

The first thing to note is that diagnosis of SxS problems on any other platform than Windows Vista is horrible.  You're best bet is to look in the event log and try to figure out what version of the DLL is being requested.  To fix SxS problems on XP it is possible to drop a .manifest file next to your application along with the correct DLL versions.  This doesn't work on W2K3 or Vista.  So, without exception the best way to fix SxS problems caused by not having the correct version is to get the .msi installer for the version of the files that the application is requesting and install it. 

Why is diagnosing SxS problems on Vista easier?  Because on Vista the SxS loader rountines have been ETW instrumented, and tool has been provided to quickly collect and format these events.  Simply run sxstrace on Vista for instructions on how to use the tool.    Remember you'll have to be an admininstrator to use ETW and it will trace all SxS activity on the machine so turn it on and off as you need it.

If you find that even after you have installed the correct SxS version things still don't run it is quite possible that the SxS policy of the new version has horked you.  Policy for SxS is similar, but not the same as, .NET's policy redirection assemblies that nobody uses.  Basically, the SxS trace will show you that a policy file is being loaded and used.  If you open the file (it's a .manifest file that is buried, and I mean buried, in the WinSxS\Manifests directory).  Just cut and paste the name from the log, because there are usually hundreds and hundreds of similarly named files in this directory.

If you find a bunch of XML elements with bindingRedirect in the policy file, look and see if one is redirecting your assembly to another version.  It's quite possible to redirect to a version of the assembly that isn't actually installed, thus causing a load failure for you application.  You'll need to find it and install it.

Sometimes you need to take matters into your own hands and to fix weird SxS problems.  Unfortunately the files in the SxS tree are installed by the Windows installer, and the ACL's are set such the owner is TrustedInstaller, and you are not able to write to them.  To rectify this situation and take matters into your own hands an Administrator can change the file ownership and give themselves write permission to the file.  Then you can comment out the offending lines, and put a line in like:

<bindingRedirect oldVersion="1.0.0.0-1.0.65535.65535" newVersion="2.0.0.0"/>

But seriously, don't do this unless you really understand what you are doing.  It's quite likely that uninstall of the SxS libraries may no longer work correctly and you could be heading into "flatten" your machine territory if things start breaking mysteriously.  The Windows Installer is a complicate and unforgiving beast.

Filed under: , , ,

Comments

# Bug me said on April 9, 2007 5:43 PM:

Everybody seems to be having SxS problems . I know I have them all the time. SxS (or side by side) was

# The Director of Random Technologies said on July 23, 2007 4:01 PM:

While I haven't been posting much here, I have been posting pretty regularly over on my main development

Anonymous comments are disabled