Willy Denoyette [MVP] ():
> IAds is a COM native interface, how did you manage to get your version
> registered correctly?
> Also, I'm not clear what language was used to implement your version? .Net
> is not a language it's a ... well it's actualy a marketing term ;-).
>
> Willy.
Yes, I know that IADs is a COM interface. But I can implement this
interface and other ADSI interfaces using C#, then add needed records
to the registry. As I understood, I can register my COM server written
on C# as well as it was written on unmanaged C++. During loading the
dll with managed code Windows will understand, that it is a manage
assembly and load MSCorEE.dll to perform interop tasks.
But my question is about how to use .NET implementation of ADSI in the
DirectoryServices namespace.
Marc Scheuner [MVP ADSI] - 03 Nov 2005 07:29 GMT
>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
dumchikov@gmail.com - 03 Nov 2005 08:15 GMT
> >Yes, I know that IADs is a COM interface. But I can implement this
> >interface and other ADSI interfaces using C#,
[quoted text clipped - 9 lines]
> 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.
Willy Denoyette [MVP] - 03 Nov 2005 18:22 GMT
>> >Yes, I know that IADs is a COM interface. But I can implement this
>> >interface and other ADSI interfaces using C#,
[quoted text clipped - 37 lines]
> 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.