Importing a COM type library and adding a few enums<p>Hello, I'm about to create an assembly which contains a converted COM type library, but I'd like to add a few enums on the way. Can I do that? This is the way I've tried so far:</p><font size=2> <p></font><font face="Courier New, Courier, Monospace" color="#008080" size=2>Object</font><font size=2><font face="Courier New, Courier, Monospace"> typeLib;</font></p> <p><font face="Courier New, Courier, Monospace">LoadTypeLibEx(dllPath, </font></font><font face="Courier New, Courier, Monospace"><font color="#008080" size=2>RegKind</font><font size=2>.RegKind_None, </font><font color="#0000ff" size=2>out</font></font><font size=2><font face="Courier New, Courier, Monospace"> typeLib);</font></p></font><font size=2> <p></font><font face="Courier New, Courier, Monospace"><font color="#008080" size=2>FileStream</font><font size=2> fs = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>FileStream</font><font size=2>(</font><font color="#800000" size=2>@&quot;key.snk&quot;</font><font size=2>, </font><font color="#008080" size=2>FileMode</font><font size=2>.Open, </font><font color="#008080" size=2>FileAccess</font></font><font size=2><font face="Courier New, Courier, Monospace">.Read);</font></p> <p></font><font face="Courier New, Courier, Monospace"><font color="#008080" size=2>StrongNameKeyPair</font><font size=2> keyPair = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>StrongNameKeyPair</font></font><font size=2><font face="Courier New, Courier, Monospace">(fs);</font></p> <p></font><font face="Courier New, Courier, Monospace"><font color="#008080" size=2>TypeLibConverter</font><font size=2> converter = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>TypeLibConverter</font></font><font size=2><font face="Courier New, Courier, Monospace">();</font></p> <p></font><font face="Courier New, Courier, Monospace"><font color="#008080" size=2>ConversionEventHandler</font><font size=2> eventHandler = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>ConversionEventHandler</font></font><font size=2><font face="Courier New, Courier, Monospace">();</font></p> <p></font><font face="Courier New, Courier, Monospace" color="#008080" size=2>AssemblyBuilder</font><font size=2><font face="Courier New, Courier, Monospace"> assembly = converter.ConvertTypeLibToAssembly(typeLib, <font color="#800000">&quot;NewAssembly.dll&quot;</font>, </font></font><font face="Courier New, Courier, Monospace"><font color="#008080" size=2>TypeLibImporterFlags</font><font size=2>.PrimaryInteropAssembly, eventHandler, </font><font color="#0000ff" size=2>null</font><font size=2>, keyPair, <font color="#800000">&quot;NewNamespace&quot;</font>, </font><font color="#0000ff" size=2>null</font></font><font size=2><font face="Courier New, Courier, Monospace">);</font></p> <p></font><font face="Courier New, Courier, Monospace"><font color="#008080" size=2>ModuleBuilder</font><font size=2> module = assembly.DefineDynamicModule(</font><font color="#800000" size=2>&quot;TempModule&quot;</font><font size=2>, </font><font color="#800000" size=2>&quot;NewAssembly.dll&quot;</font><font size=2>, </font><font color="#0000ff" size=2>true</font></font><font size=2><font face="Courier New, Courier, Monospace">);</font></font></p> <p><font size=2><font size=3>The problem is that I get an ArgumentException &quot;Duplicate file names.&quot; when running DefineDynamicModule.</font></font></p> <p><font size=2><font size=3>How can I add enums to my converted COM type library?</font></font></p> <p><font size=2><font size=3>/Chris</font></font></p> <p><font size=2><font size=3></font> </p></font>© 2009 Microsoft Corporation. All rights reserved.Thu, 19 Jun 2008 00:15:52 Zb0d039c3-075b-42b6-9ba8-6e0a1126c350http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/b0d039c3-075b-42b6-9ba8-6e0a1126c350#b0d039c3-075b-42b6-9ba8-6e0a1126c350http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/b0d039c3-075b-42b6-9ba8-6e0a1126c350#b0d039c3-075b-42b6-9ba8-6e0a1126c350compilatorhttp://social.msdn.microsoft.com/Profile/en-US/?user=compilatorImporting a COM type library and adding a few enums<p>Hello, I'm about to create an assembly which contains a converted COM type library, but I'd like to add a few enums on the way. Can I do that? This is the way I've tried so far:</p><font size=2> <p></font><font face="Courier New, Courier, Monospace" color="#008080" size=2>Object</font><font size=2><font face="Courier New, Courier, Monospace"> typeLib;</font></p> <p><font face="Courier New, Courier, Monospace">LoadTypeLibEx(dllPath, </font></font><font face="Courier New, Courier, Monospace"><font color="#008080" size=2>RegKind</font><font size=2>.RegKind_None, </font><font color="#0000ff" size=2>out</font></font><font size=2><font face="Courier New, Courier, Monospace"> typeLib);</font></p></font><font size=2> <p></font><font face="Courier New, Courier, Monospace"><font color="#008080" size=2>FileStream</font><font size=2> fs = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>FileStream</font><font size=2>(</font><font color="#800000" size=2>@&quot;key.snk&quot;</font><font size=2>, </font><font color="#008080" size=2>FileMode</font><font size=2>.Open, </font><font color="#008080" size=2>FileAccess</font></font><font size=2><font face="Courier New, Courier, Monospace">.Read);</font></p> <p></font><font face="Courier New, Courier, Monospace"><font color="#008080" size=2>StrongNameKeyPair</font><font size=2> keyPair = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>StrongNameKeyPair</font></font><font size=2><font face="Courier New, Courier, Monospace">(fs);</font></p> <p></font><font face="Courier New, Courier, Monospace"><font color="#008080" size=2>TypeLibConverter</font><font size=2> converter = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>TypeLibConverter</font></font><font size=2><font face="Courier New, Courier, Monospace">();</font></p> <p></font><font face="Courier New, Courier, Monospace"><font color="#008080" size=2>ConversionEventHandler</font><font size=2> eventHandler = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>ConversionEventHandler</font></font><font size=2><font face="Courier New, Courier, Monospace">();</font></p> <p></font><font face="Courier New, Courier, Monospace" color="#008080" size=2>AssemblyBuilder</font><font size=2><font face="Courier New, Courier, Monospace"> assembly = converter.ConvertTypeLibToAssembly(typeLib, <font color="#800000">&quot;NewAssembly.dll&quot;</font>, </font></font><font face="Courier New, Courier, Monospace"><font color="#008080" size=2>TypeLibImporterFlags</font><font size=2>.PrimaryInteropAssembly, eventHandler, </font><font color="#0000ff" size=2>null</font><font size=2>, keyPair, <font color="#800000">&quot;NewNamespace&quot;</font>, </font><font color="#0000ff" size=2>null</font></font><font size=2><font face="Courier New, Courier, Monospace">);</font></p> <p></font><font face="Courier New, Courier, Monospace"><font color="#008080" size=2>ModuleBuilder</font><font size=2> module = assembly.DefineDynamicModule(</font><font color="#800000" size=2>&quot;TempModule&quot;</font><font size=2>, </font><font color="#800000" size=2>&quot;NewAssembly.dll&quot;</font><font size=2>, </font><font color="#0000ff" size=2>true</font></font><font size=2><font face="Courier New, Courier, Monospace">);</font></font></p> <p><font size=2><font size=3>The problem is that I get an ArgumentException &quot;Duplicate file names.&quot; when running DefineDynamicModule.</font></font></p> <p><font size=2><font size=3>How can I add enums to my converted COM type library?</font></font></p> <p><font size=2><font size=3>/Chris</font></font></p> <p><font size=2><font size=3></font> </p></font>Thu, 15 Jun 2006 08:23:19 Z2006-06-16T02:29:35Zhttp://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/b0d039c3-075b-42b6-9ba8-6e0a1126c350#3159e0c7-1e69-404b-a558-6afdc1ee948dhttp://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/b0d039c3-075b-42b6-9ba8-6e0a1126c350#3159e0c7-1e69-404b-a558-6afdc1ee948dMattias Sjögrenhttp://social.msdn.microsoft.com/Profile/en-US/?user=Mattias%20Sj%u00f6grenImporting a COM type library and adding a few enums<p>Have you tried using GetModule instead of DefineDynamicModule?</p> <p> </p>Thu, 15 Jun 2006 09:16:45 Z2006-06-16T02:29:35Zhttp://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/b0d039c3-075b-42b6-9ba8-6e0a1126c350#24d4010a-5e05-479f-818c-74118edada16http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/b0d039c3-075b-42b6-9ba8-6e0a1126c350#24d4010a-5e05-479f-818c-74118edada16compilatorhttp://social.msdn.microsoft.com/Profile/en-US/?user=compilatorImporting a COM type library and adding a few enums<p>GetModule returns a Module instead of a ModuleBuilder, so its not really what I'm looking for. Also, the docs for AssemblyBuilder says:</p> <p>&quot;Some methods on the base class <a title="ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.en/cpref10/html/T_System_Reflection_Assembly.htm"><u><font color="#800080">Assembly</font></u></a> such as <b>GetModules</b> and <b>GetLoadedModules</b> will not work correctly when called <b>AssemblyBuilder</b> objects. You can load the defined dynamic assembly and call the methods on the loaded assembly. For example, to ensure that resource modules are included in the returned module list, call <b>GetModules</b> on the loaded <b>Assembly</b> object.&quot;</p> <p>I'm not quite sure what about GetModules thats not working, but I'm not using it :)</p> <p>/Chris</p> <p> </p>Thu, 15 Jun 2006 11:42:37 Z2006-06-15T11:42:37Zhttp://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/b0d039c3-075b-42b6-9ba8-6e0a1126c350#60db7ff7-98fa-4a6a-b032-390cf12c6b80http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/b0d039c3-075b-42b6-9ba8-6e0a1126c350#60db7ff7-98fa-4a6a-b032-390cf12c6b80Mattias Sjögrenhttp://social.msdn.microsoft.com/Profile/en-US/?user=Mattias%20Sj%u00f6grenImporting a COM type library and adding a few enums<div class=quote><table width="85%"><tr><td class=txt4> <strong>compilator wrote:</strong></td></tr><tr><td class=quoteTable><table width="100%"><tr><td width="100%" valign=top class=txt4> <p>GetModule returns a Module instead of a ModuleBuilder, so its not really what I'm looking for.</p> <p></td></tr></table></td></tr></table></div></p> <p>Right, but you may be able to cast it to a ModuleBuilder.</p>Thu, 15 Jun 2006 13:04:03 Z2006-06-15T13:04:03Zhttp://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/b0d039c3-075b-42b6-9ba8-6e0a1126c350#cb59ff4c-bff3-4242-93be-ad4eb88d2d9bhttp://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/b0d039c3-075b-42b6-9ba8-6e0a1126c350#cb59ff4c-bff3-4242-93be-ad4eb88d2d9bcompilatorhttp://social.msdn.microsoft.com/Profile/en-US/?user=compilatorImporting a COM type library and adding a few enumsIt worked. Scary.Thu, 15 Jun 2006 14:10:35 Z2006-06-15T14:10:35Z