Solved

Return DataSet from remote object.

Posted on 2004-03-22
6
292 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
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
        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
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()

        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
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.

JFercan
0
 
LVL 1

Accepted Solution

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

Computer101
E-E Admin
0
 

Expert Comment

by:sainavya1215
ID: 11475465
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
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 …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

863 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

21 Experts available now in Live!

Get 1:1 Help Now