Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7170997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:19:26+00:00 2026-05-28T15:19:26+00:00

I had this solution working happily and i added this attribute: [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct,

  • 0

I had this solution working happily and i added this attribute:

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false, Inherited = true)]
public class metadata : Attribute
{
    string mid;
    string mdescription;
    Dictionary<string, string> mdata;
    public string id
    {
        get
        {
            return mid;
        }
    }
    public string description
    {
        get
        {
            return mdescription;
        }
    }
    public Dictionary<string, string> data
    {
        get
        {
            return mdata;
        }
    }
    public metadata(string thisid, string thisdescription, params KeyValuePair<string, string>[] thisdataarray)
    {
        mid = thisid;
        mdescription = thisdescription;
        mdata = new Dictionary<string, string>();
        if (thisdataarray != null)
        {
            foreach (KeyValuePair<string, string> thisvaluepair in thisdataarray)
            {
                mdata.Add(thisvaluepair.Key, thisvaluepair.Value);
            }
        }
    }
}

I added a few declarations of this attribute, all [metadata(null, null)] with no errors. Somehow, when I compile, for each [metadata(null, null)] an “error CS0182: An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type” occurs, however with no line or column or file, only the project. What went wrong? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T15:19:27+00:00Added an answer on May 28, 2026 at 3:19 pm

    The problem is that KeyValuePair is not supported as attribute parameter type.
    According to the C# Language specification:

    The types of positional and named parameters for an attribute class are limited to the attribute parameter types, which are:

    • One of the following types: bool, byte, char, double, float, int,
      long, sbyte, short, string, uint, ulong, ushort.
    • The type object.
    • The type System.Type.
    • An enum type, provided it has public accessibility and the types in
      which it is nested (if any) also have public accessibility.
    • Single-dimensional arrays of the above types.

    As a workaround you can pass an array of strings where the odd members are keys and even members are values. Then inside the attribute constructor you can create your Dictionary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Has anyone else had this issue and found a working solution? I've enabled the
I've had this problem many times before, and I've never had a solution I
I had a working solution using ASP.NET MVC Preview 3 (was upgraded from a
Okay so here's the lowdown... been working on this solution for the past week
I haven't seen working solution for Drupal 7 to do this. I have an
I had this working before : echo ini_get(memory_limit).\n; ini_set(memory_limit,256M); echo ini_get(memory_limit).\n; That would input
I've been working on this Solution for a while now, but suddenly I'm getting
this was working till about an hour ago - has anyone had this happen
I had this question earlier and it was concluded it was a bug in
I had this answer on another post I asked: I believe the VS designer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.