Vb.net WCF服务无效强制转换

Vb.net WCF服务无效强制转换,vb.net,wcf,Vb.net,Wcf,所以我正在做一个丑陋的遗留windows窗体项目,它是用VB.NET编写的。我试图让它使用我以前编写的WCF web服务。当我在本地测试它时,一切都正常,但是,当我将服务部署到我的开发环境(我有开发、QA和生产环境),然后更改win form应用程序中的配置文件以指向开发服务,然后运行应用程序时,它会给我一个“无效强制转换异常”。我完全糊涂了 windows窗体如下所示: 基本上,用户所做的就是更改复选框。复选框的任何更改都将触发windows窗体中的函数“Security\u ColumnC

所以我正在做一个丑陋的遗留windows窗体项目,它是用VB.NET编写的。我试图让它使用我以前编写的WCF web服务。当我在本地测试它时,一切都正常,但是,当我将服务部署到我的开发环境(我有开发、QA和生产环境),然后更改win form应用程序中的配置文件以指向开发服务,然后运行应用程序时,它会给我一个“无效强制转换异常”。我完全糊涂了

windows窗体如下所示:

基本上,用户所做的就是更改复选框。复选框的任何更改都将触发windows窗体中的函数“Security\u ColumnChanging()”:

 Private Sub Security_ColumnChanging(ByVal sender As Object, ByVal e As System.Data.DataColumnChangeEventArgs)
    Try
        Dim intPersonnel_Id As Integer = m_oDS.Tables("Security").Rows(DataGrid1.CurrentRowIndex)("ID")
        Dim groupId As Integer

        Select Case UCase(e.Column.ColumnName)
            Case "ADMINREPORTS"
                groupId = 1
            Case "BATCH"
                groupId = 2
            Case "SECURITY"
                groupId = 3
            Case "GLOBALRULE"
                groupId = 4
            Case "PROFILES"
                groupId = 5
        End Select

        If e.ProposedValue Then
            dataSource.AddGroupForUser(intPersonnel_Id, groupId)
        Else
            dataSource.DeleteGroupForUser(intPersonnel_Id, groupId)
        End If
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

End Sub
您可以看到还有一个datasource类,它将处理所有的数据库插入和删除。datasource类中的两个函数是:

Public Class SecurityFormDataSource
Public Sub AddGroupForUser(userID As Integer, groupID As Integer)
    Using proxy As Service.AuthenticationService.AuthenticationServiceClient = New Service.AuthenticationService.AuthenticationServiceClient()
        Dim success As Boolean = proxy.AddGroupForUser(userID, groupID, Guid.Empty)
        If success = False Then
            Throw New Exception("Error happened on the service side.")
        End If
    End Using
End Sub

Public Sub DeleteGroupForUser(userID As Integer, groupID As Integer)
    Using proxy As Service.AuthenticationService.AuthenticationServiceClient = New Service.AuthenticationService.AuthenticationServiceClient()
        Dim success As Boolean = proxy.DeleteGroupForUser(userID, groupID, Guid.Empty)
        If success = False Then
            Throw New Exception("Error happened on the service side.")
        End If
    End Using
End Sub
End Class
datasource类最终调用“身份验证服务”中的函数来实际插入或删除数据库记录。当我在本地计算机上运行该服务时,一切正常,但在我将该服务部署到任何环境并再次测试windows窗体后,出现以下错误:

堆栈跟踪是:

   at System.Windows.Forms.DataGridBoolColumn.Paint(Graphics g, Rectangle   bounds, CurrencyManager source, Int32 rowNum, Brush backBrush, Brush foreBrush, Boolean alignToRight)
   at System.Windows.Forms.DataGridRelationshipRow.PaintCellContents(Graphics g, Rectangle cellBounds, DataGridColumnStyle column, Brush backBr, Brush foreBrush, Boolean alignToRight)
   at System.Windows.Forms.DataGridRow.PaintData(Graphics g, Rectangle bounds, Int32 firstVisibleColumn, Int32 columnCount, Boolean alignToRight)
   at System.Windows.Forms.DataGridRelationshipRow.Paint(Graphics g, Rectangle bounds, Rectangle trueRowBounds, Int32 firstVisibleColumn, Int32 numVisibleColumns, Boolean alignToRight)
   at System.Windows.Forms.DataGrid.PaintRows(Graphics g, Rectangle& boundingRect)
   at System.Windows.Forms.DataGrid.PaintGrid(Graphics g, Rectangle gridBounds)
   at System.Windows.Forms.DataGrid.OnPaint(PaintEventArgs pe)
   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
   at System.Windows.Forms.Control.WmPaint(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

这是VB.NET,不是C#…您是否部署了与本地测试相同的风格(零售/调试)?@RufusL是的,我没有手动部署它,我使用的是Microsoft Release Management Studio,因此不同环境中的服务将始终是相同的,以支持在第一次出现异常时停止(您的
InvalidCastException
)-它将恰好在无法浇铸的地方断裂。