Welcome to MSDN Blogs Sign
in | Join
| Help

Junfeng Zhang's .Net Framework
Notes

Fusion, CLR, .Net Framework, and others

This Blog

About

Mar

April 2006

May

S

M

T

W

T

F

S

26

27

28

29

30

31

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

1

2

3

4

5

6

Syndication

RSS 2.0

Atom 1.0

Search

Go

Archives

August 2006
(6)

July 2006
(2)

May 2006
(2)

April 2006
(12)

March 2006
(9)

February 2006
(5)

January 2006
(2)

December 2005
(10)

November 2005
(7)

October 2005
(2)

September
2005 (3)

August 2005
(1)

July 2005
(6)

June 2005
(8)

May 2005
(17)

April 2005
(9)

March 2005
(6)

February 2005
(9)

December 2004
(7)

November 2004
(12)

October 2004
(16)

September
2004 (13)

August 2004
(15)

July 2004
(10)

May 2004
(6)

April 2004
(14)

March 2004
(19)

February 2004
(39)

January 2004
(6)

News

Questions
and Topics suggestions

Navigation

Home

Photos

Post Categories

.NetFramework
(156)

Fusion
(109)

General
(18)

Others
(39)

Vista
(5)

Win32
(38)

Fellow bloggers

Raymond Chen, Old New Thing

Chris Brumme, CLR Architecture

Suzanne Cook, CLR Loader

Alan Shi, Fusion/CLR

Michael Grier, Fusion/Win32

Jon Wiswall

Myself, blogging in Chinese

Saurabh's ClickOnce blog

Diagnosing SideBySide failures

PhilW believes that SxS
COM with manifest is one of those “well kept secrets” that should be more well
known. As the current maintainer of Windows SxS, I am absolutely thrilled to
hear that.

That said, I have to admit that it is not the easiest thing in the world when
something went wrong in Sxs. Typically you are left in a situation with no hint
of what went wrong, and how to fix the problem.

In Vista some work is done to make Sxs failures easily diagnosable.

This article compares the experience of diagnosing Sxs failure in Windows XP
and Windows Vista.

In VS 2005 VC80 CRT is fusionized (when a component is made into a Sxs
assembly, we call it fusionized). When an application is compiled with VC 2005,
VC will automatically create a manifest for it, and set it to depend on VC80
CRT. In order for the application to run, you have to install VC80 CRT in the
machine first.

A common mistake is to xcopy the application to a different machine without
installing the VC80 CRT redist in that machine.

A different common mistake is to compile the application in debug mode, and
try to use the application in a machine with only retail VC80 CRT redist
installed. Application compiled in debug mode will depend on the debug version
of VC80 CRT, and there is no redist for it.

In both cases, the application will not launch due to Sxs failure (not able
to find VC80 CRT.). We will use the second case as the example in our
discussion.

So we have a test application.

(Click
to enlarge)

The test application is compiled in debug mode, thus it depends on debug
version of VC80 CRT.

(Click
to enlarge)

Let’s try it on Windows XP.

Run it in cmd.exe.

(Click to enlarge)

(Text: The system cannot execute the specified
program.)

Ok, the system cannot execute the specified program. That is not helpful.

Let’s try again with explorer.

(Click
to enlarge)

(Text: This application has failed to start because the
application configuration is incorrect. Reinstalling the application may fix
this problem.)

Hmm, a little better, but still not helpful. Application configuration is
incorrect. What application configuration? Reinstall the application may fix the
problem, how?

Actually, the message we see in the explorer error dialog is the standard
error message for Win32 error SXS_CANT_GEN_ACTCTX. Cmd.exe does not understand
this error, so it shows a generic error message.

Whenever there is a Sxs failure, Sxs always logs information to system event
log with source SideBySide. In our case, Sxs logs three messages to system event
log.

(Click
to enlarge)

In other cases, Sxs may log more (or less) messages. The oldest message
usually contains the more direct information on what exactly is the failure.
Other messages typically just repeat the same information, or more generalized
information. You should always read the oldest message relevant to the failure
to find the cause of the Sxs failure.

In our case, the three messages are identical

(Click
to enlarge)

It tells us that Sxs cannot generate activation context for
test.exe.manifest, and the reason is that some referenced assembly is not
installed. In our case, since we only have one dependency, so we know VC80 Debug
CRT is not installed. In the case when we have multiple dependencies, we still
don’t know which dependency is missing.

OK. Enough about Windows XP. Let’s try it on the latest and greatest Windows
Vista.

First, run it in cmd.exe.

(Click
to enlarge)

(Text: The application has failed to start because its
side-by-side configuration is incorrect. Please see the application event log
for more detail.)

Much better. It tells us that there is a Sxs problem, and directs us to the
application event log for more information.

(note, in Windows Vista, due to a security change, Sxs can no longer write to
the system event log. So the information is written to the application event
log.)

Let’s open the event viewer.

(Click
to enlarge)

Here it is. There is one message with source SideBySide. And it tells us what
exactly the problem is: Dependent assembly VC80 debug CRT cannot be found. Even
better, it tells us to use sxstrace.exe for detailed diagnosis.

(I created a custom view to only show SideBySide messages in event viewer.
You should look for messages from source SideBySide under Windows
Logs\Application.)

So what is the sxstrace.exe thing?

Recall that in .Net framework, fusion binding log is the ultimate diagnosis
tool for assembly binding failure. Sxstrace is basically the same idea. We want
to show exactly how Sxs is searching for the dependencies so you can figure out
how to fix the problem.

Fusion binding log is using a custom log format --- HTML and the file is
stored in internet explorer cache by default. Sxstrace uses the ETW model.

ETW model has three components: Controller, Providers, and Consumers. In our
case, sxstrace.exe is both the controller and the consumer, and Sxs is the
provider.

Sxstrace.exe is shipped in Windows Vista and resides in %windir%\system32.

Here is the usage for sxstrace.exe:

(Click
to enlarge)

To see the Sxs tracing, we have to enable the trace first.

(Click
to enlarge)

(Enable tracing requires admin privilege. You have to run sxstrace.exe in an
elevated cmd.exe window.)

Now let’s run the test application, and stop the tracing.

The trace generated is a binary file. We have to translate it to human
readable text.

(Click
to enlarge)

And here is the output:

(Click
to enlarge)

You can see exactly how Sxs probes for the dependent assembly VC80 debug CRT.

This concludes the article. I hope you find the Windows Vista experience
helpful to diagnose Sxs failures.

Published Friday, April 14, 2006 2:00 AM by junfeng
Filed
Under: Fusion, Win32

Comments

#
Interesting Finds

Friday, April 14, 2006
7:07 AM by Jason Haley

#
re: Diagnosing SideBySide failures

Sunday, April 16, 2006
11:30 PM by Norman
Diamond

I am really really glad to see these improvements.
Only one necessary improvement is still missing.

> Application
compiled in debug mode will
> depend on the debug version of VC80 CRT,

> and there is no redist for it.

Why doesn't this ever change?

Suppose Microsoft made cars.  It would be legal to use seat belts
on a test track in cars driven by test pilots, but it would be illegal to supply
or use seat belts in cars by end users.

#
re: Diagnosing SideBySide failures

Monday, April 17, 2006
12:53 AM by junfeng

Norman,

I don't own VC80 CRTs. You have to talk
to VC team.

#
re: Diagnosing SideBySide failures

Thursday, May 25, 2006
6:29 AM by Atul
Kulkarni (Chanakya)

This does not work with me. I can generate the etl file
but fail to generate the parsed txt from it. The tools crashes on me. with some
funny message saying it needs to send some information to Microsoft. I am like
ok great send it but how will I get the solution?????

Anyway it was
frustrating to go through this ordeal. If you can get me some reply please do
send them to [email-masked]

#
re: Diagnosing SideBySide failures

Thursday, June 01,
2006 2:57 PM by Jim McGowan

Hi Folks. I know absolutely nothing about .NET and/or
VC, but my Windows XP Pro machine is becoming non-responsive three or four times
a day and each time the event log has the same nine SxS errors listed with Event
IDs 32 and 59, referring to VC80.MFCLOC assembly not being found. Apparently
some application I installed has caused this, but I cannot determine which or
why.  Clueless, I have been searching for references to try to diagnose
just what is going wrong, and how to repair it. This is the first real
references I have found. Can anyone here point me toward any resources to help
get my PC back working? Your assistance is greatly appreciated! Thanks, Jim
McGowan - [email-masked]

#
re: Diagnosing SideBySide failures

Wednesday, July 12,
2006 3:21 PM by junfeng

Atul,

There are known bugs in sxstrace.exe. If
you can try the latest Vista build when it comes out that will be great.

#
Junfeng Zhang describing ways of diagnosing SxS failures

Monday, August 28,
2006 7:06 PM by Nikola Dudar's WebLog

Junfeng has an interesting walkthrough on how diagnose
SxS failures and brief introduction of new tool available on Vista. One may find
it here, http://blogs.msdn.com/junfeng/archive/2006/04/14/576314.aspx.

New Comments to this post are disabled