Solved

Return DataSet from remote object.

Posted on 2004-03-22
6
289 Views
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.

JFercan
0
Comment
Question by:JFercan
6 Comments
 
LVL 28

Expert Comment

by:iboutchkine
Comment Utility
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
        Try
            dg.DataSource = sc.ReturnDS("select * from " & txtTable.Text.ToString, txtTable.Text.ToString).Tables(0)
        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.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
0
 
LVL 2

Author Comment

by:JFercan
Comment Utility
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()

        dbConn.Open()

        With dbCommand
            .Connection = dbConn
            .CommandType = CommandType.StoredProcedure
            .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.DictionaryBase

    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(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()
        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.ListDictionary()
        props.Add("useDefaultCredentials", True)
        chan = New HttpChannel(props, New BinaryClientFormatterSinkProvider(), New BinaryServerFormatterSinkProvider())
        ChannelServices.RegisterChannel(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
0
 
LVL 2

Author Comment

by:JFercan
Comment Utility
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
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
Comment Utility
PAQed, with points refunded (250)

Computer101
E-E Admin
0
 

Expert Comment

by:sainavya1215
Comment Utility
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now