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

  • Home
  • SEARCH
  • 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 8956291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:45:26+00:00 2026-06-15T14:45:26+00:00

I have an application with a plugin architecture using MEF. For every exported part

  • 0

I have an application with a plugin architecture using MEF. For every exported part there is an attribute with the part’s name, and I want to have the names translated, because I use these strings to display the available parts in ListBoxes (or the like).

So, I tried to set the ‘Name = Strings.SomeText” in the [Export] annotation, but I get the following error:

“An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type”

Is there a solution to this? I find the use of the Metadata very useful (I do lazy loading) and I would not want to redesign everything just to get a few texts translated.

Any ideas? 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-06-15T14:45:28+00:00Added an answer on June 15, 2026 at 2:45 pm

    Unfortunately you can’t directly provide the translated text to the attributes because an attribute can only contain data that is known at compile time. So you will need to provide some compile time constant value that you can later use to look up the translated test.

    One solution would be to pass the resource name to the attribute. Then when you want to display the translated text you grab the resource name, look up the text in the resources and display the result.

    For instance your attribute could look something like:

    [Export(Name = "SomeText")]
    public class MyExport
    {
    }
    

    Then when you want to display the string you load the resources from the assembly that defines the export and you extract the actual text from the loaded resources. For instance like this (as borrowed from another answer):

    var assembly = typeof(MyExport).Assembly;
    
    // Resource file.. namespace.ClassName
    var rm = new ResourceManager("MyAssembly.Strings", assembly);
    
    // exportName contains the text provided to the Name property 
    // of the Export attribute
    var text = rm.GetString(exportName);
    

    The one obvious drawback about this solution is that you lose the type-safety that you get from using the Strings.SomeText property.

    ——— EDIT ———

    In order to make it a little easier to get the translated text you could create a derivative of the ExportAttribute which takes enough information to extract the translated text. For example the custom ExportAttribute could look like this

    public sealed class NamedExportAttribute : ExportAttribute
    {
        public NamedExportAttribute()
            : base()
        { 
        }
    
        public string ResourceName
        {
            get;
            set;
        }
    
        public Type ResourceType
        {
            get;
            set;
        }
    
        public string ResourceText()
        {
            var rm = new ResourceManager(ResourceType);
            return rm.GetString(ResourceName);
        }
    }
    

    Using this attribute you can apply it like this

    [NamedExport(
        ResourceName = "SomeText", 
        ResourceType = typeof(MyNamespace.Properties.Resources))]
    public sealed class MyClass
    { 
    }
    

    Finally when you need to get the translated text you can do this

    var attribute = typeof(MyClass).GetCustomAttribute<NamedExportAttribute>();
    var text = attribute.ResourceText();
    

    Another option is to use the DisplayAttribute

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

Sidebar

Related Questions

I am using the Google Application Engine plugin for Eclipse 3.4, and I have
I am writing a small plugin architecture and I have decided to use MEF
I have to implement a plugin architecture for my application. I have the main
I have a Java web application that uses a plugin architecture. I would like
I am converting a home-grown plugin architecture to .NET 4.0's MEF. The MEF-based application
I am using this article of architecture http://blog.extjs.eu/know-how/writing-a-big-application-in-ext/ I have this one function where
I have an application and I am using Twipsy plugin from Twitter Bootstrap to
I have an application that uses the Paperclip plugin for image upload. Now that
I have this Grails application wherein I installed JQuery, JQuery-UI, and JQGrid plugin. I
I have a plugin that is loaded by this application.. This plugin calls some

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.