0

Using VS2019, I have created a VSTO AddIn WORD project. As we know the default template of this project creates a ThisAddIn class with two events ThisAddIn_Startup and ThisAddIn_Shutdown but no constructor. But when I try to create a constructor of this class as follows, I get the following error:

public ThisAddIn()
{
}

Error:

there is no argument given that corresponds to the required formal parameter 'factory' of 'AddInBase.AddinBase(Factory, IserviceProvider, string, string)'

Question: What is the cause of this error and how can I create a constructor in ThisAddIn class?

Some Background: I am trying to mimic functionalities of a Winform (Windows Forms) project into a VSTO office project. The Winform project has some code inside its constructor Form(){...} that I need to implement inside the constructor of ThisAddIn class of VSTO projects.

nam
  • 21,967
  • 37
  • 158
  • 332
  • Did you notice that ThisAddin is a partial class (look the file ThisAddin.Designer.cs) ? you can just create a constructor in the same way.ThisAddin is based on AddInBase that requires the 4 arguments. You may also try to override AddInBase.BeginInit . – Malick Apr 11 '20 at 19:00
  • @Malick Good point. How do I access `ThisAddin.Designer.cs`? In my `VS2019` VSTO project it's only showing `ThisAddin.cs` under `Word` folder. – nam Apr 11 '20 at 20:21
  • We are not supposed to modify it because it is auto-generated. You can navigate to if via `CTRL` + `,` (https://stackoverflow.com/questions/1508973/how-to-search-for-file-names-in-visual-studio ) and enter `ThisAddin.Designer.cs` . It is not available via the solution explorer. It is just usefull to understand the class. I believe you could try to implement your code inside BeginInit. – Malick Apr 11 '20 at 23:25

0 Answers0