JFercan
asked on
Return DataSet from remote object.
I am working on application using remonting and IIS to host the data component. One of the methods of the remote object creates a DataSet and returns it to the calling method. I have a Shared dll that holds the Interfaces so that is makes it easier to communicate. This dll is in both the server and the client. The method mentioned above implentes one of these interfaces. I am using http as the remonting channel and the BinaryFormatter.
It was working fine until I updated the .NET Framework to 1.1. Now I am getting the following message.
"An unhandled exception of type 'System.InvalidCastExcepti on' occurred in mscorlib.dll
Additional information: Return argument has an invalid type."
Any help will be greatly appreciated.
Thank you.
JFercan
It was working fine until I updated the .NET Framework to 1.1. Now I am getting the following message.
"An unhandled exception of type 'System.InvalidCastExcepti
Additional information: Return argument has an invalid type."
Any help will be greatly appreciated.
Thank you.
JFercan
ASKER
Maybe some code will help:
Shared.dll has this interface and structure
'************************* ********** ********** ********** ********** ********** *****
Public Interface IRegion
Function LoadProxy() As DataSet
Function LoadRecord(ByVal intID As Integer) As structRegion
Sub Save(ByVal sRegion As structRegion, ByRef intID As Integer)
Sub Delete(ByVal intID As Integer)
End Interface
<Serializable()> Public Structure structRegion
Public RegionID As Integer
Public RegionDescription As String
End Structure
'************************* ********** ********** ********** ********** ********** *****
Data.dll in IIS folder has this:
'************************* ********** ********** ********** ********** ********** *****
Imports NorthwindTraders.Northwind Shared.Int erfaces
Imports NorthwindTraders.Northwind Shared.Str uctures
Imports System.Configuration
Imports Npgsql
Public Class RegionDC
Inherits MarshalByRefObject
Implements IRegion
Private mintRegionID As Integer
Private mstrRegionDescription As String
Public Function LoadProxy() As DataSet Implements IRegion.LoadProxy
Dim strConn As String = ConfigurationSettings.AppS ettings("N orthwind_D SN") & "User Id=us;Password=pwd"
Dim dbConn As New NpgsqlConnection(strConn)
Dim dbCommand As New NpgsqlCommand()
Dim dbAdapter As New NpgsqlDataAdapter(dbComman d)
Dim dbDataSet As New DataSet()
dbConn.Open()
With dbCommand
.Connection = dbConn
.CommandType = CommandType.StoredProcedur e
.CommandText = "usp_region_getall()"
End With
dbAdapter.Fill(dbDataSet)
dbCommand = Nothing
dbConn.Close()
Return dbDataSet
End Function
End Class
'************************* ********** ********** ********** ********** ********** *****
UserObj.dll has this code This gets called from the user interface.
'************************* ********** ********** ********** ********** ********** *****
Public Class RegionMgr
Inherits System.Collections.Diction aryBase
Protected Sub New()
Load()
End Sub
Private Sub Load()
Dim objIRegion As IRegion
Dim dRow As DataRow
Dim ds As DataSet
objIRegion = (CType(Activator.GetObject (GetType(I Region), "http://localhost/Northwind/RegionDC.rem"), IRegion))
ds = objIRegion.LoadProxy() '*** HERE IS WHERE THE ERROR OCCURES ***'
objIRegion = Nothing
ds.WriteXml(New IO.FileStream("C:\region.x ml", IO.FileMode.Create))
End Sub
End Class
'************************* ********** ********** ********** ********** ********** *****
Now, on my main form I have the following to create the channel:
'************************* ********** ********** ********** ********** ********** *****
Imports System.Runtime.Remoting.Ch annels
Imports System.Runtime.Remoting.Ch annels.Htt p
Public Class frmMain
Inherits System.Windows.Forms.Form
Private chan As HttpChannel
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
'*** CHANNEL INITALIZATION ***'
Dim props As New Collections.Specialized.Li stDictiona ry()
props.Add("useDefaultCrede ntials", True)
chan = New HttpChannel(props, New BinaryClientFormatterSinkP rovider(), New BinaryServerFormatterSinkP rovider())
ChannelServices.RegisterCh annel(chan )
End Sub
.
.
.
.
End Class
'************************* ********** ********** ********** ********** ********** *****
This error is really killing me because nothing on this code changed since it was working before.
Thank you for your cooperation.
JFercan
Shared.dll has this interface and structure
'*************************
Public Interface IRegion
Function LoadProxy() As DataSet
Function LoadRecord(ByVal intID As Integer) As structRegion
Sub Save(ByVal sRegion As structRegion, ByRef intID As Integer)
Sub Delete(ByVal intID As Integer)
End Interface
<Serializable()> Public Structure structRegion
Public RegionID As Integer
Public RegionDescription As String
End Structure
'*************************
Data.dll in IIS folder has this:
'*************************
Imports NorthwindTraders.Northwind
Imports NorthwindTraders.Northwind
Imports System.Configuration
Imports Npgsql
Public Class RegionDC
Inherits MarshalByRefObject
Implements IRegion
Private mintRegionID As Integer
Private mstrRegionDescription As String
Public Function LoadProxy() As DataSet Implements IRegion.LoadProxy
Dim strConn As String = ConfigurationSettings.AppS
Dim dbConn As New NpgsqlConnection(strConn)
Dim dbCommand As New NpgsqlCommand()
Dim dbAdapter As New NpgsqlDataAdapter(dbComman
Dim dbDataSet As New DataSet()
dbConn.Open()
With dbCommand
.Connection = dbConn
.CommandType = CommandType.StoredProcedur
.CommandText = "usp_region_getall()"
End With
dbAdapter.Fill(dbDataSet)
dbCommand = Nothing
dbConn.Close()
Return dbDataSet
End Function
End Class
'*************************
UserObj.dll has this code This gets called from the user interface.
'*************************
Public Class RegionMgr
Inherits System.Collections.Diction
Protected Sub New()
Load()
End Sub
Private Sub Load()
Dim objIRegion As IRegion
Dim dRow As DataRow
Dim ds As DataSet
objIRegion = (CType(Activator.GetObject
ds = objIRegion.LoadProxy() '*** HERE IS WHERE THE ERROR OCCURES ***'
objIRegion = Nothing
ds.WriteXml(New IO.FileStream("C:\region.x
End Sub
End Class
'*************************
Now, on my main form I have the following to create the channel:
'*************************
Imports System.Runtime.Remoting.Ch
Imports System.Runtime.Remoting.Ch
Public Class frmMain
Inherits System.Windows.Forms.Form
Private chan As HttpChannel
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
'*** CHANNEL INITALIZATION ***'
Dim props As New Collections.Specialized.Li
props.Add("useDefaultCrede
chan = New HttpChannel(props, New BinaryClientFormatterSinkP
ChannelServices.RegisterCh
End Sub
.
.
.
.
End Class
'*************************
This error is really killing me because nothing on this code changed since it was working before.
Thank you for your cooperation.
JFercan
ASKER
OK, I uninstalled the 1.1. Framework and my code worked fine again.
Has anyone had this problem, how can I work with both frameworks without running into this problem.?
Please, if you have any ideas let me know.
Thank you.
JFercan
Has anyone had this problem, how can I work with both frameworks without running into this problem.?
Please, if you have any ideas let me know.
Thank you.
JFercan
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
HI, Could u pls help me with this question https://www.experts-exchange.com/questions/21048088/Remoting-unbound-comboBox-Error.html
Here is th client call to return dataset
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Ch
Imports System.Runtime.Remoting.Ch
Dim sc As ServerClass
Private Sub btnCallServer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCallServer.Click
If Not Initialize() Then Return
Try
dg.DataSource = sc.ReturnDS("select * from " & txtTable.Text.ToString, txtTable.Text.ToString).Ta
Catch ex As Exception
MsgBox(Err.Description)
End Try
End Sub
and here is the server procedures
Imports System.Data.OleDb
Public Class ServerClass
Inherits MarshalByRefObject
Dim fsConn As String
Dim ds As DataSet
Dim da As OleDbDataAdapter
Dim dt As DataTable
Public Function ReturnDS(ByVal sSQL As String, ByVal sTable As String) As DataSet
Call CreateDS(sSQL, sTable)
Return ds
End Function
Private Sub CreateDS(ByVal sSQL As String, ByVal sTable As String)
Dim sDBNAme As String = "c:\TestDB\TestDB.mdb"
fsConn = "Provider=Microsoft.Jet.OL
ds = New DataSet()
da = New OleDbDataAdapter(sSQL, fsConn)
da.Fill(ds, sTable)
End Sub
End Class