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
Solved

Return DataSet from remote object.

Posted on 2004-03-22
6
299 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 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