2015-10-22 1 views
0

Je suis un exemple de code dans le lien this.Impossible d'initialiser l'objet DTE

je frappe un droit accroc sur la deuxième ligne:

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 
//using EnvDTE; 

namespace TwinCAT_Automation_Interface 
{ 
    public partial class Main : Form 
    { 
     public Main() 
     { 
      InitializeComponent(); 
     } 

     //Creating TwinCAT Projects via templates (Recommended) 
     Type  myType = System.Type  .GetTypeFromProgID ("VisualStudio.DTE.12.0"); 
     dynamic  myDTE = System.Activator.CreateInstance  (myType); //error right here 
    } 
} 

L'erreur dit:

Erreur 1 Une initialisation de champ ne peut pas référencer le champ non statique, méthode , ou bien ' TwinCAT_Automation_Interface.Main.myType '

Que fais-je tort? C'est le même extrait de code; Je viens de le modifier un peu. S'il vous plaît aider !!!!

OK, je l'ai fixé en changeant à la suivante:

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 
//using EnvDTE; 

namespace TwinCAT_Automation_Interface 
{ 
    public partial class Main : Form 
    { 
     public Main() 
     { 
      InitializeComponent(); 
     } 

     public void myMethod() 
     { 
      //Creating TwinCAT Projects via templates (Recommended) 
      Type  myType = System.Type  .GetTypeFromProgID ("VisualStudio.DTE.12.0"); 
      dynamic  myDTE = System.Activator.CreateInstance  (myType);     // dynamic linking for DTE-object 
     } 
    } 
} 

L'explication est en lien this. C'est une erreur de compilateur.

Répondre

0

Il s'agit d'une erreur de compilation. Voir la question pour le lien vers la réponse.