2014-10-31 30 views
-1

我不是VB.NET的傢伙,但我必須現在。我正嘗試調用一個服務並使用下面的VB.NET代碼獲取數據。Linq InvalidCastException在VB.NET中,但在C#中工作#

但我收到一個異常,說InvalidCastException指定的轉換無效。

Dim service = Ioc.Resolve(Of Services.DokumentServiceClient)() 
Dim response = service.Dokument(Id, GroupId, False) 
Dim DocumentId = ASPxListBoxDokument.SelectedItem.Value 

Dim result = (From documents In response.Values 
       From d In documents 
       Where d.DocumentId = DocumentId 
       Select d).FirstOrDefault 

所以我在c#中嘗試過,它的工作原理。 這是在C#代碼

var response = client.Dokument(Id, GroupId, false); 

Guid DocumentId = ASPxListBoxDokument.SelectedItem.Value 
var result = (from documents in response.Values 
       from d in documents 
       where d.DocumentId == DocumentId 
       select d).FirstOrDefault(); 

我應該做的就是它在VB.NET工作?

+3

雖然這*不是相同的代碼。 C#代碼中的'client'類型在哪裏? – hometoast 2014-10-31 10:44:36

+1

_你在哪裏得到這個異常?堆棧跟蹤會完全告訴你發生在哪一行。 – 2014-10-31 10:46:53

+0

是否在您的VB代碼中拋出異常的'Ioc.Resolve'行(即不在您的c#中的行)? – 2014-10-31 10:47:48

回答

0

在我的VB的問題是,我並沒有將其轉換爲一個GUID

Dim DocumentId = ASPxListBoxDokument.SelectedItem.Value 

但在我的C#代碼我被聲明爲的Guid

Guid DocumentId = ASPxListBoxDokument.SelectedItem.Value 

業餘的錯誤。

相關問題