COBCH0845 Unknown class: DirectoryServices in Visual COBOL

[Migrated content. Thread originally posted on 02 May 2012]

I am getting the above error when I try to reference System.DirectoryServices.AccountManagement. The IDE allows me to add the reference and intellisense pops up like it knows it's there but then it gives me an error saying it is an unknown class. What am I doing wrong?

Alternatively, I have created a C# method to validate user credentials using the DirectoryServices.AccountManagement and would like to call the method from Managed COBOL but have not found any examples of how to do this. Could you provide me with one?

  • System.DirectoryServices.AccountManagement is not a class it is a namespace.

    To use it you must add a reference in the COBOL project to the System.DirectoryServices.AccountManagement assembly.

    If you post what your C# method looks like then I will show you how it can be done in Visual COBOL.

    C# methods can be called from COBOL by simply adding a reference in the COBOL project to the C# Project and then invoking its methods.

    01 mycsClass   type csproject.csclass.
    01 myparam     string.
    01 myreturn    string.
        set mycsClass to new type csproject.csclass   *> Create new instance of class
        set myreturn to mycsClass::mymethod(myparam)  *> with return parameters
        invoke mycsClass::mymethod(myparams)     *> no return parameters

  • Thanks for your help!!
    I did include a reference to the assembly but it gave me the class error.

    The C# code is below. I'm trying to do the equivalent in Visual COBOL:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.DirectoryServices.AccountManagement;

    namespace DomainSecurity
    public class DomainSecurityValidation
    public bool ValidateUser (string strDomain, string strUsername, string strPassword)
    using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, strDomain))
    bool isValid = pc.ValidateCredentials(strUsername, strPassword);
    return isValid;
    return false;
  • Verified Answer

    In Visual COBOL this would look like:

          $set ilusing"System.Collections.Generic"
          $set ilusing"Stsrem.Text"
          $set ilusing"System.DirectoryServices.AccountManagement"
           class-id DomainSecurity.DomainSecurityValidation.
           working-storage section.

           method-id ValidateUser.
           local-storage section.
           01 pc    type PrincipalContext.
           procedure division using strDomain as string, strUsername as string, strPassword as string
                              returning isValid as Condition-value.
                  set pc to new PrincipalContext(type ContextType::Domain, strDomain)
                  set isValid to pc::ValidateCredentials(strUsername, strPassword)
                  set isValid to false
  • I am trying to implement HASH algorithm in Enterprise Developer 3.0
    for Eclipse. Can you please suggest which directives I need to include. and what setup need to done.
  • No, because there are thousands of well-documented hash functions, and an infinite number of possible hash algorithms (and a finite but very large number that can be implemented on generally-available hardware). You haven't told us anything meaningful in your question.

    What are you trying to accomplish? Why? What are you using to do it?

    Also, this is not the appropriate place to ask. Don't reply to an unrelated thread with a new question. Create a new topic in the forum for the product you're using.
  • Hi Michael,

    I am writing a program to store the password in projected by using the Hash algorithm. while writing the below code getting error "COBCH0845S Unknown type 'type System.Security.Cryptography.SHA1Managed'"
    - COBCH0012S Operand mymessage is not declared
    COBCH0845S Unknown type 'type System.Text.StringBuilder'

    Program :------

    configuration section.

    class cSHA1Managed as "System.Security.Cryptography.SHA1Managed"

    class cStringBuilder as "System.Text.StringBuilder".
    data division.
    working-storage section.

    01 PWD pic x(22) value "This is a TEST String.".

    01 mySHA1 cSHA1Managed.
    Errror : "COBCH0845S Unknown type 'type System.Security.Cryptography.SHA1Managed'"
    01 myByteArray binary-char unsigned occurs any. *> Byte Array

    01 myHash
    binary-char unsigned occurs any. *> Byte Array

    01 ws-byte binary-char unsigned. *> Byte

    01 strBuilder cStringBuilder.
    Error : "COBCH0845S Unknown type 'type System.Security.Cryptography.SHA1Managed'"
    01 array-len binary-long.

    procedure division.
    ***** Create a SHA1 Hashing Instance
    set mySHA1 to cSHA1Managed::"New"()

    set myByteArray to mymessage
    Error : -- Multiple markers at this line
    - COBCH1710S 'type HashIt' has no member with name 'mymessage'
    - COBCH0012S Operand mymessage is not declared
    set myHash to mySHA1::"ComputeHash"(myByteArray)

    create-hex-string section.


    * Create Hex String from Byte[]

    set strBuilder to cStringBuilder::"New"()

    set array-len to myHash::"Length"

    move length of myHash to array-len

    perform varying ws-byte through myHash

    invoke strBuilder::"Append"(String::"Format"("{0,2:x}", ws-byte)::"Replace"(" " , "0"))

    end program HashIt.


    Can you please guide/suggest. This may not be the right one for Enterprise Developer for Eclipse.
  • Again: This is not the forum in which to post this question. Please start a new topic in the Visual COBOL or Enterprise Developer forum. Visual COBOL would probably be better, since you don't seem to be asking about any features specific to Enterprise Developer.

    When you do, please include the product you're using, its version, and the type of code (native, .NET, JVM) you're generating.