The CoInitializeSecurity settings are thread-specific. If you create a new 
thread and do all the COM work on that, do you get the same error?

I seem to recall discovering that there was something about the AssemblyResolve 
hook that forced COM to be initialized.

From: ironruby-core-boun...@rubyforge.org 
[mailto:ironruby-core-boun...@rubyforge.org] On Behalf Of Orion Edwards
Sent: Wednesday, August 12, 2009 6:00 PM
To: ironruby-core@rubyforge.org
Subject: [Ironruby-core] COM security question

I'm having a go at automating Microsoft Virtual Server 2005 R2 using the COM 
API's via IronRuby.

Virtual Server requires the COM security level to be set to 'Impersonation' or 
higher (as mentioned here 
http://msdn.microsoft.com/en-us/library/aa367595(VS.85).aspx )

The sample code is missing from that particular MSDN page, but essentially what 
it does is call CoInitializeSecurity as follows

CoInitializeSecurity(IntPtr.Zero,
            -1,
            IntPtr.Zero,
            IntPtr.Zero,
            (uint)RpcAuthnLevel.PktPrivacy,
            (uint)RpcImpLevel.Impersonate,
            IntPtr.Zero,
            (uint)EoAuthnCap.DynamicCloaking,
            IntPtr.Zero);

I've created a small C# wrapper dll which does that, but when I try to call it 
from within IronRuby, the following exception occurs:

:0: Security must be initialized before any interfaces are marshalled or 
unmarshalled. It cannot be changed once initialized. (Exception from HRESULT: 
0x80010119) (System::Runtime::InteropServices::COMException)

This implies that IronRuby is doing some COM or marshalling stuff internally, 
and it's too late for me to call CoInit.

Thus far, I'm stumped - Is there anything I can do to work around this?

Thanks a lot, Orion.

PS: I'm using IronRuby 0.9. I've been really impressed by the performance 
improvements since earlier versions, congratulations on all the good work so 
far. Just need to improve the startup time and it'll be awesome!
_______________________________________________
Ironruby-core mailing list
Ironruby-core@rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core

Reply via email to