[Mono-list] Getting an octet string attribute value via DirectorServices (?)

Adam Tauno Williams adam@morrison-ind.com
Thu, 18 Nov 2004 16:34:18 -0500


I have an octet string attribute I'm trying to read from an LDAP server,
and according the the MSDN article 
http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/sds/sds/octet_string__sid__property_type.asp
I shoule be able to cast the value to a byte[].  But when I try to do so
in Mono I get a "Cannot cast from source type to destination type."
exception.
-----------<snip>----------------------------------------------
DirectoryEntry					dsAgent;
DirectorySearcher				searchAgent;
SearchResult					searchResult;
string						searchRoot;
byte[]						prefValue;

....
dsAgent = new DirectoryEntry(searchRoot);
searchAgent = new DirectorySearcher(dsAgent);
searchAgent.SearchScope = SearchScope.OneLevel;
searchAgent.Filter = "(&(objectclass=morrisonapplicationpreference)" +
                       "(morrisonapplicationname=" + appName + ")" +
                       "(morrisonpreferencename=" + prefName + "))";
searchResult = searchAgent.FindOne();
if (searchResult == null) {
  Console.WriteLine("No matching object found");
 } else {
     DirectoryEntry de = searchResult.GetDirectoryEntry();
     prefValue =
(sbyte[])de.Properties["morrisonpreferencevalue"].Value;
    }
-----------<end snip>----------------------------------------------
mono-core-1.0.4-1.ximian.10.1
SuSe Pro 9.2