Skip to main content

The problem occurs when creating a new list in cobol. The list defintiion is in a c# dll. Whenever the list is instantiated in code we get the following error: System.ArgumentNullException: "Key cannot be null. Arg_ParamName_Name"

The program compiles and can be started but when the line is reached, the error occurs. When setting a breakpoint the error doesn't occur but then a second error occurs. Inside of the object the list is created of we get a NullReference VARIABLENAME not set to an instance of an object. The variable is of type string and is initialized with an empty string in the constructor. The variable is private and can only be accessed over an property which does a null check as well.

Object declaration:

private string _VALUETYPE= "";
        private string _VALUE = "";
        private string _VALUE_EXTENSION = "";

        public string VALUETYPE
        {
            get { return _VALUETYPE; }
            set { _VALUETYPE = value; }
        }

        public string VALUE
        {
            get { return _VALUE; }
            set { _VALUE = value; }
        }

        public string VALUE_EXTENSION
        {
            get { return _VALUE_EXTENSION; }
            set
            {
                _VALUE_EXTENSION = value;
            }
        }

List declaration (constructor):

private readonly List<Systemtabelle> systemtabelle;


public SOList()  {
    this.systemtabelle = new List<Systemtabelle>();
    Add(new Systemtabelle());
}

List intatiation:

declare soList = new type PlainModelLibrary.Implementation.SOList()

Any idea will be welcome.


#.net
#C
#VisualCOBOL
#c

The problem occurs when creating a new list in cobol. The list defintiion is in a c# dll. Whenever the list is instantiated in code we get the following error: System.ArgumentNullException: "Key cannot be null. Arg_ParamName_Name"

The program compiles and can be started but when the line is reached, the error occurs. When setting a breakpoint the error doesn't occur but then a second error occurs. Inside of the object the list is created of we get a NullReference VARIABLENAME not set to an instance of an object. The variable is of type string and is initialized with an empty string in the constructor. The variable is private and can only be accessed over an property which does a null check as well.

Object declaration:

private string _VALUETYPE= "";
        private string _VALUE = "";
        private string _VALUE_EXTENSION = "";

        public string VALUETYPE
        {
            get { return _VALUETYPE; }
            set { _VALUETYPE = value; }
        }

        public string VALUE
        {
            get { return _VALUE; }
            set { _VALUE = value; }
        }

        public string VALUE_EXTENSION
        {
            get { return _VALUE_EXTENSION; }
            set
            {
                _VALUE_EXTENSION = value;
            }
        }

List declaration (constructor):

private readonly List<Systemtabelle> systemtabelle;


public SOList()  {
    this.systemtabelle = new List<Systemtabelle>();
    Add(new Systemtabelle());
}

List intatiation:

declare soList = new type PlainModelLibrary.Implementation.SOList()

Any idea will be welcome.


#.net
#C
#VisualCOBOL
#c

What Visual COBOL version are you using?
I get different behavior when using 8.0 but I don't knoiw what the definition of the Systemtabelle class is.

The following worked for me:

Try adding a type to the soList variable in the COBOL program:

declare soList as type PlainModelLibrary.Implementation.SOList = new type PlainModelLibrary.Implementation.SOList()


What Visual COBOL version are you using?
I get different behavior when using 8.0 but I don't knoiw what the definition of the Systemtabelle class is.

The following worked for me:

Try adding a type to the soList variable in the COBOL program:

declare soList as type PlainModelLibrary.Implementation.SOList = new type PlainModelLibrary.Implementation.SOList()

I use Visual Cobol 8.0 as well, with the latest patch.

Adding a type to the variable hasn't solved the problem.

The complete definition of the systemtabelle class is:

public class Systemtabelle
    {
        private string _VALUETYPE= "";
        private string _VALUE = "";
        private string _VALUE_EXTENSION = "";

        public string VALUETYPE
        {
            get { return _VALUETYPE; }
            set { _VALUETYPE = value; }
        }

        public string VALUE
        {
            get { return _VALUE; }
            set { _VALUE = value; }
        }

        public string VALUE_EXTENSION
        {
            get { return _VALUE_EXTENSION; }
            set
            {
                _VALUE_EXTENSION = value;
            }
        }



        public Systemtabelle() {
            this.VALUETYPE = "";
            this.VALUE = "";
            this.VALUE_EXTENSION = "";
        }  
    }

The systemtabelle class contains key value information plus an additional extension value.
The purpose is reading the key value information from a dat file, creating an systemtabelle instance with the information and adding it to the soList.

The c# dll and the cobol program are both using the .net 6 framework.


I use Visual Cobol 8.0 as well, with the latest patch.

Adding a type to the variable hasn't solved the problem.

The complete definition of the systemtabelle class is:

public class Systemtabelle
    {
        private string _VALUETYPE= "";
        private string _VALUE = "";
        private string _VALUE_EXTENSION = "";

        public string VALUETYPE
        {
            get { return _VALUETYPE; }
            set { _VALUETYPE = value; }
        }

        public string VALUE
        {
            get { return _VALUE; }
            set { _VALUE = value; }
        }

        public string VALUE_EXTENSION
        {
            get { return _VALUE_EXTENSION; }
            set
            {
                _VALUE_EXTENSION = value;
            }
        }



        public Systemtabelle() {
            this.VALUETYPE = "";
            this.VALUE = "";
            this.VALUE_EXTENSION = "";
        }  
    }

The systemtabelle class contains key value information plus an additional extension value.
The purpose is reading the key value information from a dat file, creating an systemtabelle instance with the information and adding it to the soList.

The c# dll and the cobol program are both using the .net 6 framework.

I tested this with Visual COBOL 8.0 PU4 with .NET 6.0 and did not experience the issue you report.

I had to change one line of code because I was getting an error on it.
I changed the Add statement to read:

systemtabelle.Add(new Systemtabelle());

This is what I am using as a test:

namespace testlistnull
{
    public class SOList
    {
        private string _VALUETYPE = "";
        private string _VALUE = "";
        private string _VALUE_EXTENSION = "";

        public string VALUETYPE
        {
            get { return _VALUETYPE; }
            set { _VALUETYPE = value; }
        }

        public string VALUE
        {
            get { return _VALUE; }
            set { _VALUE = value; }
        }

        public string VALUE_EXTENSION
        {
            get { return _VALUE_EXTENSION; }
            set
            {
                _VALUE_EXTENSION = value;
            }
        }

        private readonly List<Systemtabelle> systemtabelle;

        public SOList()
        {
            this.systemtabelle = new List<Systemtabelle>();

            systemtabelle.Add(new Systemtabelle());
        }
    }
    public class Systemtabelle
    {
        private string _VALUETYPE = "";
        private string _VALUE = "";
        private string _VALUE_EXTENSION = "";

        public string VALUETYPE
        {
            get { return _VALUETYPE; }
            set { _VALUETYPE = value; }
        }

        public string VALUE
        {
            get { return _VALUE; }
            set { _VALUE = value; }
        }

        public string VALUE_EXTENSION
        {
            get { return _VALUE_EXTENSION; }
            set
            {
                _VALUE_EXTENSION = value;
            }
        }
        public Systemtabelle()
        {
            this.VALUETYPE = "";
            this.VALUE = "";
            this.VALUE_EXTENSION = "";
        }
    }
}

And the COBOL:

declare soList = new type testlistnull.SOList()


I tested this with Visual COBOL 8.0 PU4 with .NET 6.0 and did not experience the issue you report.

I had to change one line of code because I was getting an error on it.
I changed the Add statement to read:

systemtabelle.Add(new Systemtabelle());

This is what I am using as a test:

namespace testlistnull
{
    public class SOList
    {
        private string _VALUETYPE = "";
        private string _VALUE = "";
        private string _VALUE_EXTENSION = "";

        public string VALUETYPE
        {
            get { return _VALUETYPE; }
            set { _VALUETYPE = value; }
        }

        public string VALUE
        {
            get { return _VALUE; }
            set { _VALUE = value; }
        }

        public string VALUE_EXTENSION
        {
            get { return _VALUE_EXTENSION; }
            set
            {
                _VALUE_EXTENSION = value;
            }
        }

        private readonly List<Systemtabelle> systemtabelle;

        public SOList()
        {
            this.systemtabelle = new List<Systemtabelle>();

            systemtabelle.Add(new Systemtabelle());
        }
    }
    public class Systemtabelle
    {
        private string _VALUETYPE = "";
        private string _VALUE = "";
        private string _VALUE_EXTENSION = "";

        public string VALUETYPE
        {
            get { return _VALUETYPE; }
            set { _VALUETYPE = value; }
        }

        public string VALUE
        {
            get { return _VALUE; }
            set { _VALUE = value; }
        }

        public string VALUE_EXTENSION
        {
            get { return _VALUE_EXTENSION; }
            set
            {
                _VALUE_EXTENSION = value;
            }
        }
        public Systemtabelle()
        {
            this.VALUETYPE = "";
            this.VALUE = "";
            this.VALUE_EXTENSION = "";
        }
    }
}

And the COBOL:

declare soList = new type testlistnull.SOList()

I tested the affected code in a new test project with a c# library and a main cobol program, where it worked. So it has to have something to do with the configuration of the main cobol project I think. The code itself works just fine. I submitted a ticket to the support.