Highlighted
Absent Member.
Absent Member.
661 views

[archive] Error "Invalid class string" when returning from a .Net DLL

[Migrated content. Thread originally posted on 08 June 2009]

Hello,

I've tried everything to figure this issue out, and have only run into dead ends.

We have two machines in the office (XP and Vista) which do not receive the error. On all the other machines (1 Vista, 4 XP) we receive the error.

Here is the error we receive:

Invalid class string (Exception from HRESULT: 0x800401F3 (CO_E_CLASSSTRING))

We receive the error when a function in a .Net DLL exits.

I have created a simple .Net DLL and a Cobol program that shows the error.

Here is the .Net C# code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Diagnostics;

namespace TestCall
{
    public class Class1
    {
        public void display_msg(string msg_to_display)
        {
            MessageBox.Show("Message = " + msg_to_display);
        }
    }
}


Here is the .def file that is created by NetDefGen:

      *  ACUCOBOL-GT Version 8.0.0 .NET Copy Book - Generated On 6/8/2009 10:12:01 AM

           OBJECT @ASSEMBLY
           NAME    "@TestCall"
           VERSION "1.0.0.0"
           CULTURE "neutral"
           STRONG  "null"


      * FULLY-QUALIFIED-NAME TestCall.Class1, TestCall, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

      * TestCall.Class1
           NAMESPACE "TestCall"
           CLASS     "Class1"
           MODULE    "TestCall.dll"

           CONSTRUCTOR, 0, @CONSTRUCTOR1

      * [Class: Class1] Void display_msg(System.String)
           METHOD, 0, "@display_msg"
               "BSTR" @msg_to_display, TYPE 8


And here is the COBOL program I use to call the .Net DLL:

       IDENTIFICATION DIVISION.
       PROGRAM-ID. TESTCALL.
       AUTHOR. EDC (PWD).
       SECURITY.
       REMARKS.
               Calls a .Net DLL.

       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SPECIAL-NAMES.
       COPY 'testcall.def'.
           .
      *
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
      *
       DATA DIVISION.
       FILE SECTION.
       WORKING-STORAGE SECTION.
      *
       01  TESTCALL-HANDLE                     USAGE IS HANDLE.
      *
      *
       PROCEDURE DIVISION.
      *
       DECLARATIVES.
       END DECLARATIVES.
      *     
       ACU-MAIN-LOGIC.
           CREATE "TestCall"
                NAMESPACE IS "TestCall"
                CLASS-NAME IS "Class1"
                HANDLE IS TESTCALL-HANDLE.
           MODIFY TESTCALL-HANDLE "display_msg" ("This is it!").
           EXIT PROGRAM.
           STOP RUN.


When the COBOL program runs, it calls the DLL with no problem and the DLL displays the message box. After pressing OK on the message box, the following error is displayed:

Invalid class string (Exception from HRESULT: 0x800401F3 (CO_E_CLASSSTRING))

I am compiling the cobol program with:

SET CBLFLAGS= -o @.acu -e @.erf
CCBL32 -zd testcall.cbl


We are using version 8.0.1.2363 of the compiler.
The runtime version is 8.0.1.2427

The .Net DLL is compiled for x86. I've attached the .Net C# Project if you wanted to see what other settings we are using.

Thank you for any help you can provide.

Paul DuBois
EDC Technology
0 Likes
2 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] Error "Invalid class string" when returning from a .Net DLL

It worked on my XP machine with no issues. Many MS articles about similar issues either the CLSID GUID or registry lead to this error:mad:
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Error "Invalid class string" when returning from a .Net DLL

Thanks to all who viewed and thanks for your reply Dilbert.

We figured it out. We needed to run the following command on the PC from our Acu BIN folder:

marshal /regserver

I had forgotten that I had done this on the two PC's that it worked on, since I had done it some months ago. In addition, I thought that this was only needed if you had a .Net DLL that you wanted to CALL Cobol from. In our case here, we were not calling Cobol, we were calling .Net and then returning to Cobol.

Another issue was that on this forum there are some posts that show the marshal command as:
marshal /register

We had tried this and it didn't work. Then we searched the forum again and found another post that showed the command that worked.

As a suggestion, it would help a lot if information about marshal was added to the documentation. It would have saved us a lot of time. 🙂

Thank you,

Paul DuBois
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.