Skip to main content

This article explains how to fix compiler error CS1503 received when a C# program is calling a COBOL program.

Problem:

A C# program is calling a .NET COBOL program passing three parameters as its arguments. You receive error CS1503 in the C# program:

C:\\Users\\ConsoleApplication1\\Program.cs(25,56): error CS1503: Argument '3': cannot convert from 'int' to 'MicroFocus.COBOL.Program.Reference'

The C# program includes the following code:


string unit = "102";
string msgtext = "";
int i = 0, r = 0;
try
{
r = cblprog.PROG1(ref unit, ref msgtext, i);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}

The COBOL program includes the following code:


Linkage section.
01 unit-no usage string.
01 return-msg-text usage string.
01 test-int pic s9(9) comp-5.
Procedure division using unit-no return-msg-text test-int.

Resolution:

The reason to receive error CS1503 in the example above is that the parameter passed to the integer parameter test-int is not correctly defined.

By default, C# passes an integer on the stack by value unless you specify it should be by reference using the keyword "ref".

By default, COBOL passes all parameters by reference unless you specify it should be by value using the keyword "by value".

You can fix the problem causing error CS1503 in one of the following ways:


  1. Change the C# code as follows:

    r = cblprog.PROG1(ref unit, ref msgtext, ref i);
  2. Or, change the COBOL code as follows:

    Procedure division using unit-no return-msg-text by value test-int.

Incident Number: 2154522

Old KB# 14570