Solved

Return DataSet from remote object.

Posted on 2004-03-22
6
305 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Featured Post

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

717 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