Implicit Styles = "Key cannot be null."???

11 posts, 0 answers
  1. David
    David avatar
    20 posts
    Member since:
    Nov 2015

    Posted 23 Sep Link to this post

    I'm working on converting my project to use Implicit Styles. I've followed the Documentation to a T. I'm using NoXAML binaries, I've copied the entire set of theme XAML files into my project, merged them all in the App.xaml file, etc.

    Everything I ask to use an implicit theme winds up throwing an error that says "Key cannot be null". Sometimes the entire designer is replaced with a window that says the same and gives a StackTrace. I've attached screenshots of both. 

    Can anyone give me some guidance here? Telerik doesn't release crappy broken components, so I'm assuming that I'm missing something easy.

    Humble me please.  :)

  2. Martin
    Admin
    Martin avatar
    60 posts

    Posted 27 Sep Link to this post

    Hello David,

    Thank you for contacting us on this issue.

    One way to use ImplicitStyles is to copy and manage the .xaml files on their own in your project or to refer them from the theme assembly with all the needed components (here is just a sample prieview): 
    <Application.Resources>
      <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
          <ResourceDictionary Source="/Telerik.Windows.Themes.Office_Black;component/Themes/System.Windows.xaml" />
          <ResourceDictionary Source="/Telerik.Windows.Themes.Office_Black;component/Themes/Telerik.Windows.Controls.xaml" />
          <ResourceDictionary Source="/Telerik.Windows.Themes.Office_Black;component/Themes/Telerik.Windows.Controls.Navigation.xaml" />
        </ResourceDictionary.MergedDictionaries>
      </ResourceDictionary>
    </Application.Resources>

    I am mentioning that because you might have missed a reference somewhere from the needed styles (some controls depend on styles from other groups - e.g. RadToolBar needs all the Buttons' and RadButtons styles etc).

    Furthermore, since you have made sure you are using all noXAML binaries for all the controls, you can try Cleaning the solution, then manually cleaning the contents of the bin and obj folders of the project(s) and Rebuilding them and restart the VisualStudio.

    If the error message persists and you are not receiving an exception when you run the project - you might need to clean the cache of the Designer. It caches the needed assemblies for quicker loading but in cases when they are switched, it might not replace them properly.

    You can try manually cleaning the ShadowCache folder - which is the cache for the assemblies for the designer. It is normally situated at:
    C:\Users\<user>\AppData\Local\Microsoft\VisualStudio\<version>\Designer\ShadowCache

    If you do that, you would need to close any instances of VisualStudio. It can be a of a great size, so cleaning it might take some time. On the next start, the Designer will take time to load, but it should work properly.

    However, if the exception persists, please do not hesitate to contact us again and if it possible, attach a sample project where the behavior manifests so we can examine it.

    Regards,
    Martin
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
  4. David
    David avatar
    20 posts
    Member since:
    Nov 2015

    Posted 28 Sep in reply to Martin Link to this post

    Hi Martin,

    Thanks for the response. I am completely baffled by what is going on. I created a blank project and everything works just fine. So I started copying all of my existing project over to the one to try and see what would cause it to break. It never broke. So then I figured it must be some project configuration issue. So I opened each project file in notepad and compared line by line and everything matches. 

    No matter what I do, I can't get the original project to work.

    My OCD isn't letting me drop this even though the new project works (I'm concerned the new project will work temporarily and then I'll do something to cause the same error again). Do you have any advice as to how I can debug this? I've attached the VS debugger to the XAML Designer and found that whenever I modify the Style attribute of one of the controls in question, a System.ArgumentNullException is thrown. The null value causing the exception is the resourceKey for the FrameworkElement (which is a TextBox in this case).

    I hope this helps.

  5. David
    David avatar
    20 posts
    Member since:
    Nov 2015

    Posted 28 Sep Link to this post

    Hi Martin,

    One other thing that may help you answer my question is that if use the Theme Assembly, everything works just fine. So it must be something to do with the actual XAML files. Does it matter which order I merge them in? 

    Sorry to be a pain. 

    Dave

  6. David
    David avatar
    20 posts
    Member since:
    Nov 2015

    Posted 28 Sep in reply to David Link to this post

    My gosh I'm sorry to spam this thread like this. I don't get the "key cannot be null" message. But the project is unable to resolve the stock styles contained within the Theme Assembly (e.g. The resource "TextBoxStyle" could not be resolved.). Here is my App.xaml file. I've referenced the Theme Assembly. Also, this only happens in the Designer. When I run the application everything looks just fine.

    <Application x:Class="PatchPro.Dispatch.App"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:local="clr-namespace:PatchPro.Dispatch"
                 StartupUri="Views/DispatchDockingView.xaml">
        <Application.Resources>
     
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary Source="/Telerik.Windows.Themes.Windows8;component/Themes/System.Windows.xaml"/>
                    <ResourceDictionary Source="/Telerik.Windows.Themes.Windows8;component/Themes/Telerik.Windows.Controls.Data.xaml"/>
                    <ResourceDictionary Source="/Telerik.Windows.Themes.Windows8;component/Themes/Telerik.Windows.Controls.Docking.xaml"/>
                    <ResourceDictionary Source="/Telerik.Windows.Themes.Windows8;component/Themes/Telerik.Windows.Controls.GridView.xaml"/>
                    <ResourceDictionary Source="/Telerik.Windows.Themes.Windows8;component/Themes/Telerik.Windows.Controls.Input.xaml"/>
                    <ResourceDictionary Source="/Telerik.Windows.Themes.Windows8;component/Themes/Telerik.Windows.Controls.Navigation.xaml"/>
                    <ResourceDictionary Source="/Telerik.Windows.Themes.Windows8;component/Themes/Telerik.Windows.Controls.Spreadsheet.xaml"/>
                    <ResourceDictionary Source="/Telerik.Windows.Themes.Windows8;component/Themes/Telerik.Windows.Controls.xaml"/>
                    <ResourceDictionary Source="/Telerik.Windows.Themes.Windows8;component/Themes/Telerik.Windows.Documents.xaml"/>
                    <ResourceDictionary Source="/Assets/Styles/UniversalStyles.xaml"/>
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
     
        </Application.Resources>
    </Application>

  7. Martin
    Admin
    Martin avatar
    60 posts

    Posted 30 Sep Link to this post

    Hello David,

    It could be the order of merging as some styles depend on other styles from more basic assemblies. I can suggest you move the Controls.xaml dictionary in the beginning after System.Windows.xaml. It might solve the issue. 

    Normally cleaning the cache in obj and bin folders of the project, restarting VS and rebuilding should sort that issue if it has something to do with wrong cached assemblies.

    I cannot reproduce this for now, so could I ask you if the issue still persists to either list the controls you are using in your project or send a sample code or project where this error occurs, so we can investigate it further. 

    Regards,
    Martin
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  8. David
    David avatar
    20 posts
    Member since:
    Nov 2015

    Posted 30 Sep in reply to Martin Link to this post

    Is there a way to send you my project without posting it publicly on these forums?
  9. David
    David avatar
    20 posts
    Member since:
    Nov 2015

    Posted 30 Sep Link to this post

    Solved...sort of.

    After hours of looking for what was causing that "Key cannot be null" exception, I decided to upgrade my project from .NET 4.5.2 to 4.6.1. Whatever was going on resolved immediately which is bizarre.

    Just prior to upgrading I was in the process of debugging the Designer with the .NET Framework source code. From what I could gather something was going on within System.Windows.xaml and it had to do with a ScrollViewer. 

    No idea if that's of any use to you guys at Telerik. 

    Thanks for trying to help though, much appreciated.

     

  10. Martin
    Admin
    Martin avatar
    60 posts

    Posted 04 Oct Link to this post

    Hi David,

    It is true that the threads here are public. You can open a Support thread, which will be private and you can attach a project there.

    It could be a problem with cached assemblies either in the project or in the designer cache (the Shadow Cache folder), since the problem is resolved by changing the .NET version.

    Regards,
    Martin
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  11. David
    David avatar
    20 posts
    Member since:
    Nov 2015

    Posted 04 Oct in reply to Martin Link to this post

    I don't think it had to do with caching as I cleared the bin/obj folders as well as the ShadowCache folder multiple times. But it is awfully suspicious that changing the version fixed it.

    Anyhow, thanks for the suggestions.

  12. Martin
    Admin
    Martin avatar
    60 posts

    Posted 06 Oct Link to this post

    Hi David,

    Thank you for your cooperation. I am as well unaware of the possible cause of the problem.

    I am pleased that the issue is resolved on your side. I will look into that. 
    If you feel the need, you can open a support thread to attach sample project where the issue is isolated.

    Please do not hesitate to contact us further, if you are facing problems with the usage of our controls.

    Regards,
    Martin
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for WPF is Visual Studio 2017 Ready