private static Transaction JitSafeGetContextTransaction(ContextData contextData)
        {
            SafeIUnknown safeUnknown = null;

            if (contextData.WeakDefaultComContext != null)
            {
                safeUnknown = (SafeIUnknown)contextData.WeakDefaultComContext.Target;
            }
            if ((contextData.DefaultComContextState == DefaultComContextState.Unknown) || ((contextData.DefaultComContextState == DefaultComContextState.Available) && (safeUnknown == null)))
            {
                try
                {
                    System.Transactions.NativeMethods.CoGetDefaultContext(-1, ref IID_IObjContext, out safeUnknown);
                    contextData.WeakDefaultComContext  = new WeakReference(safeUnknown);
                    contextData.DefaultComContextState = DefaultComContextState.Available;
                }
                catch (EntryPointNotFoundException exception)
                {
                    if (DiagnosticTrace.Verbose)
                    {
                        ExceptionConsumedTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceBase"), exception);
                    }
                    contextData.DefaultComContextState = DefaultComContextState.Unavailable;
                }
            }
            if (contextData.DefaultComContextState == DefaultComContextState.Available)
            {
                IntPtr zero = IntPtr.Zero;
                System.Transactions.NativeMethods.CoGetContextToken(out zero);
                if (safeUnknown.DangerousGetHandle() == zero)
                {
                    return(null);
                }
            }
            if (!ContextUtil.IsInTransaction)
            {
                return(null);
            }
            return(ContextUtil.SystemTransaction);
        }
Example #2
0
 internal static extern void CoGetDefaultContext(Int32 aptType, ref Guid contextInterface, out SafeIUnknown safeUnknown);
 internal static extern void CoGetDefaultContext(int aptType, ref Guid contextInterface, out SafeIUnknown safeUnknown);