System.Runtime.InteropServices.COMException when calling AddFromTemplate

Rudolf Meier 291 Reputation points
2024-04-19T13:54:03.79+00:00

I have written a VS extension (for 2019). It shows a menu point. When it is clicked, I execute this code:

private void Execute(object sender, EventArgs e)
{
ThreadHelper.ThrowIfNotOnUIThread();

dte.SelectedItems.Item(1).Project.ProjectItems.AddFromTemplate("path to vstemplate for a dialog", "TestDialog");

}

Now... this works. It does show the wizard for this template. It does create and add the dialog (or whatever this template should do) ... it does also work for other templates. Everything fine... except, that I get an unhandled System.Runtime.InteropServices.COMException after the call. And... I don't understand why. Is this normal? Do I have to catch it? Is it because of something I'm not doing? ... what is it?

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,176 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.