public Assembly ResolveRef(object typeLib) { ITypeLib tLib = typeLib as ITypeLib; string tLibname; string outputFolder = ""; string interopFileName; string asmPath; try { tLibname = Marshal.GetTypeLibName(tLib); IntPtr ppTlibAttri = IntPtr.Zero; tLib.GetLibAttr(out ppTlibAttri); System.Runtime.InteropServices.ComTypes.TYPELIBATTR tLibAttri = (System.Runtime.InteropServices.ComTypes.TYPELIBATTR)Marshal.PtrToStructure(ppTlibAttri, typeof(System.Runtime.InteropServices.ComTypes.TYPELIBATTR)); string guid = tLibAttri.guid.ToString(); RegistryKey typeLibsKey = Registry.ClassesRoot.OpenSubKey("TypeLib\\{" + guid + "}"); TypeLibrary typeLibrary = TypeLibrary.Create(typeLibsKey); Converter.TlbImp importer = new Converter.TlbImp(Parent.References); outputFolder = Path.GetDirectoryName(this.Parent.AsmPath); interopFileName = Path.Combine(outputFolder, String.Concat("Interop.", typeLibrary.Name, ".dll")); asmPath = interopFileName; //asm.Save(Path.GetFileName(asmPath)); //Call ResolveRefEventArgs to notify extra assembly imported as depenedencies ResolveRefEventArgs t = new ResolveRefEventArgs("Reference Interop '" + Path.GetFileName(asmPath) + "' created succesfully."); Parent.InvokeResolveRef(t); Parent.References.Add(new ComReferenceProjectItem(ScriptControl.GetProject(), typeLibrary)); return(importer.Import(interopFileName, typeLibrary.Path, typeLibrary.Name, this.Parent)); } catch (Exception Ex) { ResolveRefEventArgs t = new ResolveRefEventArgs(Ex.Message); Parent.InvokeResolveRef(t); return(null); } finally { Marshal.ReleaseComObject(tLib); } }