Absent Member.
Absent Member.
2672 views

.NetCobol invoking a C# method. Error COBCH0829.

.Net Cobol class:

      $set ilusing "CSharpPrograms"

       class-id. CobolMain.

       method-id. main public.

           invoke type Console::WriteLine("CobolMain: Hello World")

           invoke type CSharpSub::DisplayMethod()

       end method main.

       end class.

  

C# Class:

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

//  This is an experiment of calling a C# program from a Cobol main program.

 

namespace CSharpPrograms

{

  public class CSharpSub

  {

    public void DisplayMethod()

    {

      Console.WriteLine("CSharpSub: Hello World");

    }

    static void Main()

    {

    }

  }

}

  

When building, I get the error below in the Cobol class.  I have tried many things.  Is there some special Cobol syntax I am not using?  Thanks.

 

Error 1     COBCH0829: Could not find method 'DisplayMethod' with this signature

0 Likes
1 Reply
Highlighted
Micro Focus Expert
Micro Focus Expert

There are a couple of problems with your example.

1. You have a main method in both the COBOL project and the C# project. You should remove the main method from the C# project and make the main method in COBOL a static method.

2, The invoke in the COBOL program is using the type specifyer which is used to invoke static methods yet the C# method is not defined as being static. If you wish to call an instance method in the C# program then you must first create an instance of the class in COBOL and then call the method on the instance:

Example:

01 myinstance  type CSharpPrograms.CSharpSub.

  set myinstance to new CSharpSub

  invoke myinstance::DisplayMethod

To call it as a static method you would use the following:

     $set ilusing"CSharpPrograms"
      class-id. CobolMain.
      method-id. main static.
      procedure division.
          invoke type Console::WriteLine("CobolMain: Hello World")
          invoke type CSharpPrograms.CSharpSub::DisplayMethod
      end method main.
      end class.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CSharpPrograms
{
   public class CSharpSub
   {
       public static void DisplayMethod()
       {
           Console.WriteLine("CSharpSub: Hello World");
       }
   }
}

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.