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>