8

I have a problem that has puzzled me for some time now. On a WPF/.NET 3.5 product I have released, about 1 out of 100 installs will not be able to run the software at all due to the following error:

System.Windows.Markup.XamlParseException: Failed object initialization (ISupportInitialize.EndInit). The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) Error at object 'System.Windows.Controls.MenuItem' in markup file 'mainwindow.xaml'.

This is puzzling for three reasons:

  1. This only happens on about 1 to 2 percent of installs.

  2. There is nothing unusual as far as I can tell about the .NET installations or OS on these systems.

  3. This is happening with a default framework reference (System.Windows.Controls.MenuItem)

Can anyone think of possible causes for this?

EDIT: After following the tip from "500", I was able to run the Fusion log viewer on the customer machine. On the development machine and all other test machines, there are successful binding attempts on "PresentationFramework" and "PresentationFramework.Aero", which are expected. On the client machine, there is an additional binding attempt that fails (Irrelevant lines removed):

*** Assembly Binder Log Entry  (2/3/2013 @ 1:18:44 PM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = PresentationFramework.Dawn TOP, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
 (Fully-specified)
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = NULL
Calling assembly : PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in default load context.
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Post-policy reference: PresentationFramework.Dawn TOP, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/My App/PresentationFramework.Dawn TOP.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/My App/PresentationFramework.Dawn TOP/PresentationFramework.Dawn TOP.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/My App/PresentationFramework.Dawn TOP.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/My App/PresentationFramework.Dawn TOP/PresentationFramework.Dawn TOP.EXE.
LOG: All probing URLs attempted and failed.

A Google search for "PresentationFramework.Dawn" returns no results and I cannot locate any reference to this file. Any explanation or additional tests that can be done?

EDIT 2: It turns out that the customer had installed an unofficial Windows 7 Aero theme called "Dusk". For some reason, PresentationFramework decided to make a call to PresentationFramework.Dusk instead of PresentationFramework.Aero (a reference that I explicitly included in the project). I'm assuming that the error is the result of a bad installation of the 3rd party theme since Dusk cannot be found in the GAC, but can you shed any light on how I might stop the reference from being attempted and force all GUI elements to use PresentationFramework.Aero?

Ben McIntosh
  • 1,532
  • 3
  • 20
  • 29
  • Sounds like an issue with the build or deployment. Maybe something related to .NET versioning? Do your build machine or clients have 4.5 installed? – John Bowen Jan 30 '13 at 13:42
  • The build machine does not have 4.5 installed and clients with and without 4.5 have reported the same error. – Ben McIntosh Jan 30 '13 at 22:07
  • I'm surprised having a custom OS theme would cause a crash. I mean it would cause the binding error but that is because WPF will look for a resourcedictionary that matches the OS theme. Since PresentationFramework declares that its theme files are in external assemblies it will try to load an assembly with that name. That should fail but WPF is set up to handle that. It will then fallback to loading the "classic" OS theme and using that as the default resourcedictionary for the classes. – AndrewS Feb 07 '13 at 14:22
  • BTW is there an inner exception message to the exception you're getting? Do you get a problem if you just create a brand new app that just contains a Menu with some MenuItems and run it on the systems on which your app fails? – AndrewS Feb 07 '13 at 14:29

2 Answers2

3

On those machines where it fails, run the Assembly Binding Log Viewer to gain a better understanding of why it's going off the rails.

  • Is there a standardized way to do this on a customer machine that does not have VS installed? – Ben McIntosh Feb 01 '13 at 18:30
  • See this question (should have found that earlier actually): http://stackoverflow.com/questions/1012252/using-fuslogvw-exe-on-a-machine-with-no-visual-studio-installed – 500 - Internal Server Error Feb 01 '13 at 18:42
  • Dawn in this context sounds like a custom WPF theme (Aero is an example of a standard theme name) that your application is referring to. Do you have any references to Dawn in your XAML? – 500 - Internal Server Error Feb 04 '13 at 05:31
  • No, the word "dawn" does not appear anywhere in the solution (find in files). Is there any tool that you are aware of that can track down the reason a binding attempt is made? Also, remember that this reference binding is not even attempted on my test machines. – Ben McIntosh Feb 04 '13 at 06:59
  • Second edit above... any insight would be much appreciated to keep this from happening again. – Ben McIntosh Feb 07 '13 at 06:31
3

In your application you can specify which Theme you want to use to force another theme than the system theme.

This code needs to be added to your ApplicationStartUp event

void App_Startup(object sender, StartupEventArgs e) {
  // other startup code
  Uri uri = new Uri(“PresentationFramework.Aero;V3.0.0.0;31bf3856ad364e35;component\\themes/aero.normalcolor.xaml”, UriKind.Relative);

  Resources.MergedDictionaries.Add(Application.LoadComponent(uri) as ResourceDictionary);
}

You can also define your Theme in XAML:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source=“/PresentationFramework.Aero;V3.0.0.0;31bf3856ad364e35;component\themes/aero.normalcolor.xaml“ />
        </ResourceDictionary.MergedDictionaries>

        <!– other resources go here –>

    </ResourceDictionary>
</Application.Resources>

This setting defines that you want to use the Aero theme. (Maybe you need to change the version and the public key token you want to use).

Further information can be found here.

Jehof
  • 34,674
  • 10
  • 123
  • 155