Getting IOException: Cannot locate resource 'themes/themeresources.xaml' error when trying to show a dialog in an Extension.

Jim Locigno 20 Reputation points
2023-12-31T17:12:02.21+00:00

I'm still trying to learn the VSIX stuff - and I'm still doing in process extensions (since I think out of process extension are still in preview).

But I am trying to show a Dialog in a Visual Studio extension and I get this error:

System.Windows.Markup.XamlParseException
  HResult=0x80131501
  Message='Initialization of 'VSIXProject13.MyCustomDialog' threw an exception.' Line number '19' and line position '7'.
  Source=PresentationFramework
  StackTrace:
   at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)

  This exception was originally thrown at this call stack:
    MS.Internal.AppModel.ResourcePart.GetStreamCore(System.IO.FileMode, System.IO.FileAccess)
    System.IO.Packaging.PackagePart.GetStream(System.IO.FileMode, System.IO.FileAccess)
    System.IO.Packaging.PackWebResponse.CachedResponse.GetResponseStream()
    System.IO.Packaging.PackWebResponse.ContentType.get()
    MS.Internal.WpfWebRequestHelper.GetContentType(System.Net.WebResponse)
    System.Windows.ResourceDictionary.Source.set(System.Uri)
    Community.VisualStudio.Toolkit.Themes.MergeStyles(System.Windows.FrameworkElement)
    Community.VisualStudio.Toolkit.Themes.OnElementInitialized(object, System.EventArgs)
    System.Windows.FrameworkElement.RaiseInitialized(System.Windows.EventPrivateKey, System.EventArgs)
    System.Windows.FrameworkElement.TryFireInitialized()
    ...
    [Call Stack Truncated]

Inner Exception 1:
IOException: Cannot locate resource 'themes/themeresources.xaml'.

I have searched google and everything else and found nothing relevant. This dialog I have now is completely "empty" , this was done to narrow down the issue. But even the empty dialog I still get this error:

Extension Code:

> global using Community.VisualStudio.Toolkit;
> global using Microsoft.VisualStudio.Shell;
> global using System;
> global using Task = System.Threading.Tasks.Task;
> using EnvDTE;
> using EnvDTE80;
> using Microsoft;
> using Microsoft.VisualStudio;
> using System.Diagnostics;
> using System.IO;
> using System.Runtime.InteropServices;
> using System.Threading;
> using System.Windows.Threading;
> namespace VSIXProject13
> {
>     [ProvideAutoLoad(VSConstants.UICONTEXT.SolutionExists_string, PackageAutoLoadFlags.BackgroundLoad)]
>     [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
>     [InstalledProductRegistration(Vsix.Name, Vsix.Description, Vsix.Version)]
>     [ProvideMenuResource("Menus.ctmenu", 1)]
>     [Guid(PackageGuids.VSIXProject13String)]
>     public sealed class VSIXProject13Package : ToolkitPackage
>     {
>         public const string PackageGuidString = "bcf67d7a-8e10-4fe5-af47-2fa32560656a";
>         private DTE2 _dte;
>         protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
>         {
>             await this.RegisterCommandsAsync();
>             await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
>             await base.InitializeAsync(cancellationToken, progress);
>             _dte = (DTE2)await GetServiceAsync(typeof(DTE));
>             Assumes.Present(_dte);
>             _dte.Events.CommandEvents.BeforeExecute += OnBeforeCommandExecute;
>         }
>         private void OnBeforeCommandExecute(string Guid, int ID, object CustomIn, object CustomOut, ref bool CancelDefault)
>         {
>             if (ID == 234) //View Solution explorer is command id=234
>             {
>                 var test = new MyDialogWindow1();
>                 var result = test.ShowDialog();
>             }
>         }
>         private void OnBeginShutdown()
>         {
>             // Clean up resources and unregister event handlers
>             _dte.Events.DTEEvents.OnBeginShutdown -= OnBeginShutdown;
>             _dte.Events.CommandEvents.BeforeExecute -= OnBeforeCommandExecute;
>             //_dte.Events.CommandEvents.AfterExecute -= OnAfterCommandExecute;
>         }
>     }
> }
> ```


```powershell
> global using Community.VisualStudio.Toolkit;
> global using Microsoft.VisualStudio.Shell;
> global using System;
> global using Task = System.Threading.Tasks.Task;
> using EnvDTE;
> using EnvDTE80;
> using Microsoft;
> using Microsoft.VisualStudio;
> using System.Diagnostics;
> using System.IO;
> using System.Runtime.InteropServices;
> using System.Threading;
> using System.Windows.Threading;
> 
> namespace VSIXProject13
> {
>     [ProvideAutoLoad(VSConstants.UICONTEXT.SolutionExists_string, PackageAutoLoadFlags.BackgroundLoad)]
>     [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
>     [InstalledProductRegistration(Vsix.Name, Vsix.Description, Vsix.Version)]
>     [ProvideMenuResource("Menus.ctmenu", 1)]
>     [Guid(PackageGuids.VSIXProject13String)]
>     public sealed class VSIXProject13Package : ToolkitPackage
>     {
> 
>         public const string PackageGuidString = "bcf67d7a-8e10-4fe5-af47-2fa32560656a";
>         private DTE2 _dte;
> 
> 
>         protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
>         {
> 
>             await this.RegisterCommandsAsync();
> 
>             await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
> 
>             await base.InitializeAsync(cancellationToken, progress);
> 
>             _dte = (DTE2)await GetServiceAsync(typeof(DTE));
>             Assumes.Present(_dte);
> 
>             _dte.Events.CommandEvents.BeforeExecute += OnBeforeCommandExecute;
>         }
> 
> 
>         private void OnBeforeCommandExecute(string Guid, int ID, object CustomIn, object CustomOut, ref bool CancelDefault)
>         {
> 
>             if (ID == 234) //View Solution explorer is command id=234
>             {
> 
>                 var test = new MyDialogWindow1();
>                 var result = test.ShowDialog();
> 
> 
>             }
> 
> 
> 
> 
>         }
> 
> 
> 
> 
>         private void OnBeginShutdown()
>         {
>             // Clean up resources and unregister event handlers
>             _dte.Events.DTEEvents.OnBeginShutdown -= OnBeginShutdown;
>             _dte.Events.CommandEvents.BeforeExecute -= OnBeforeCommandExecute;
>             //_dte.Events.CommandEvents.AfterExecute -= OnAfterCommandExecute;
>         }
>     }
> }
> 
> 
Dialog code (created with Dialog Window (Community) template:


xml
<platform:DialogWindow  x:Class="VSIXProject13.MyDialogWindow1"
                        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                        xmlns:platform="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.15.0"
                        xmlns:toolkit="clr-namespace:Community.VisualStudio.Toolkit;assembly=Community.VisualStudio.Toolkit"
                        toolkit:Themes.UseVsTheme="True"
                        mc:Ignorable="d"
                        Width="600"
                        Height="400"
                        d:DesignHeight="600"
                        d:DesignWidth="400">
    <Grid>

    </Grid>
</platform:DialogWindow>

Visual Studio Extensions
Visual Studio Extensions
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Extensions: A program or program module that adds functionality to or extends the effectiveness of a program.
189 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Anna Xiu-MSFT 27,636 Reputation points Microsoft Vendor
    2024-01-02T07:40:22.2766667+00:00

    Hi @Jim Locigno ,

    It may be related to the Community.VisualStudio.Toolkit.

    You can try to update the NuGet package to the latest version 17.0.507. You can see the similar issue:

    "themes/themeresources.xaml is missing" error on 17.0.430 · Issue #322 · VsixCommunity/Community.VisualStudio.Toolkit · GitHub 

    Sincerely,

    Anna


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

     

    1 person found this answer helpful.
    0 comments No comments