2011-01-06 56 views
0

我的「安全性」組件包括驗證碼:沒有重載「<method>」匹配委託「<delegate>」

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

第二裝配引用我的「安全」組件,包括此代碼:

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(); 
    } 

Security_InteropEvent由IntelliSense生成,並具有正確的簽名,但出現錯誤「沒有爲'Security_InteropEvent'重載匹配委託'Security.Security.InteropEventDelegate'」。爲什麼?

回答

3

你有另外一種叫InteropEventType的地方嗎?這將使Security_InteropEvent的第一個參數與第一個參數InteropEventDelegate的類型不同。

雖然我提到的名字,我會強烈建議你不要給一個類型和命名空間相同的名稱。 Eric Lippert有關於此的危險的whole blog series。 (我說的是Security.Security,我原本認爲這是一個命名空間不佳的名稱空間,直到我看到你正在調用構造函數爲止。)

+0

我第二個這個建議。簡單的摘錄`Security = new Security.Security`對同一個詞有三個含義! – configurator 2011-01-07 00:09:05

相關問題