Compiler Error C3821
TOC
Collapse the table of content
Expand the table of content
The document is archived and information here might be outdated

Compiler Error C3821

'function': managed type or function cannot be used in an unmanaged function

Functions with inline assembly or setjmp cannot contain value types or managed classes. To fix this error, remove the inline assembly and setjmp or remove the managed objects.

C3821 can also occur if you try to use automatic storage in a vararg function. For more information, see ... (Variable Argument Lists) and C++ Stack Semantics for Reference Types.

The following sample generates C3821.

// C3821a.cpp
// compile with: /clr /c
public ref struct R {};
void test1(...) {
   R r;   // C3821
}

The following sample generates C3821.

// C3821b.cpp
// compile with: /clr
// processor: /x86
ref class A {
   public:
   int i;
};

int main() {
   // cannot use managed classes in this function
   A ^a;   

   __asm {
      nop
   }
} // C3821

The following sample generates C3821.

// C3821c.cpp
// compile with: /clr:oldSyntax
// processor: /x86
__gc  class A {
   public:
   int i;
};

int main() {
   // cannot use managed classes in this function
   A *a;   

   __asm {
      nop
   }
} // C3821
Show:
© 2016 Microsoft