2014-05-13 49 views
5

我有一個用C#.NET編寫的公開COM接口的DLL,所以vb6應用程序可以調用我的DLL。此接口看起來像:c#.net COM dll打破引用vb6應用程序

[System.Runtime.InteropServices.Guid("3D2C106C-097F-4ED7-9E4F-CDBC6A43BDC4")] 
    public interface IZDPharmaManager { 
     [System.Runtime.InteropServices.DispId(2)] 
     SearchPatientEventArgs FoundPatient { get; set; } 
     [System.Runtime.InteropServices.DispId(3)] 
     IntPtr Start(string server, string database, string user, string password, bool integrated, int praktijkID, string userGUID, int userID, string userName, bool hasRightToSearchPatient); 
     [System.Runtime.InteropServices.DispId(4)] 
     void Stop(); 
     [System.Runtime.InteropServices.DispId(5)] 
     void InitializeSkinner(System.Object skinnerFramework); 
    } 

[System.Runtime.InteropServices.Guid("4438852E-CF2D-4DB0-8E6E-428F65A6B16C")] 
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] 
public interface IZDPharmaManagerEvents { 
    [DispId(1)] 
    void SearchPatient(ZDPharmaManager sender, SearchPatientEventArgs e); 
} 

    [System.Runtime.InteropServices.Guid("9297D43F-C581-3F0F-AA60-9506C6B77B5F")] 
    [ClassInterface(ClassInterfaceType.None)] 
    public class SearchPatientEventArgs : WebHIS.ZDPharmaceutisch.ISearchPatientEventArgs { 

     public SearchPatientEventArgs() { 
      //Nodig voor COM. 
     } 

     public int ID { get; set; } 
     public string FullName { get; set; } 
     public string OwnName { get; set; } 
     public string PartnerName { get; set; } 
     public string DateOfBirth { get; set; } 
     public string ZipCode { get; set; } 
     public string HouseNumber { get; set; } 
     public string BSN { get; set; } 
    } 

    public delegate void SearchPatientEventHandler(ZDPharmaManager sender, SearchPatientEventArgs e); 

    [System.Runtime.InteropServices.Guid("465AC7EC-27EF-3D95-AAA6-29D01FCF15A1")] 
    [ClassInterface(ClassInterfaceType.None)] 
    [ComSourceInterfaces(typeof(IZDPharmaManagerEvents))] 
    public class ZDPharmaManager : WebHIS.ZDPharmaceutisch.IZDPharmaManager { 

     public event SearchPatientEventHandler SearchPatient = null; 

     public SearchPatientEventArgs FoundPatient { get; set; } 

     //private MainForm GraphicalInterface { get; set; } 
     private ChoosePatient GraphicalInterface { get; set; } 

     public ZDPharmaManager() { 
      //Nodig voor COM. 
     } 

     #region IZDPharmaManager Members 

     public IntPtr Start(string server, 
      string database, 
      string user, 
      string password, 
      bool integrated, 
      int praktijkID, 
      string userGUID, 
      int userID, 
      string userName, 
      bool hasRightToSearchPatient) { 

      //Zet connectiestring. 
      DAL.DAC.CnnInfo = new System.Data.SqlClient.SqlConnectionStringBuilder() { 
       DataSource = server, 
       InitialCatalog = database, 
       UserID = user, 
       Password = password, 
       IntegratedSecurity = integrated 
      }; 

      DAL.DAC.PracticeID = praktijkID; 
      DAL.DAC.UserGUID = userGUID; 
      DAL.DAC.UserID = userID; 
      DAL.DAC.UserName = userName; 
      DAL.DAC.HasRightToSearchPatient = hasRightToSearchPatient; 

      //Apotheek IDs ophalen en bewaren. 
      DAL.DAC.PharmacyIDs = DAL.PracticeDAO.GetPharmacyByPracticeID(praktijkID); 

      //Initialiseer grafische interface. 
      //this.GraphicalInterface = new MainForm(); 
      this.GraphicalInterface = new ChoosePatient(); 

      //Haal ongekoppelde afhaalberichten op. 
      this.GraphicalInterface.Patients = new VML.PatientsVM(this); 

      //Toon grafische interface. 
      this.GraphicalInterface.Show(); 

      return this.GraphicalInterface.Handle; 

     } 

     public void Stop() { 
      foreach (var item in this.SearchPatient.GetInvocationList()) { 
       this.SearchPatient -= (SearchPatientEventHandler)item; 

      } 
      this.GraphicalInterface.Close(); 
      this.GraphicalInterface = null; 
      this.FoundPatient = null; 
     } 

     public void InitializeSkinner(System.Object skinnerFramework) { 

      WebHIS.ZDPharmaceutisch.SkinnerModule.SkinFramework = (XtremeSkinFramework.SkinFramework)skinnerFramework; 

     } 
     #endregion 

     internal virtual void OnSearchPatient(SearchPatientEventArgs e) { 
      if (this.SearchPatient != null) { 
       this.SearchPatient(this, e); 
      } 
     } 


    } 

這工作正常。但是,每次我在不更改接口的情況下構建此DLL時(因爲我必須修復邏輯中的某處),引用vb6應用程序時出現故障,我們需要重新編譯vb6應用程序。

有誰知道我在做什麼錯?因爲我們有vb.net DLL,因爲固定的GUID,重新編譯後沒有打破引用。任何幫助將非常感激。

更新 vb6應用程序和DLL都可以使用。但是,當我重新編譯該DLL並通過vb6應用程序在我們的測試服務器上進行測試時,我得到一個自動化錯誤(通常意味着該參考已損壞,您還需要重新編譯vb6應用程序)

+0

即時通訊不太清楚你的意思,但如果你已經附上引用,現在你正在改變你的DLL,你至少需要關閉VB6或免費引用你的DLL後,每次編譯你的DLL。 –

+0

這確實不是我的意思。 vb6應用程序和DLL都可以運行。但是,當我重新編譯該DLL並通過vb6應用程序在我們的測試服務器上進行測試時,我得到一個自動化錯誤(通常意味着該參考已損壞,您還需要重新編譯vb6應用程序) –

+0

DLL中的其他公共類可能會自動UUID/GUID在您重新編譯時會發生變化。看起來就像我最近看到的一個例子。 – DaveInCaz

回答

11

我沒有看到任何強可以解釋這個問題的線索。組件的[Guid]屬性很重要,它設置了類型庫ID。 [AssemblyVersion]很重要,它設置了類型庫版本號。屬性在項目的AssemblyInfo.cs文件中聲明。確保你的構建系統不符合這些屬性。

最好的方法是找出究竟發生了什麼變化。從Visual Studio命令提示符運行OleView.exe實用程序。文件+查看Typelib並選擇.tlb文件。將右側面板的內容複製/粘貼到文本文件中。

重建項目並重復OleView練習。您現在可以簡單地使用差異工具來查看究竟發生了什麼變化。如果您需要更多幫助,請更新您的問題。

+0

非常感謝您向我解釋OleView.exe。有了這個實用程序,我可以發現程序集暴露得比我知道的還多,並且正在生成GUID(打斷了課程的參考) –

+0

@DannyvanderKraan你能提供一些關於意外暴露的細節嗎?謝謝 – DaveInCaz

+0

@DaveInCaz對不起,但我在3年前問過這個問題,我不記得了。它的要點是,雖然我認爲構建並沒有改變我的程序集的API,但實際上是這樣。我發現使用上述Hans的方法。 –