[quoted text, click to view] <dumchikov@gmail.com> wrote in message
news:1131002147.277661.193650@g14g2000cwa.googlegroups.com...
>> >Yes, I know that IADs is a COM interface. But I can implement this
>> >interface and other ADSI interfaces using C#,
>>
>> Yes, but why would you even bother to do so? System.DirectoryServices
>> with DirectoryEntry and DirectorySearcher is much easier to use in the
>> first place..... why create potential problems with interop and stuff
>> like that when you could use the out-of-the-box .NET components
>> instead?
>>
>> Marc
>> ================================================================
>> Marc Scheuner May The Source Be With You!
>> Berne, Switzerland m.scheuner -at- inova.ch
>
> Yes the DirectoryServices namespace is quite useful.
> The thing is that I need to implement my own ADSI provider on .NET. So
> I did following things:
>
> 1) Created description of IADs
>
> [ComImport]
> [InterfaceType(ComInterfaceType.InterfaceIsDual)]
> [Guid("FD8256D0-FD15-11CE-ABC4-02608C9E7553")]
> public interface IADs
> {
> // Properties and methods
> }
>
> 2) Implemented this interface
> internal class ADsObject : IADs
> {
> // implementation
> }
>
> 3) Tried to use the implementation
>
> ADsObject obj = new ADsObject("adsPath");
> DirectoryEntry entry = new DirectoryEntry(obj);
>
> But the ArgumentException was thrown in the last line.
> That's the problem.
>
Let's take a close look at what you are trying to do here (if above is all
you did).
- You implemented a single interface in a managed class (IAds) and decorated
it with some COM interop attributes, the CLR will construct a CCW
representing the COM interface whenever a COM client tries to create an
instance.
- Now your managed client creates an instance of your managed class
ADsObject, what is returned is NOT a COM interface (wrapped in a RCW), it's
just a plain normal managed object reference.
Then you pass this reference as argument to to DirectoryEntry, but now the
trouble starts, your IADs "is not a"
System.DirectoryServices.Interop.UnsafeNativeMethods.IADs type, it's an
Yournamespace.IADs type. So the cast fails with a bad argument exception.
I hope you understand by now that what your are trying to do is not possible
(heaven thanks), unless you are implemeneting the provider AND your own
DirestoryServices namespace, or if you are replacing the COM provider (all
interfaces of ActiveDS.dll)) by your own native COM server, using the same
GUID's. I assume this is not something you are willing to do, right?
Willy.