Quantcast
Channel: Visual COBOL - Forum - Recent Threads
Viewing all articles
Browse latest Browse all 4356

RE: .NetCobol invoking a C# method. Error COBCH0829.

$
0
0

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");
       }
   }
}


Viewing all articles
Browse latest Browse all 4356

Trending Articles