简体   繁体   中英

Problems with save operation in Visual Studio VSIX custom editor and .Net 6.0 Web application projects

We have built a Visual Studio Extension (VSIX). It is a custom editor for editing a special file that contains definitions for the datamodel in our CMS.

We are porting our CMS to.Net 6.0 from.Net 4.8 ( framework -> core ), however we are struggling getting the editor to work in.Net 6.0 projects. It works fine in web applications written in.Net 4.8, but not in.Net 6.0 web application projects.

Whenever we click the save button in Visual Studio, we get a very general and non specific error message that says: "The operation could not be completed. Unspecified error"

在此处输入图像描述

We run the extension with source code in debug mode using the Visual Studio SDK, and there is no exception that is picked up by Visual Studio. ( We use one Visual Studio instance to start another instance of Visual Studio in debug mode, as normal with VSIX projects). Breakpoints etc. work, and we have activated all exceptions in the debugger. When we click save in Visual Studio projects, we get the error message before any method is called in our code. We do not even enter the "IVsPersistDocData2.SaveDocData" method of the "WindowPane" class. The plugin is written in C#. Apart from save, everything works fine. The editor loads fine and function as normal in both types of projects.

There must be some difference in the way the extension integrates with Visual Studio that differ between.Net4.8 projects and.Net6.0 projects. Of course, there are differences in file paths etc in these projects, but I do not see how this is the root of the problem as we do not even get to the stage where any method is called in our editor source code.

As a test I created a very simple extension with only the bare minimum to enable a WindowPane extension, and I get the same error message when saving in 6.0 projects

We created the first version of the plugin back in 2013, using templates from Microsoft and have been updating it for every new version of Visual Studio. There have been some changes in the documentation and projects templates for VSIX, but unfortunately, there is no longer any C# template for custom editors, only C++. ( https://docs.microsoft.com/en-us/visualstudio/extensibility/walkthrough-creating-a-custom-editor?view=vs-2022 ) Pherhaps someone knows any workings examples of custom editors written in c#?

So, we are a little stuck, the error message does not give us any clue to what is wrong. I have not found any documentation that could explain differences in Net 4.8 and Net 6.0 web projects that could cause this.

Anyone had a similar problem? Or perhaps a clue to what is causing this.

(BTW, we are using the latest version of Visual Studio 2022 Community and Windows 11)

After opening a support incident with Microsoft, further investigation and live debugging pointed to problems with VisualStudio.ProjectSystem.VS.Implementation.Package.ProjectNode.SaveItem and a possible internal bug in Visual Studio.

A temporary workaround suggested by Microsoft support, was to add the definition of IPersistFileFormat to the WindowPane implementation. ( None of the methods needed to be implemented. )

This solved the problem for us. The definition of our working WindowPane is now:

public sealed class OntologyDesignerEditorPane: WindowPane, IVsPersistDocData2, IPersistFileFormat, IVsFileChangeEvents

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM