You receive a "C2691" error code when you use a jagged array in Managed Extensions for C++ (814058)



The information in this article applies to:

  • Microsoft Visual C++ .NET (2002)
  • Microsoft Visual C++ .NET (2003)

SYMPTOMS

If you declare a jagged array, or use a function that returns a jagged array, you receive the following compilation error while compiling the code:
mytest.cpp(6) : error C2691: '<data type used> __gc[]' : invalid type for __gc array element

where <data type used> is the data type of the jagged array.

CAUSE

A jagged array is not supported in the products that are listed in "Applies To" section of this article.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce the Behavior

Declaring a Jagged Array

  1. Click Start, point to All Programs, point to Microsoft Visual Studio .NET, point to Visual Studio .NET Tools, and then click Visual Studio .NET Command Prompt.
  2. Paste the following code in Notepad:
    #using <mscorlib.dll>
    using namespace System;
    void main()
    {
        Int32 myJaggedArray[][] = new Int32 [50][];
        return;
    }
  3. Save the file as MyTest.cpp.
  4. At the command prompt, type the following command to compile the code:
    cl /clr MyTest.cpp
  5. At the command prompt, you receive the compilation error that is described in the "Symptoms" section of this article.

Using a Jagged Array

  1. Click Start, point to All Programs, point to Microsoft Visual Studio .NET, point to Visual Studio .NET Tools, and then click Visual Studio .NET Command Prompt.
  2. Paste the following code in Notepad:
    #using <mscorlib.dll>
    #using <System.Drawing.dll>
    using namespace System::Drawing::Imaging;
    void main()
    {
        ImageCodecInfo::GetImageEncoders();
        return;
    }
    The GetImageEncoders method returns a jagged array.
  3. Save the file as MyTest.cpp.
  4. At the command prompt, type the following command to compile the code:

    cl /clr MyTest.cpp

  5. At the command prompt, you receive the compilation error that described in the "Symptoms" section of this article.

Note The following is the list of the fields, properties, and methods that return a jagged array in the .NET Framework:
Assembly: Microsoft.JScript.dll
	Field Type: Microsoft.JScript.TypeReflector::System.Reflection.MemberInfo[][] memberInfos

Assembly: mscorlib.dll
	Field Type: System.Reflection.Emit.AssemblyBuilderData::Byte[][] m_CABytes
	Field Type: System.Reflection.Emit.LocalSymInfo::Byte[][] m_ubSignature

Assembly: D:\WINDOWS\Microsoft.NET\Framework\v1.0.4207\System.Data.dll
	Field Type: System.Data.SqlClient.SqlDataReader::System.String[][] _tableNamesShilohSP1
	Method Return Type: System.Data.SqlClient.SqlDataReader::System.String[][] get_TableNamesShilohSP1()
	Method Parameter: System.Data.SqlClient.SqlDataReader::Void set_TableNamesShilohSP1(System.String[][])
	Property: System.Data.SqlClient.SqlDataReader::System.String[][] TableNamesShilohSP1
	Method Return Type: System.Data.SqlClient.TdsParser::System.String[][] ProcessTableNameShilohSP1(Int32)

Assembly: System.dll
	Field Type: System.Text.RegularExpressions.RegexBoyerMoore::Int32[][] _negativeUnicode
	Field Type: System.Text.RegularExpressions.Match::Int32[][] _matches
	Field Type: System.Text.RegularExpressions.MatchSparse::Int32[][] _matches

Assembly: System.Drawing.dll
	Constructor Parameter: System.Drawing.Imaging.ColorMatrix::Void .ctor(Single[][])
	Method Parameter: System.Drawing.Imaging.ColorMatrix::Void SetMatrix(Single[][])
	Method Return Type: System.Drawing.Imaging.ColorMatrix::Single[][] GetMatrix()
	Field Type: System.Drawing.Imaging.ImageCodecInfo::Byte[][] signaturePatterns
	Field Type: System.Drawing.Imaging.ImageCodecInfo::Byte[][] signatureMasks
	Method Return Type: System.Drawing.Imaging.ImageCodecInfo::Byte[][] get_SignaturePatterns()
	Method Parameter: System.Drawing.Imaging.ImageCodecInfo::Void set_SignaturePatterns(Byte[][])
	Method Return Type: System.Drawing.Imaging.ImageCodecInfo::Byte[][] get_SignatureMasks()
	Method Parameter: System.Drawing.Imaging.ImageCodecInfo::Void set_SignatureMasks(Byte[][])
	Property: System.Drawing.Imaging.ImageCodecInfo::Byte[][] SignaturePatterns
	Property: System.Drawing.Imaging.ImageCodecInfo::Byte[][] SignatureMasks

Assembly: System.Runtime.Remoting.dll
	Field Type: System.IO.ByteBufferPool::Byte[][] _bufferPool

Assembly: System.Web.dll
	Method Return Type: System.Web.HttpWorkerRequest::System.String[][] GetUnknownRequestHeaders()
	Field Type: System.Web.Hosting.ISAPIWorkerRequest::System.String[][] _unknownRequestHeaders
	Method Return Type: System.Web.Hosting.ISAPIWorkerRequest::System.String[][] GetUnknownRequestHeaders()
	Method Return Type: System.Web.Hosting.ISAPIWorkerRequestInProc::System.String[][] GetUnknownRequestHeaders()
	Method Return Type: System.Web.Hosting.ISAPIWorkerRequestInProcForIIS6::System.String[][] GetUnknownRequestHeaders()
	Method Return Type: System.Web.Hosting.ISAPIWorkerRequestOutOfProc::System.String[][] GetUnknownRequestHeaders()
	Method Return Type: System.Web.Hosting.SimpleWorkerRequest::System.String[][] GetUnknownRequestHeaders()
	Method Return Type: System.Web.SessionState.StateHttpWorkerRequest::System.String[][] GetUnknownRequestHeaders()
	Field Type: System.Web.Util.WildcardPath::System.Text.RegularExpressions.Regex[][] _dirs
	Method Return Type: System.Web.Util.WildcardPath::System.Text.RegularExpressions.Regex[][] DirsFromWildcard(System.String)
	Method Return Type: System.Web.Util.WildcardUrl::System.Text.RegularExpressions.Regex[][] DirsFromWildcard(System.String)

Assembly: vjslib.dll
	Field Type: com.ms.vjsharp.text.FormatInfo::System.String[][] __zoneStrings
	Method Return Type: com.ms.vjsharp.text.FormatInfo::System.String[][] getZoneStrings()
	Method Return Type: java.util.ListResourceBundle::System.Object[][] getContents()
	Method Return Type: java.awt.GridBagLayout::Double[][] getLayoutWeights()
	Method Return Type: java.awt.GridBagLayout::Int32[][] getLayoutDimensions()
	Field Type: com.ms.vjsharp.security.provider.DSAKeyPairGenerator::SByte[][] m_rgbParams
	Field Type: java.text.DateFormatSymbols::System.String[][] __zoneStrings
	Method Parameter: java.text.DateFormatSymbols::Void setZoneStrings(System.String[][])
	Method Return Type: java.text.DateFormatSymbols::System.String[][] getZoneStrings()
	Method Return Type: java.applet.Applet::System.String[][] getParameterInfo()

Assembly: vjswfchtml.dll
	Field Type: com.ms.wfc.html.DhKeyValuePairs::Char[][] m_cvalues
	Field Type: com.ms.wfc.html.DhNameValuePairs::Char[][] strings

REFERENCES

For more information about jagged arrays, visit the following Microsoft Developer Network (MSDN) Web site: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfjaggedarrays.asp

Modification Type:MinorLast Reviewed:1/13/2006
Keywords:kbCollectionClass kbprb KB814058 kbAudDeveloper kbAudITPRO