Absent Member.
Absent Member.

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

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


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

           NAME    "@TestCall"
           VERSION ""
           CULTURE "neutral"
           STRONG  "null"

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

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


      * [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:

       AUTHOR. EDC (PWD).
               Calls a .Net DLL.

       COPY 'testcall.def'.
       01  TESTCALL-HANDLE                     USAGE IS HANDLE.
           CREATE "TestCall"
                NAMESPACE IS "TestCall"
                CLASS-NAME IS "Class1"
           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 of the compiler.
The runtime version is

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
2 Replies
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:
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
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.