2011-01-06 16 views
0

を委任一致するための過負荷:「<method>」マイ「セキュリティ」アセンブリは、このコード「を含む<delegate>」

public delegate void InteropEventDelegate(InteropEventType etype, string data, string data2, string data3); 
    public event InteropEventDelegate InteropEvent; 

第2組立は、私の「セキュリティ」アセンブリを参照すると、このコードが含まれています

void LoadSecurity() 
    { 
     if (!AssemblyIsLocked && Security == null) 
     { 
      this.Security = new Security.Security(UnlockCode); 
      this.Security.InteropEvent += new Security.Security.InteropEventDelegate(Security_InteropEvent); 
     } 
    } 

    void Security_InteropEvent(InteropEventType etype, string data, string data2, string data3) 
    { 
     throw new NotImplementedException(); 
    } 

IntelliSenseによってSecurity_InteropEventが生成され、正しいシグネチャを持っていますが、「Security_InteropEvent」のオーバーロードがデリゲート「Security.Security.InteropEventDelegate」に一致しないというエラーが発生します。どうして?

答えて

3

InteropEventTypeという別のタイプが宣言されていますか?これにより、Security_InteropEventの最初のパラメータがInteropEventDelegateの最初のパラメータと異なるタイプになります。

名前を言及していますが、と強くは、型と名前空間に同じ名前を付けないことをお勧めします。エリック・リッペルト氏は、これの危険性についてwhole blog seriesを持っています。 (私はあなたがそれについてのコンストラクタを呼んでいることを見てまで、私が元々はあまり名前のついた名前空間であると仮定したSecurity.Securityについて話しています)。

+0

私はこの勧告を2番目に推奨します。単純な抜粋 'Security = new Security.Security'は同じ単語に対して3つの意味を持っています! – configurator

+0

はい、InteropEventTypeが定義されているアセンブリ間でENUMS.CSファイルを共有していました。両方の場所で同じように定義されていますが、2つの別々のタイプとして扱われると思います。アセンブリ間で列挙型を共有する方法はありますか – PahJoker

+0

@PahJoker:1つのアセンブリを他のアセンブリを参照することによって、基本的に列挙型を共有します。 2つの異なるアセンブリにタイプを定義しないでください。問題が発生する可能性があります。 –

関連する問題