0
votes

Hi have a project in C# that return a list of object of type MyClass with the method GetArray(). I register this dll with regasm ClassLibrary1.dll /codebase /tlb and then I add the ClassLibrary1.tlb reference in a project in VB6 as the code below. When I run the VB6 application inside the Microsoft Visual Studio 6.0 it works but when I try to run the vb6 exe I have a runtime error

using System.Collections.Generic;

using System.Runtime.InteropServices;

namespace ClassLibrary1

{

    [ClassInterface(ClassInterfaceType.AutoDual)]

    [Guid("D878834C-306E-4260-905F-BDEBDF14CBDA")]

    [ComVisible(true)]

    public class MyProjectC

    {

        public MyClass[] GetArray()

        {

            var list = new List<MyClass>

                           {

                               new MyClass {Nome = "A"},

                               new MyClass {Nome = "AB"},

                               new MyClass {Nome = "AC2"},

                               new MyClass {Nome = "D"}

                           };

            return list.ToArray();
        }
    }


    [ClassInterface(ClassInterfaceType.AutoDual)]

    [Guid("D878834C-306E-4260-905F-BDEBDF14C111")]

    [ComVisible(true)]

    public class MyClass

    {

        public string Nome;

    }

}


Private Sub Form_Load()

    On Error GoTo error

    Dim str As String

    Dim oBookMark As Variant
    Dim theProjectC As New ClassLibrary1.MyProjectC


    For Each oBookMark In theProjectC.GetArray
        str = oBookMark.Nome
        MsgBox str
    Next

    Exit Sub

error:
MsgBox "Errore" & Err.Description

End Sub
1
It would help if you posted what the runtime error was.Richard Marskell - Drackir
You could also test it on the EXE itself rather than in the IDE. For some or other reason we can't get the VB6 app to work when in the IDE, but the EXE works fine.jakdep

1 Answers

0
votes

Try changing your public field MyClass.Nome to a public property:

public string MyNome { get; set; }