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 939971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:52:41+00:00 2026-05-15T21:52:41+00:00

I have a app that requires a dll to be loaded at runtime and

  • 0

I have a app that requires a dll to be loaded at runtime and I want to create some Custom Attributes in the dynamically loaded DLL so when it is loaded I can check to make sure that certain attributes have certain values before trying to use it.

I create an attribute like this

using System;
[AttributeUsage(AttributeTargets.Class)]
public class ValidReleaseToApp : Attribute
{
    private string ReleaseToApplication;

    public ValidReleaseToApp(string ReleaseToApp)
    {
        this.ReleaseToApplication = ReleaseToApp;
    }
} 

In the dynamically loaded DLL I set the attribute like this

[ValidReleaseToApp("TheAppName")]
public class ClassName : IInterfaceName
etc... etc....

But when I try and read the Attribute Value I only get the Attribute Name “ValidReleaseToApp” How do I retrieve the Value “TheAppName”?

Assembly a = Assembly.LoadFrom(PathToDLL);
Type type = a.GetType("Namespace.ClassName", true);
System.Reflection.MemberInfo info = type;
var attributes = info.GetCustomAttributes(true);
MessageBox.Show(attributes[0].ToString());

Update:

Since I am Dynamically loading the dll at runtime the definition of the Attribute is not avail. to the Main App. So when I try to do the following as suggested

string value = ((ValidReleaseToApp)attributes[0]).ReleaseToApplication;
MessageBox.Show(value);

I get this error

The type or namespace name 'ValidReleaseToApp' could not be found

Update2:

OK so the problem was that I defined the Attribute within the project of the dynamically loaded DLL. Once I moved the Attribute definitions to it’s own project and Added a reference to that project to both the Main Project and that of the Dynamically loaded dll The suggested code worked.

  • 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-15T21:52:42+00:00Added an answer on May 15, 2026 at 9:52 pm

    This should work, I don’t have an example in front of me right now, but it looks right. You’re basically skipping the steps of exposing the property you want access to, and casting to the attribute type to retrieve that property.

    using System;
    [AttributeUsage(AttributeTargets.Class)]
    public class ValidReleaseToApp : Attribute
    {
        private string _releaseToApplication;
        public string ReleaseToApplication { get { return _releaseToApplication; } }
    
        public ValidReleaseToApp(string ReleaseToApp)
        {
            this._releaseToApplication = ReleaseToApp;
        }
    } 
    
    
    Assembly a = Assembly.LoadFrom(PathToDLL);
    Type type = a.GetType("Namespace.ClassName", true);
    System.Reflection.MemberInfo info = type;
    var attributes = info.GetCustomAttributes(true);
    if(attributes[0] is ValidReleaseToApp){
       string value = ((ValidReleaseToApp)attributes[0]).ReleaseToApplication ;
       MessageBox.Show(value);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that references an outside DLL which in production will be
I have an app with a manifest that requires running as administrator, but part
I have written a web app that requires IE version 8 (or higher presumably).
I have an App I have updated with some .Net4 assemblies, including the custom
I have an app that requires push notifications sent to user when a post
I have an app that needs to open a new window (in the same
I have an app that executes commands on a Linux server via SSH just
I have a app that I'm deploying to a development server using Capistrano. I'd
I have an app that is failing on the install. The vendor says I
I have an App that will send authenticated emails using System.Net.Mail and System.Net.NetworkCredential my

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.