Exemplo n.º 1
0
        internal IProxyProvider GetProxyProvider()
        {
            if (null == monikerSupportLibrary)
            {
                lock (this)
                {
                    if (null == monikerSupportLibrary)
                    {
                        getCODelegate = null;
                        using (RegistryHandle regKey = RegistryHandle.GetCorrectBitnessHKLMSubkey((IntPtr.Size == 8), ServiceModelInstallStrings.WinFXRegistryKey))
                        {
                            string            file        = regKey.GetStringValue(ServiceModelInstallStrings.RuntimeInstallPathName).TrimEnd('\0') + "\\" + fileName;
                            SafeLibraryHandle tempLibrary = UnsafeNativeMethods.LoadLibrary(file);
                            tempLibrary.DoNotFreeLibraryOnRelease();

                            monikerSupportLibrary = tempLibrary;
                            if (monikerSupportLibrary.IsInvalid)
                            {
                                monikerSupportLibrary.SetHandleAsInvalid();
                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ServiceMonikerSupportLoadFailed(file));
                            }
                        }
                    }
                }
            }

            if (null == getCODelegate)
            {
                lock (this)
                {
                    if (null == getCODelegate)
                    {
                        try
                        {
                            IntPtr procaddr = UnsafeNativeMethods.GetProcAddress(monikerSupportLibrary, functionName);
                            getCODelegate = (DelegateDllGetClassObject)Marshal.GetDelegateForFunctionPointer(procaddr, typeof(DelegateDllGetClassObject));
                        }
                        catch (Exception e)
                        {
                            if (Fx.IsFatal(e))
                            {
                                throw;
                            }

                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ComPlusProxyProviderException(SR.GetString(SR.FailedProxyProviderCreation), e));
                        }
                    }
                }
            }

            IClassFactory  cf            = null;
            IProxyProvider proxyProvider = null;

            try
            {
                getCODelegate(ClsidProxyInstanceProvider, typeof(IClassFactory).GUID, ref cf);

                proxyProvider = cf.CreateInstance(null, typeof(IProxyProvider).GUID) as IProxyProvider;
                Thread.MemoryBarrier();
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }

                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ComPlusProxyProviderException(SR.GetString(SR.FailedProxyProviderCreation), e));
            }
            finally
            {
                if (null != cf)
                {
                    Marshal.ReleaseComObject(cf);
                    cf = null;
                }
            }

            return(proxyProvider);
        }
Exemplo n.º 2
0
 internal ProxySupportWrapper()
 {
     monikerSupportLibrary = null;
     getCODelegate         = null;
 }
 internal IProxyProvider GetProxyProvider()
 {
     if (this.monikerSupportLibrary == null)
     {
         lock (this)
         {
             if (this.monikerSupportLibrary == null)
             {
                 this.getCODelegate = null;
                 using (RegistryHandle handle = RegistryHandle.GetCorrectBitnessHKLMSubkey(IntPtr.Size == 8, @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Client"))
                 {
                     string libFilename = handle.GetStringValue("InstallPath").TrimEnd(new char[1]) + @"\ServiceMonikerSupport.dll";
                     this.monikerSupportLibrary = UnsafeNativeMethods.LoadLibrary(libFilename);
                     this.monikerSupportLibrary.DoNotFreeLibraryOnRelease();
                     if (this.monikerSupportLibrary.IsInvalid)
                     {
                         this.monikerSupportLibrary.SetHandleAsInvalid();
                         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ServiceMonikerSupportLoadFailed(libFilename));
                     }
                 }
             }
         }
     }
     if (this.getCODelegate == null)
     {
         lock (this)
         {
             if (this.getCODelegate == null)
             {
                 try
                 {
                     IntPtr procAddress = UnsafeNativeMethods.GetProcAddress(this.monikerSupportLibrary, "DllGetClassObject");
                     this.getCODelegate = (DelegateDllGetClassObject) Marshal.GetDelegateForFunctionPointer(procAddress, typeof(DelegateDllGetClassObject));
                 }
                 catch (Exception exception)
                 {
                     if (Fx.IsFatal(exception))
                     {
                         throw;
                     }
                     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ComPlusProxyProviderException(System.ServiceModel.SR.GetString("FailedProxyProviderCreation"), exception));
                 }
             }
         }
     }
     IClassFactory ppv = null;
     IProxyProvider provider = null;
     try
     {
         this.getCODelegate(ClsidProxyInstanceProvider, typeof(IClassFactory).GUID, ref ppv);
         provider = ppv.CreateInstance(null, typeof(IProxyProvider).GUID) as IProxyProvider;
         Thread.MemoryBarrier();
     }
     catch (Exception exception2)
     {
         if (Fx.IsFatal(exception2))
         {
             throw;
         }
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ComPlusProxyProviderException(System.ServiceModel.SR.GetString("FailedProxyProviderCreation"), exception2));
     }
     finally
     {
         if (ppv != null)
         {
             Marshal.ReleaseComObject(ppv);
             ppv = null;
         }
     }
     return provider;
 }
        internal IProxyProvider GetProxyProvider()
        {
            if (this.monikerSupportLibrary == null)
            {
                lock (this)
                {
                    if (this.monikerSupportLibrary == null)
                    {
                        this.getCODelegate = null;
                        using (RegistryHandle handle = RegistryHandle.GetCorrectBitnessHKLMSubkey(IntPtr.Size == 8, @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Client"))
                        {
                            string libFilename = handle.GetStringValue("InstallPath").TrimEnd(new char[1]) + @"\ServiceMonikerSupport.dll";
                            this.monikerSupportLibrary = UnsafeNativeMethods.LoadLibrary(libFilename);
                            this.monikerSupportLibrary.DoNotFreeLibraryOnRelease();
                            if (this.monikerSupportLibrary.IsInvalid)
                            {
                                this.monikerSupportLibrary.SetHandleAsInvalid();
                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ServiceMonikerSupportLoadFailed(libFilename));
                            }
                        }
                    }
                }
            }
            if (this.getCODelegate == null)
            {
                lock (this)
                {
                    if (this.getCODelegate == null)
                    {
                        try
                        {
                            IntPtr procAddress = UnsafeNativeMethods.GetProcAddress(this.monikerSupportLibrary, "DllGetClassObject");
                            this.getCODelegate = (DelegateDllGetClassObject)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(DelegateDllGetClassObject));
                        }
                        catch (Exception exception)
                        {
                            if (Fx.IsFatal(exception))
                            {
                                throw;
                            }
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ComPlusProxyProviderException(System.ServiceModel.SR.GetString("FailedProxyProviderCreation"), exception));
                        }
                    }
                }
            }
            IClassFactory  ppv      = null;
            IProxyProvider provider = null;

            try
            {
                this.getCODelegate(ClsidProxyInstanceProvider, typeof(IClassFactory).GUID, ref ppv);
                provider = ppv.CreateInstance(null, typeof(IProxyProvider).GUID) as IProxyProvider;
                Thread.MemoryBarrier();
            }
            catch (Exception exception2)
            {
                if (Fx.IsFatal(exception2))
                {
                    throw;
                }
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ComPlusProxyProviderException(System.ServiceModel.SR.GetString("FailedProxyProviderCreation"), exception2));
            }
            finally
            {
                if (ppv != null)
                {
                    Marshal.ReleaseComObject(ppv);
                    ppv = null;
                }
            }
            return(provider);
        }
        internal IProxyProvider GetProxyProvider()
        {
            if (null == monikerSupportLibrary)
            {
                lock (this)
                {
                    if (null == monikerSupportLibrary)
                    {
                        getCODelegate = null;
                        using (RegistryHandle regKey = RegistryHandle.GetCorrectBitnessHKLMSubkey((IntPtr.Size == 8), ServiceModelInstallStrings.WinFXRegistryKey))
                        {
                            string file = regKey.GetStringValue(ServiceModelInstallStrings.RuntimeInstallPathName).TrimEnd('\0') + "\\" + fileName;
                            SafeLibraryHandle tempLibrary = UnsafeNativeMethods.LoadLibrary(file);
                            tempLibrary.DoNotFreeLibraryOnRelease();

                            monikerSupportLibrary = tempLibrary;
                            if (monikerSupportLibrary.IsInvalid)
                            {
                                monikerSupportLibrary.SetHandleAsInvalid();
                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ServiceMonikerSupportLoadFailed(file));
                            }
                        }
                    }
                }
            }

            if (null == getCODelegate)
            {
                lock (this)
                {
                    if (null == getCODelegate)
                    {
                        try
                        {
                            IntPtr procaddr = UnsafeNativeMethods.GetProcAddress(monikerSupportLibrary, functionName);
                            getCODelegate = (DelegateDllGetClassObject)Marshal.GetDelegateForFunctionPointer(procaddr, typeof(DelegateDllGetClassObject));

                        }
                        catch (Exception e)
                        {
                            if (Fx.IsFatal(e))
                                throw;

                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ComPlusProxyProviderException(SR.GetString(SR.FailedProxyProviderCreation), e));
                        }
                    }
                }
            }

            IClassFactory cf = null;
            IProxyProvider proxyProvider = null;

            try
            {
                getCODelegate(ClsidProxyInstanceProvider, typeof(IClassFactory).GUID, ref cf);

                proxyProvider = cf.CreateInstance(null, typeof(IProxyProvider).GUID) as IProxyProvider;
                Thread.MemoryBarrier();
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                    throw;

                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ComPlusProxyProviderException(SR.GetString(SR.FailedProxyProviderCreation), e));
            }
            finally
            {
                if (null != cf)
                {
                    Marshal.ReleaseComObject(cf);
                    cf = null;
                }
            }

            return proxyProvider;
        }
 internal ProxySupportWrapper()
 {
     monikerSupportLibrary = null;
     getCODelegate = null;
 }