This documentation is archived and is not being maintained.

Compiler Error C2717

Error Message

'__nogc new' cannot be used to create a managed type object

__nogc new can only be used to create instances of unmanaged classes and value types. For more information, see __nogc.

C2717 is only reachable using /clr:oldSyntax.

The following sample generates C2717:

// C2717.cpp
// compile with: /clr:oldSyntax
#using <mscorlib.dll>
using namespace System;

__gc class G {};

int main() {
   G* pG = __nogc new G;   // C2717
   G* pG2 = new G;   // OK

   G* arr __gc[] = __nogc new G*[10];   // C2717
   G* arr2 __gc[] = new G*[10];   // OK
}
Show: