Compiler Error C3391

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at Compiler Error C3391.

type_arg' : invalid type argument for generic parameter 'param' of generic 'generic_type', must be a non-nullable value type

A generic type was instantiated incorrectly. Check the type definition. For more information, see Nullable and Generics.

The following sample, using C#, creates a component that contains a generic type, with certain constraints that are not supported when authoring generic types in Visual C++ 2005. For more information, see .Constraints on Type Parameters.

// C3391.cs  
// compile with: /target:library  
// a C# program  
public class GR<N>  
where N : struct {}  

The following sample generates C3391.

// C3391_b.cpp  
// compile with: /clr  
#using <C3391.dll>  
using namespace System;  
value class VClass {};  
  
int main() {  
   GR< Nullable<VClass> >^ a =   
      gcnew GR< Nullable<VClass> >();   // C3391 can't be Nullable  
   GR<VClass>^ aa = gcnew GR<VClass>();   // OK  
}  

Show: