我正在将 Dynamics CRM SDK 2011 的 Microsoft 示例中的一些控制台代码转换为 ASP.NET Web 应用程序。它在控制台模式下运行良好,但在转换为在 ASP.NET 中运行后出现错误:
Microsoft.VisualBasic.dll 中出现了“System.InvalidCastException”类型的第一次机会异常
这是我的源代码:
Public Sub Run(ByVal connectionString As String, ByVal promptforDelete As Boolean)
Try
Dim connection As Microsoft.Xrm.Client.CrmConnection =
CrmConnection.Parse(connectionString)
_orgService = New OrganizationService(connection)
Using _orgService
Dim account_Renamed As Account = New Account With {.Name = "Fourth Coffee"}
_accountId = _orgService.Create(account_Renamed)
Response.Write(CType("{0} {1}", Char()), account_Renamed.LogicalName, account_Renamed.Name)
Dim cols As New ColumnSet(New String() {"name",
"address1_postalcode",
"lastusedincampaign"})
Dim retrievedAccount As Account = _orgService.Retrieve("account", _accountId, cols).ToEntity(Of Account)()
Response.Write("Retrieved record.")
retrievedAccount.Address1_PostalCode = "98052"
Response.Write("Updated Account Postal Code.")
End Using
Catch ex As Exception
End Try
End Sub