Results 1 to 8 of 8

Thread: Expose C# List<T> to COM Interop and access it from classic asp

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Posts
    268

    Question Expose C# List<T> to COM Interop and access it from classic asp

    Hi,
    I have developed a C# COM Component which will return a List<classname> as result. But not able to read this from classic asp. Please help me to sort out this issue.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Expose C# List<T> to COM Interop and access it from classic asp

    Lists don't exist in classic ASP... you'll either need to return it as an array, or a collection... you could try returning it as a List, and then declare the variable on the ASP side as a collection and see if that works... but something tells me it's not going to.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Posts
    268

    Re: Expose C# List<T> to COM Interop and access it from classic asp

    Quote Originally Posted by techgnome View Post
    Lists don't exist in classic ASP... you'll either need to return it as an array, or a collection... you could try returning it as a List, and then declare the variable on the ASP side as a collection and see if that works... but something tells me it's not going to.

    -tg
    Hi,

    Thank you for reply.

    I have tried like this http://stackoverflow.com/questions/5...097474#5097474

    But in this they are sending only one dimensional array but mine multi dimensional array.

    Thank you.

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Expose C# List<T> to COM Interop and access it from classic asp

    Huh? is it a List<> or a multi-dimensional array? It can't be both. Are you returning a List<> with another List<> in it? Bottom line, VBScript in ASP cannot handle a List<> whether it's the main object returned or a property of another object or the property of a property of an object... it needs to be an array... if you look at the example at the link, you'll see that's exactly what they are doing... casting the list .ToArray and returning that result.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Posts
    268

    Question Re: Expose C# List<T> to COM Interop and access it from classic asp

    Thanks for the quick reply.

    In .net it is a list, but I have converted that list to an array.
    Now I want to send this array to classic asp via COM.

    Please help me in that.

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Expose C# List<T> to COM Interop and access it from classic asp

    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Posts
    268

    Question Re: Expose C# List<T> to COM Interop and access it from classic asp

    Hi,

    Thank you for the reply.

    That is my another post for the COM interop issue and I have resolved it.
    But this is for converting C# List to Classic asp. Have to pass via COM.

  8. #8
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    Re: Expose C# List<T> to COM Interop and access it from classic asp

    If you have already solved the problem, how to do interop,
    then all you have to do (at the C#-side of things), to convert
    your <List> content (in case it has "multiple Columns") - into
    a COM-based DataContainer-Object which will be understood
    without problems in the asp-script.

    An easy to use COM-DataContainer (even at the C#-end), which
    supports multiple Columns, is the ADODB.Recordset.

    You will just have to create a freestanding instance of it, and then copy
    your <List>-data over, before returning or passing it back to the asp-Script.

    A freestanding ADO.Recordset (without any connections to any DB)
    can be created as shown below (decide yourself, whether you instantiate
    it in the asp-script and pass it as an Object-Param to C#, or if you
    create it in C# and just pass it back as a Function-Result.

    Code can be pasted into a *.vbs File and tested there...:

    Code:
    ' *.asp-Code:
    Dim Rs
    Set Rs = CreateEmptyRsWithFourColumns 'create a new ADO-Rs (with 4 Cols) 
    
        SimulatesTheCSharpMethodCall Rs '<- pass the (yet empty) Rs-Instance to C#
      
        Rs.MoveFirst
        MsgBox Rs(0) 'show the result of the 1st Row and 1st Col
        
        Rs.MoveNext
        MsgBox Rs(0) 'show the result of the 2nd Row and 1st Col
    
    
    'this creation-function could remain in the asp-Script 
    Function CreateEmptyRsWithFourColumns()
    Const Int32 = 3, BSTR = 8, DBL = 5, CUR = 6
    Dim Rs
    Set Rs = CreateObject("ADODB.Recordset")
    
          'define 4 Columns (of type Int32, BSTR, Double, Currency)
          Rs.Fields.Append "fld_Int32", Int32
          Rs.Fields.Append "fld_BSTR", BSTR
          Rs.Fields.Append "fld_DBL", DBL
          Rs.Fields.Append "fld_Cur", CUR
          
        Rs.Open
      
      Set CreateEmptyRsWithFourColumns = Rs
    End Function
    
    'this is, what needs to be managed in a copy-over-routine, which gets
    'implemented at the C#-end appropriately (replacing this Script-Impl.)
    Sub SimulatesTheCSharpMethodCall(Rs)
    
        Rs.AddNew 'adds a 1st Row (or Record) - using FieldName-Strings
          Rs("fld_Int32").Value = 1111
          Rs("fld_BSTR").Value = "Some String 1"
          Rs("fld_DBL").Value = 1111.11111
          Rs("fld_Cur").Value = 1111111.11
        
        Rs.AddNew 'add a 2nd Row (or Record) - ZeroBased Indexes work too
          Rs(0).Value = 2222
          Rs(1).Value = "Some String 2"
          Rs(2).Value = 2222.22222
          Rs(3).Value = 2222222.22
    End Sub
    Olaf

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width