2011-11-21 59 views
0

我目前正在用我的C#MVC3項目使用的com組件出現一些奇怪的現象。爲什麼對COM組件的調用僅使用VisualStudio QuickWatch窗口返回值?

COM組件(名爲YVPCUST)包含以下VB6例程:

qtcsl32.YVPCUST yvpCust = new qtcsl32.YVPCUST(); 

object code = (object)"RAAG"; 
object minimumAge = 0; 
object maximumAge = 0; 
object suffix = (object)string.Empty; //not to be used 

int returnCode; 

returnCode = yvpCust.GetDocument(code, minimumAge, maximumAge, suffix); 

Public Function GetDocument(ByVal a_sCode As Variant, ByRef a_sLocation As Variant, ByRef a_sDestination As Variant, ByRef a_sSuffix As Variant) As Integer 
    Dim oSystem  As System 

    Set oSystem = CreateObject("qtcsl32.System") 
    GetDocument = oSystem.GetDocumentByRef(a_sCode, a_sLocation, a_sDestination, a_sSuffix) 
    Set oSystem = Nothing 

End Function 

的C#MVC3項目正在使用哪個直接引用部件命名YVPCUST COM組件層建例程GetDocument()應該獲得所提供的代碼的最大值和最小值。但是,當我在編譯或調試模式下運行應用程序並跨越最後一行時,minimumAge和maximumAge值設置不正確,它們被設置爲默認值0(無論重新執行此行的次數)。

但是,(在調試模式下)如果我在最後一行中斷了代碼,而是使用QuickWatch運行該行,當我從QuickWatch窗口返回代碼時,這些值被設置爲正確的最小和最大年齡當我將鼠標懸停在他們身上時。

有沒有人有任何想法,爲什麼會發生這種情況?

此COM組件用於應用程序中的其他各個位置(但不是此例程),沒有任何問題。

回答

0

我意識到,對於COM組件的C#包裝有以下聲明:

short GetDocument(object a_sCode, ref object a_sLocation, ref object a_sDestination, ref object a_sSuffix); 

我才明白,代碼行應該已被寫入(包括裁判的):

returnCode = yvpCust.GetDocument(code, ref minimumAge, ref maximumAge, suffix); 

這並未不解釋爲什麼它使用QuickWatch窗口,但我已經設法得到所需的結果。

相關問題