<p>I have a method in .NET (C#) which returns <code>string[][]</code>. When using RegAsm or TlbExp (from the .NET 2.0 SDK) to create a COM type library for the containing assembly, I get the following warning:</p>

<blockquote>
  <p>WARNING: There is no marshaling support for nested arrays.</p>
</blockquote>

<p>This warning results in the method in question not being exported into the generated type library. I've been told there's ways around this using Variant as the COM return type, and then casting/etc on the COM client side. For this particular assembly, the target client audience is VB6. <b>But how do you actually do this on the .NET side?</b></p>

<p><i>Note</i>: I have an existing legacy DLL (with its exported type library) where the return type is Variant, but this DLL (and the .tlb) is generated using pre-.NET legacy tools, so I can't use them. </p>

<p>Would it help at all if the assembly was written in VB.NET instead?</p>

[{'answer_id': 71395, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': "<p>The equivalent of variant in C# is System.Object.  So you might want to try to return the result cast to object and pick it back up on the other side as a variant.</p>\n\n<p>VB doesn't have any facilities that C# lacks, so I doubt it would be better or easier if the .NET side was written in VB.</p>\n"}, {'answer_id': 74711, 'author': 'Euro Micelli', 'author_id': 2230, 'author_profile': 'https://Stackoverflow.com/users/2230', 'pm_score': 3, 'selected': True, 'text': '<p>Even if you were to return an Object (which maps to a Variant in COM Interop), that doesn\'t solve your problem. VB will be able to "hold" onto it and "pass it around", but it won\'t be able to do anything with it.</p>\n\n<p>Technically, there is no exact equivalent in VB for a string[][]. However, if your array is not "jagged" (that is, all the sub-arrays are the same length), you should be able to use a two-dimensional array as your return type. COM Interop should be able to translate that.</p>\n\n<pre><code>string [,] myReturnValue = new string[rowCount,colCount];\n</code></pre>\n\n<p>Whether your method formally returns an Object (which will look like a Variant to VB), or a string[,] (which will look like an Array of Strings in VB), is somewhat immaterial. The String array is a nicer return, but not a requirement.</p>\n\n<p>If you array <em>is</em> jagged, then you are going to have to come up with a different method. For example, you could choose to make your return 2D array as big as the biggest of the sub-arrays, and then pass the length information in a separate [out] int[] parameter, so that VB can know which elements are used.</p>\n'}]
['https://Stackoverflow.com/questions/70501', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/7724/']