Нужна помощь с Marshal.GetObjectForIUnknown
От: BEMN_Vlad  
Дата: 30.07.09 12:38
Оценка:
В кратце есть COM+ сервер на C#. Есть библиотека типов. Объект сервера создается. Точнее не сам объект, а System.Runtime.Remoting.Proxies.__TransparentProxy, что впринципе не важно. Далее с сервера вызывается функция которая создает в сервере объект и ссылка на этот объект возвращается клиенту, после чего не понятно как получить объект этот на клиенте через ссылку.
object _group = Marshal.GetObjectForIUnknown((IntPtr)pUnk); — генерирует ошибку :

[The runtime has encountered a fatal error. The address of the error was at 0x79f82af6, on thread 0x6e4. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.]

Вот код клиентской части :

           Type interfaceType = typeof(IOPCServer);
            object[] interfaceAttributes = interfaceType.GetCustomAttributes(false);
            object guidAttribute = Array.Find(interfaceAttributes, delegate(object l_Attributes) { return (l_Attributes is GuidAttribute); });
            string sGuid = ((GuidAttribute)guidAttribute).Value;

            string _progIdT = "BEMN.OPC_SERVER";
            string filter = String.Format("{0}\\Clsid", _progIdT);
            RegistryKey key = Registry.ClassesRoot.OpenSubKey(filter, false);
            string clsid = key.GetValue(String.Empty).ToString();

            Guid CLSID_MyClass = new Guid(clsid);
            Guid IID_MyInterface = new Guid(sGuid);

            IntPtr pTB = new IntPtr();
            IntPtr pPD = new IntPtr();
            int hServer = -1;
            int pRUR = -1;
            Guid gg = new Guid();
            object pUnk = new object();
            
            try
            {
                object classObj = BEMN.COM.Activator.Activator.CreateInstance(IID_MyInterface,
                CLSID_MyClass, CLSCTX.CLSCTX_ALL, "haritonov");

                IOPCServer _OPC_SERVER = (classObj as IOPCServer);
                _OPC_SERVER.AddGroup("01", 1, 1, 1, pTB, pPD, 1, out hServer, out pRUR, ref gg, out pUnk);

                object _group = Marshal.GetObjectForIUnknown((IntPtr)pUnk); - Тут ошибка.

            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }



З.Ы. Сервер загружается в dllhost. Т.е. не в адресном пространстве клиента.

Может кто то может подсказать?
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.