2017-11-09 4 views
0

のインスタンスを作成できません)。私はプログラムを実行するときしかし、私は、コードの1行目に、次の実行時エラーを取得: は、私は、次の(非常に単純な)プログラムを持っているAutConnList

Unable to cast COM object of type 'System.__ComObject' to interface type 'AutConnListTypeLibrary.AutConnList'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{3CB39CC1-6F18-11D0-910D-0004AC3617E1}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

私は以下の参考文献は、(デフォルトのもの以外に)自分のプロジェクトに追加した

References added to the project

リファレンスがありませんか?それとも、コードに間違いがありますか?前述したように、実行時エラーです。コードはうまくコンパイルされます。

答えて

0

この問題は非常に簡単な解決策です(理解するのはあまり簡単ではありません)。 Main()メソッドに[STAThread]属性を追加するだけです。元の投稿のコードは次のようになります。

[STAThread] 
static void Main(string[] args) 
{ 
    // The program has 'using AutConnListTypeLibrary' in the header 
    AutConnList connections = new AutConnList(); 
    connections.Refresh(); 
    Debug.Print(connections.Count.ToString()); 
} 
関連する問題