-3

We have created solution like the one below and added the default project after creating solution. Please refer code below

        Type visualStudioType = Type.GetTypeFromProgID("VisualStudio.DTE.12.0", true);
        DTE env = Activator.CreateInstance(visualStudioType, true) as DTE;
        ServiceProvider serviceProvider = new ServiceProvider(env as Microsoft.VisualStudio.OLE.Interop.IServiceProvider);
        DTE dte = (DTE)serviceProvider.GetService(typeof(DTE));
        Object obj = System.Activator.CreateInstance(visualStudioType, true);

        EnvDTE80.DTE2 dte8Obj = (EnvDTE80.DTE2)obj;

        Solution2 soln = (Solution2)dte8Obj.Solution;

1.I get exception like below, When create project solution.

Solution explorer Exception

2.After create project, We cannot able to convert project as VSProject. Its showing exception like below.

Exception when convert project as vsproject

Please give solution for resolve above mention issues .

Community
  • 1
  • 1
Dheepa
  • 1
  • 2

1 Answers1

0

Your code can be simplified to:

Type visualStudioType = Type.GetTypeFromProgID("VisualStudio.DTE.12.0", true);

EnvDTE80.DTE2 dte2 = Activator.CreateInstance(visualStudioType, true) as EnvDTE80.DTE2;

EnvDTE80.Solution2 soln = dte2.Solution as EnvDTE80.Solution2;

Regarding the error locating EnvDTE version 7.0.3300.0 see:

Error When EnvDTE Is Used with VSLangProj Assemblies

Carlos Quintero
  • 4,300
  • 1
  • 11
  • 18
  • Hi Carrlos, Thanks for your response. I have tried to add app.config file like above your suggested, But issue not resolved. – Dheepa Jan 05 '17 at 06:30
  • Hi Carrlos, I have tried to create project using above your suggest code snippet . But I get below mention errors randomly, 1).System.Runtime.InteropServices.COMException (0x80080005): Retrieving the COM class factory for component with CLSID {656D8328-93F5-41A7-A48C-B42858161F25} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)). 2)."RPC server is unavailable.(Exception from HRESULT:0x800706BA)" Can you please suggest how to resolve above mention issues ? " Best Regards, – Dheepa Jan 05 '17 at 09:20