private Assembly ResolveAssemblyFromTypeLibID(Guid iid, Guid typeLibraryID, string version, bool noAssemblyGeneration)
        {
            Assembly assembly;

            ComPlusTLBImportTrace.Trace(TraceEventType.Verbose, 0x5000d, "TraceCodeComIntegrationTLBImportStarting", iid, typeLibraryID);
            bool      flag        = false;
            ITypeLib2 typeLibrary = null;

            try
            {
                lock (this.assemblyTableLock)
                {
                    this.assemblyTable.TryGetValue(typeLibraryID, out assembly);
                    if (assembly == null)
                    {
                        typeLibrary = this.GettypeLibrary(typeLibraryID, version);
                        object pVarVal = null;
                        typeLibrary.GetCustData(ref clrAssemblyCustomID, out pVarVal);
                        if (pVarVal == null)
                        {
                            flag = true;
                        }
                        string str = pVarVal as string;
                        if (string.IsNullOrEmpty(str))
                        {
                            flag = true;
                        }
                        if (noAssemblyGeneration && flag)
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("NativeTypeLibraryNotAllowed", new object[] { typeLibraryID })));
                        }
                        if (!flag)
                        {
                            ComPlusTLBImportTrace.Trace(TraceEventType.Verbose, 0x5000e, "TraceCodeComIntegrationTLBImportFromAssembly", iid, typeLibraryID, str);
                            assembly = Assembly.Load(str);
                        }
                        else
                        {
                            ComPlusTLBImportTrace.Trace(TraceEventType.Verbose, 0x5000f, "TraceCodeComIntegrationTLBImportFromTypelib", iid, typeLibraryID);
                            assembly = TypeLibraryHelper.GenerateAssemblyFromNativeTypeLibrary(iid, typeLibraryID, typeLibrary);
                        }
                        this.assemblyTable[typeLibraryID] = assembly;
                    }
                }
            }
            catch (Exception exception)
            {
                DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, EventLogCategory.ComPlus, (EventLogEventId)(-1073610728), new string[] { iid.ToString(), typeLibraryID.ToString(), exception.ToString() });
                throw;
            }
            finally
            {
                if (typeLibrary != null)
                {
                    Marshal.ReleaseComObject(typeLibrary);
                }
            }
            if (null == assembly)
            {
                throw Fx.AssertAndThrow("Assembly should not be null");
            }
            ComPlusTLBImportTrace.Trace(TraceEventType.Verbose, 0x50011, "TraceCodeComIntegrationTLBImportFinished", iid, typeLibraryID);
            return(assembly);
        }
Exemplo n.º 2
0
 void ITypeLibImporterNotifySink.ReportEvent(ImporterEventKind eventKind, int eventCode, string eventMsg)
 {
     ComPlusTLBImportTrace.Trace(TraceEventType.Verbose, TraceCode.ComIntegrationTLBImportConverterEvent,
                                 SR.TraceCodeComIntegrationTLBImportConverterEvent, iid, typeLibraryID, eventKind, eventCode, eventMsg);
 }
        private Assembly ResolveAssemblyFromTypeLibID(Guid iid, Guid typeLibraryID, string version, bool parseVersionAsHex, bool noAssemblyGeneration)
        {
            ComPlusTLBImportTrace.Trace(TraceEventType.Verbose, TraceCode.ComIntegrationTLBImportStarting,
                                        SR.TraceCodeComIntegrationTLBImportStarting, iid, typeLibraryID);
            Assembly asm;

            bool      generateNativeAssembly = false;
            ITypeLib2 typeLibrary            = null;

            try
            {
                lock (assemblyTableLock)
                {
                    assemblyTable.TryGetValue(typeLibraryID, out asm);
                    if (asm == null)
                    {
                        typeLibrary = GettypeLibrary(typeLibraryID, version, parseVersionAsHex);
                        object opaqueData = null;
                        typeLibrary.GetCustData(ref clrAssemblyCustomID, out opaqueData);
                        if (opaqueData == null)
                        {
                            generateNativeAssembly = true;      // No custom data for this IID this is not a CLR typeLibrary
                        }
                        String assembly = opaqueData as String;
                        if (String.IsNullOrEmpty(assembly))
                        {
                            generateNativeAssembly = true;      // No custom data for this IID this is not a CLR typeLibrary
                        }
                        if (noAssemblyGeneration && generateNativeAssembly)
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.NativeTypeLibraryNotAllowed, typeLibraryID)));
                        }
                        else if (!generateNativeAssembly)
                        {
                            ComPlusTLBImportTrace.Trace(TraceEventType.Verbose, TraceCode.ComIntegrationTLBImportFromAssembly,
                                                        SR.TraceCodeComIntegrationTLBImportFromAssembly, iid, typeLibraryID, assembly);
                            asm = Assembly.Load(assembly);            // Assembly.Load will get a full assembly name
                        }
                        else
                        {
                            ComPlusTLBImportTrace.Trace(TraceEventType.Verbose, TraceCode.ComIntegrationTLBImportFromTypelib,
                                                        SR.TraceCodeComIntegrationTLBImportFromTypelib, iid, typeLibraryID);
                            asm = TypeLibraryHelper.GenerateAssemblyFromNativeTypeLibrary(iid, typeLibraryID, typeLibrary as ITypeLib);
                        }

                        assemblyTable[typeLibraryID] = asm;
                    }
                }
            }
            catch (Exception e)
            {
                DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error,
                                                    (ushort)System.Runtime.Diagnostics.EventLogCategory.ComPlus,
                                                    (uint)System.Runtime.Diagnostics.EventLogEventId.ComPlusTLBImportError,
                                                    iid.ToString(),
                                                    typeLibraryID.ToString(),
                                                    e.ToString());
                throw;
            }
            finally
            {
                // Add Try Finally to cleanup typeLibrary
                if (typeLibrary != null)
                {
                    Marshal.ReleaseComObject((object)typeLibrary);
                }
            }

            if (null == asm)
            {
                throw Fx.AssertAndThrow("Assembly should not be null");
            }
            ComPlusTLBImportTrace.Trace(TraceEventType.Verbose, TraceCode.ComIntegrationTLBImportFinished,
                                        SR.TraceCodeComIntegrationTLBImportFinished, iid, typeLibraryID);
            return(asm);
        }