Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

Compiler Error C3104

illegal attribute argument

You specified an invalid argument to an attribute.

See Attribute Parameter Types for more information.

This error can be generated as a result of compiler conformance work that was done for Visual C++ 2005: when passing managed arrays to custom attributes, the type of the array is no longer deduced from the aggregate initialization list. The compiler now requires you to specify the type of the array as well as the initializer list. See Breaking Changes in the Visual C++ 2005 Compiler for more information.

The following sample generates C3104.

// C3104a.cpp
// compile with: /clr /c
using namespace System;

public ref struct ABC : public Attribute {
   array<double> ^ param;

[ABC( {1,2,3}, param = {2.71, 3.14})]   // C3104
// try the following line instead
// [ABC( gcnew array<int> {1,2,3}, param = gcnew array<double>{2.71, 3.14})] 
ref struct AStruct{};

The following sample generates C3104.

// C3104b.cpp
// compile with: /clr /c
// C3104 expected
using namespace System;

int func() {
   return 0; 

ref class A {
   A(int) {}

// Delete the following 2 lines to resolve.
ref class B {};

// OK
ref class B {};

The following sample generates C3104.

// C3104c.cpp
// compile with: /clr:oldSyntax /c
using namespace System;

[ attribute(Class) ]
public __gc class AnotherAttr {
   AnotherAttr(Object* arr __gc[]) : var0(arr) {}
   Object* var1 __gc[];
   Object* var0 __gc[];

[ AnotherAttr( { __box(3.14159), S"pi" }, var1 = { S"a", S"b" } ) ]   // C3104
public __gc class Class1 {};

// OK
[ AnotherAttr( new Object * __gc[] {__box(3.14159), S"pi" }, var1 = new Object * __gc[] { S"a", S"b" } ) ]
public __gc class Class2 {};

Community Additions

© 2015 Microsoft