Groups | Blog | Home
all groups > dotnet security > november 2007 >

dotnet security : Need help with error adding meetingBlob to a meeting class object



Pucca
11/2/2007 1:30:20 PM
I got the following error:
System.ArgumentException: Value does not fall within the expected range. At
System.DirectorySservcies.Interop.UnsafeNativeMethods.IAds.PutEx(Int32
InControlCode, String bstrName, Object vProp) at
System.DirecotryServices.PropertyValueCollection.set_Value(Object value)


public struct Blob
{
public IntPtr pData;
public int nLength;//the length of the actual data in nLength and
public int nSize;//the length of the buffer for the data in nSize.

}
[DllImport("PaAsn.dll", CharSet = CharSet.Unicode)]
public static extern DE_ERRORS EncodeContextDefaults(ref IntPtr blob,
[In, Out]ContextDefaults m);

// allocate memry for the blob
IntPtr pBlob = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(CDS.Blob)));
// call the function passing the pointer to the blob
byrefEncodeContextDefaults
CDS.LibWrap.EncodeContextDefaults(ref pBlob, contextDefaults);
// copy the unmanaged blob to managed struct Blob
CDS.Blob blob = (CDS.Blob)Marshal.PtrToStructure(pBlob, typeof(CDS.Blob));
// allocate byte array with size of blob.nLength
byte[] meetingBlob = new byte[blob.nLength];
// marshal the data pointed to by pData into the byte array
System.Runtime.InteropServices.Marshal.Copy(blob.pData, meetingBlob, 0,
blob.nLength);
defaultContext.Properties["meetingBlob"].Value = ((object)(blob));
defaultContext.CommitChanges();

Joe Kaplan
11/2/2007 3:50:42 PM
Shouldn't you be passing in the byte array, meetingBlob, and not the
structure, blob, to the DirectoryEntry?

Joe K.

--
Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
--
[quoted text, click to view]

Pucca
11/2/2007 4:26:00 PM
Yes, you're absolutely right. Thank you very much!
--
Thanks.


[quoted text, click to view]
AddThis Social Bookmark Button