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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:15:12+00:00 2026-05-15T11:15:12+00:00

I am using an 3rd party assembly that provides services via a static class:

  • 0

I am using an 3rd party assembly that provides services via a static class:

Foo.Bar.StaticLibraryClass.Start();
var x = Foo.Bar.StaticLibraryClass.GetSomeStuff();
Foo.Bar.StaticLibraryClass.Stop();

If the class were not static, I could use an instance of it via a dynamically typed variable:

dynamic lib = new Foo.Bar.NotStaticLibraryClass();
lib.Start();
var x = lib.GetSomeStuff();
lib.Stop();

Unfortunately however, the class IS static. Is there any equivalent I can write that will let me work in the same way?

dynamic lib = /* ??????? */
lib.Start();
var x = lib.GetSomeStuff();
lib.Stop();

(Why do I want to use a dynamic variable to access a perfectly good .NET type? There are actually multiple versions of the library DLL, and I must identify and load the appropriate one at runtime. The different DLLs expose the same type and method names, but they do inherit from any common interface. So if I can find a way to use dynamic typing, it will spare me from writing a lot of fiddly reflection code to use the DLLs’ methods.)

  • 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-15T11:15:12+00:00Added an answer on May 15, 2026 at 11:15 am

    Sorry, C# dynamic does not support this usage directly. In order to call a class method in C#, you have to name the type in your source code directly. And to do that, you have to reference the assembly. dynamic doesn’t change this.

    dynamic does dispatch to class methods when necessary (such as when you have a dynamic argument), but even in those cases the limitation above stands.

    If the target types provided an instance that you could put in a dynamic variable, then you’d be fine. If you provided such an instance you’d be fine. Alternatively, if you have your heart set on dynamic, you could write your own IDynamicMetaObjectProvider that wraps these class methods dynamically given a System.Type. That would be an instructive project if you want to learn about the DLR, at least.

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

Sidebar

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.