2

I am developing an extension for Visual Studio that uses DialogWindow from the Microsoft.VisualStudio.PlatformUI namespace. My window looks something along the lines of this:

...
using Microsoft.VisualStudio.PlatformUI

namespace views
{
    public partial class MyDialog : DialogWindow
    {
        public MyDialog()
        {
            ...
            InitializeComponent();
        }
    }
    ...
}

And my xaml looks something like this:

<platformUI:DialogWindow
        ...
        xmlns:platformUi="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.14.0"
        ...>
    ...
</platformUi:DialogWindow>

I my issue arises when this window is constructed in an Nunit test case. This exception is thrown once InitializeComponent() is called:

Message: System.Windows.Markup.XamlParseException : Provide value on 'System.Windows.Markup.StaticExtension' threw an exception.
  ----> System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
  ----> System.NotSupportedException : Microsoft.VisualStudio.Shell.Interop.SVsSettingsManager

The window is constructed in the Nunit setup method, but only the first method to construct the window throws this exception. I assume subsequent calls to InitializeComponent() don't go through for whatever reason, so the subsequent test still pass.

I am guessing the reason why this exception is thrown is because DialogWindow isn't meant to be used outside the context of Visual Studio, but I hope there is a solution to this as it would be difficult to remove this construction from the unit test. Does anyone have any ideas on how I can fix this?

WRJohnson
  • 21
  • 3
  • See for exsample this [https://stackoverflow.com/questions/56567075/how-to-run-nunit-test-in-sta-thread](https://stackoverflow.com/questions/56567075/how-to-run-nunit-test-in-sta-thread) – dostavka2008 Jun 13 '23 at 11:35

0 Answers0