Return DataSet from remote object.

Posted on 2004-03-22
Medium Priority
Last Modified: 2008-02-26
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.InvalidCastException' occurred in mscorlib.dll

Additional information: Return argument has an invalid type."

Any help will be greatly appreciated.

Thank you.

Question by:JFercan
LVL 28

Expert Comment

ID: 10657128
Remoting works fine for me under both .Net FRamework

Here is th client call to return dataset

Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Tcp

    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
            dg.DataSource = sc.ReturnDS("select * from " & txtTable.Text.ToString, txtTable.Text.ToString).Tables(0)
        Catch ex As Exception
        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.OLEDB.4.0;Data Source=" & sDBNAme & ";Persist Security Info=False"

        ds = New DataSet()
        da = New OleDbDataAdapter(sSQL, fsConn)
        da.Fill(ds, sTable)
    End Sub
End Class

Author Comment

ID: 10661978
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.NorthwindShared.Interfaces
Imports NorthwindTraders.NorthwindShared.Structures
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.AppSettings("Northwind_DSN") & "User Id=us;Password=pwd"
        Dim dbConn As New NpgsqlConnection(strConn)
        Dim dbCommand As New NpgsqlCommand()
        Dim dbAdapter As New NpgsqlDataAdapter(dbCommand)
        Dim dbDataSet As New DataSet()


        With dbCommand
            .Connection = dbConn
            .CommandType = CommandType.StoredProcedure
            .CommandText = "usp_region_getall()"
        End With


        dbCommand = Nothing

        Return dbDataSet
    End Function
End Class

UserObj.dll has this code  This gets called from the user interface.
Public Class RegionMgr
    Inherits System.Collections.DictionaryBase

    Protected Sub New()
    End Sub

    Private Sub Load()
        Dim objIRegion As IRegion
        Dim dRow As DataRow
        Dim ds As DataSet

        objIRegion = (CType(Activator.GetObject(GetType(IRegion), "http://localhost/Northwind/RegionDC.rem"), IRegion))
        ds = objIRegion.LoadProxy()     '*** HERE IS WHERE THE ERROR OCCURES ***'
        objIRegion = Nothing

        ds.WriteXml(New IO.FileStream("C:\region.xml", IO.FileMode.Create))
    End Sub  
End Class

Now, on my main form I have the following to create the channel:
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Http

Public Class frmMain
    Inherits System.Windows.Forms.Form

    Private chan As HttpChannel

#Region " Windows Form Designer generated code "

    Public Sub New()

        'This call is required by the Windows Form Designer.

        'Add any initialization after the InitializeComponent() call

        Dim props As New Collections.Specialized.ListDictionary()
        props.Add("useDefaultCredentials", True)
        chan = New HttpChannel(props, New BinaryClientFormatterSinkProvider(), New BinaryServerFormatterSinkProvider())
    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.


Author Comment

ID: 10673276
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.


Accepted Solution

Computer101 earned 0 total points
ID: 10923546
PAQed, with points refunded (250)

E-E Admin

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Free Data Recovery software is an advanced solution from Kernel Tools to recover data and files such as documents, emails, database, media and pictures, etc. It supports recovery from physical & logical drive after a hard disk crash, accidental/inte…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question