What is wrong with my Themes dictionary?

Mar 3, 2009 at 2:00 PM
Edited Mar 3, 2009 at 2:32 PM
When I do this:

  if self.FindResource( 'MyThemeDictionary' ) = nil
     then MessageBox.Show( 'nope' )
     else MessageBox.Show( 'gotit' );

using this:

  <Application.Resources>
      <eco:EcoServiceProviderReference x:Key="ecoServiceProviderRef"></eco:EcoServiceProviderReference>
      <ResourceDictionary x:Key="MyThemeDictionary">
         <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/PresentationFramework.Aero;component/themes/Aero.NormalColor.xaml"/>
            <ResourceDictionary Source="/PresentationFramework.Classic;component/themes/Classic.xaml"/>
            <ResourceDictionary Source="/PresentationFramework.Royale;component/themes/Royale.NormalColor.xaml"/>
            <ResourceDictionary Source="/PresentationFramework.Luna.Homestead;component/themes/Luna.Homestead.xaml"/>
            <ResourceDictionary Source="/PresentationFramework.Luna.Metallic;component/themes/Luna.Metallic.xaml"/>
            <ResourceDictionary Source="/PresentationFramework.Zune;component/themes/Zune.NormalColor.xaml"/>
         </ResourceDictionary.MergedDictionaries>
      </ResourceDictionary>
  </Application.Resources>

I get:
System.Windows.Markup.XamlParseException occurred
  Message="'/PresentationFramework.Classic;component/themes/Classic.xaml' value cannot be assigned to property 'Source' of object 'System.Windows.ResourceDictionary'. Could not load file or assembly 'PresentationFramework.Classic, Culture=neutral' or one of its dependencies. The system cannot find the file specified.  Error at object 'System.Windows.ResourceDictionary' in markup file 'PersonalPlan;component/app.xaml' Line 14 Position 33."
  Source="PresentationFramework"
  LineNumber=14
  LinePosition=33
  NameContext="MergedDictionaries"
  StackTrace:
       at System.Windows.Markup.XamlParseException.ThrowException(String message, Exception innerException, Int32 lineNumber, Int32 linePosition, Uri baseUri, XamlObjectIds currentXamlObjectIds, XamlObjectIds contextXamlObjectIds, Type objectType)
       at System.Windows.Markup.XamlParseException.ThrowException(ParserContext parserContext, Int32 lineNumber, Int32 linePosition, String message, Exception innerException)
       at System.Windows.Markup.BamlRecordReader.ThrowExceptionWithLine(String message, Exception innerException)
       at System.Windows.Markup.BamlRecordReader.ReadPropertyRecordBase(String attribValue, Int16 attributeId, Int16 converterTypeId)
       at System.Windows.Markup.BamlRecordReader.ReadPropertyConverterRecord(BamlPropertyWithConverterRecord bamlPropertyRecord)
       at System.Windows.Markup.BamlRecordReader.ReadRecord(BamlRecord bamlRecord)
       at System.Windows.Markup.BamlRecordReader.ReadElement(Int64 startPosition, XamlObjectIds contextXamlObjectIds, Object dictionaryKey)
       at System.Windows.ResourceDictionary.CreateObject(Int32 valuePosition, Object key)
       at System.Windows.ResourceDictionary.RealizeDeferContent(Object key, Object& value, Boolean& canCache)
       at System.Windows.ResourceDictionary.GetValueWithoutLock(Object key, Boolean& canCache)
       at System.Windows.ResourceDictionary.GetValue(Object key, Boolean& canCache)
       at System.Windows.ResourceDictionary.FetchResource(Object resourceKey, Boolean allowDeferredResourceReference, Boolean mustReturnDeferredResourceReference, Boolean& canCache)
       at System.Windows.Application.FindResourceInternal(Object resourceKey, Boolean allowDeferredResourceReference, Boolean mustReturnDeferredResourceReference)
       at System.Windows.FrameworkElement.FindResourceInternal(FrameworkElement fe, FrameworkContentElement fce, DependencyProperty dp, Object resourceKey, Object unlinkedParent, Boolean allowDeferredResourceReference, Boolean mustReturnDeferredResourceReference, DependencyObject boundaryElement, Boolean isImplicitStyleLookup, Object& source)
       at System.Windows.FrameworkElement.FindResourceInternal(FrameworkElement fe, FrameworkContentElement fce, Object resourceKey)
       at System.Windows.FrameworkElement.FindResource(Object resourceKey)
       at PersonalPlan.MainWindow.MenuItem_Click_1(Object sender, RoutedEventArgs e) in C:\Users\mtiede\Documents\Visual Studio 2008\Projects\SW\Personal Plan\WPFApp\PersonalPlan\PersonalPlan\MainWindow.xaml.pas:line 39
  InnerException: System.IO.FileNotFoundException
       Message="Could not load file or assembly 'PresentationFramework.Classic, Culture=neutral' or one of its dependencies. The system cannot find the file specified."
       Source="mscorlib"
       FileName="PresentationFramework.Classic, Culture=neutral"
       FusionLog="=== Pre-bind state information ===\r\nLOG: User = Den-PC\\mtiede\r\nLOG: DisplayName = PresentationFramework.Classic, Culture=neutral\n (Partial)\r\nLOG: Appbase = file:///C:/Users/mtiede/Documents/Visual Studio 2008/Projects/SW/Personal Plan/WPFApp/PersonalPlan/PersonalPlan/bin/Debug/\r\nLOG: Initial PrivatePath = NULL\r\nCalling assembly : PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.\r\n===\r\nLOG: This bind starts in default load context.\r\nLOG: Using application configuration file: C:\\Users\\mtiede\\Documents\\Visual Studio 2008\\Projects\\SW\\Personal Plan\\WPFApp\\PersonalPlan\\PersonalPlan\\bin\\Debug\\PersonalPlan.exe.config\r\nLOG: Using machine configuration file from C:\\Windows\\Microsoft.NET\\Framework\\v2.0.50727\\config\\machine.config.\r\nLOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).\r\nLOG: Attempting download of new URL file:///C:/Users/mtiede/Documents/Visual Studio 2008/Projects/SW/Personal Plan/WPFApp/PersonalPlan/PersonalPlan/bin/Debug/PresentationFramework.Classic.DLL.\r\nLOG: Attempting download of new URL file:///C:/Users/mtiede/Documents/Visual Studio 2008/Projects/SW/Personal Plan/WPFApp/PersonalPlan/PersonalPlan/bin/Debug/PresentationFramework.Classic/PresentationFramework.Classic.DLL.\r\nLOG: Attempting download of new URL file:///C:/Users/mtiede/Documents/Visual Studio 2008/Projects/SW/Personal Plan/WPFApp/PersonalPlan/PersonalPlan/bin/Debug/PresentationFramework.Classic.EXE.\r\nLOG: Attempting download of new URL file:///C:/Users/mtiede/Documents/Visual Studio 2008/Projects/SW/Personal Plan/WPFApp/PersonalPlan/PersonalPlan/bin/Debug/PresentationFramework.Classic/PresentationFramework.Classic.EXE.\r\n"
       StackTrace:
            at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
            at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
            at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
            at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
            at System.Windows.Navigation.BaseUriHelper.GetLoadedAssembly(String assemblyName, String assemblyVersion, String assemblyKey)
            at MS.Internal.AppModel.ResourceContainer.GetResourceManagerWrapper(Uri uri, String& partName, Boolean& isContentFile)
            at MS.Internal.AppModel.ResourceContainer.GetPartCore(Uri uri)
            at System.IO.Packaging.Package.GetPartHelper(Uri partUri)
            at System.IO.Packaging.Package.GetPart(Uri partUri)
            at System.IO.Packaging.PackWebResponse.CachedResponse.GetResponseStream()
            at System.IO.Packaging.PackWebResponse.GetResponseStream()
            at System.IO.Packaging.PackWebResponse.get_ContentType()
            at MS.Internal.WpfWebRequestHelper.GetContentType(WebResponse response)
            at MS.Internal.WpfWebRequestHelper.GetResponseStream(WebRequest request, ContentType& contentType)
            at System.Windows.ResourceDictionary.set_Source(Uri value)
       InnerException:


Under Vista, if I remove all but the Aero, it works fine, but when I add any of the others (well, I only tested Classic and Luna.Homestead), I get an error that says it can't find the file.

Am I doing it wrong, or is there some way to suppress the error when it doesn't find it?

I assume the problem is that the other themes aren't part of Vista, but I'm just guessing.  I put them in there in case the app ran under XP.
Apr 30, 2009 at 8:43 AM
Try to add vesrion and token information in the resource dictionary. e.g. <ResourceDictionary Source="/PresentationFramework.Classic;V3.0.0.0;31bf3856ad364e35;component/themes/classic.xaml" />
Apr 6, 2010 at 2:56 PM

Thanks cartoixa, that solved a similar problem I had.