none
“Unable to cast object of System.Byte[] to ActiveDs.IADsSecurityDescriptor” RRS feed

  • Question

  • My problem is that I am using LDAPconnection class and connecting over ssl. I manage to get nTSecurityDescriptor value but now getting error

    "Unable to cast object of System.Byte[] to ActiveDs.IADsSecurityDescriptor"

    I am using code like this SearchResponse response = (SearchResponse)connection.SendRequest(request); IADsSecurityDescriptor sd = (IADsSecurityDescriptor)response.Entries[0].Attributes["nTSecurityDescriptor"][0];

    Is there any error or some other way to do this?

    Tuesday, November 6, 2012 6:51 AM

Answers

  • At last I find the answer of my question. This class convert the byte[] to valid security decriptor comobject.

    ActiveDs.ADsSecurityUtility secUtility = new ActiveDs.ADsSecurityUtility();
    ActiveDs.IADsSecurityDescriptor sd = (IADsSecurityDescriptor)secUtility.ConvertSecurityDescriptor((byte[])attribute[0], (int)ADS_SD_FORMAT_ENUM.ADS_SD_FORMAT_RAW, (int)ADS_SD_FORMAT_ENUM.ADS_SD_FORMAT_IID);
    • Marked as answer by mayank.karki Saturday, November 24, 2012 7:03 AM
    Saturday, November 24, 2012 7:02 AM

All replies

  • Hi Mayank,

    Welcome to the MSDN Forum.

    How about this code?

    SearchResponse response = (SearchResponse)connection.SendRequest(request); 
    IADsSecurityDescriptor sd = (IADsSecurityDescriptor)response.Entries[0].Attributes["nTSecurityDescriptor"];

    If it doesn't work, you can check the which element of response.Entries[0].Attributes["nTSecurityDescriptor"] is a IADsSecurityDescriptor instance by setting a break point at this line, and use the quick watch .

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, November 7, 2012 1:06 PM
    Moderator
  • Hi,

    response.Entries[0].Attributes["nTSecurityDescriptor"] returns a DirectoryAttribute object which contains only one element of byte[].

    Saturday, November 17, 2012 7:20 AM
  • Add the variable 'response' to a watch item by highlighting in the valiable and the right click mouse.  Then select "add watch'.  You should be able to see how many objercts ware returned.  response.Entry[] is an array.


    jdweng

    Saturday, November 17, 2012 11:53 AM
  • At last I find the answer of my question. This class convert the byte[] to valid security decriptor comobject.

    ActiveDs.ADsSecurityUtility secUtility = new ActiveDs.ADsSecurityUtility();
    ActiveDs.IADsSecurityDescriptor sd = (IADsSecurityDescriptor)secUtility.ConvertSecurityDescriptor((byte[])attribute[0], (int)ADS_SD_FORMAT_ENUM.ADS_SD_FORMAT_RAW, (int)ADS_SD_FORMAT_ENUM.ADS_SD_FORMAT_IID);
    • Marked as answer by mayank.karki Saturday, November 24, 2012 7:03 AM
    Saturday, November 24, 2012 7:02 AM