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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:24:13+00:00 2026-06-18T01:24:13+00:00

I have a class with several methods (e.g. Method1, Method2, Method3) and inside each

  • 0

I have a class with several methods (e.g. Method1, Method2, Method3) and inside each method I load an assembly (same one in each method) and invoke a certain method (reflection) like this:

void Method1() // error handling etc. omitted
{
    Assembly asm = Assembly.LoadFrom(path);

    Type type = asm.GetType(classname);
    MethodInfo methodInfo = type.GetMethod("MethodName", ...);
    var o = Activator.CreateInstance(type); 
    var result = methodInfo.Invoke(o, parameters);
}

Is it OK performance-wise to do reflection this way, provided that all these methods load the same assembly? The code then looks like this:

obj.Method1(); // calls Assembly.Load()
obj.Method2(); // calls Assembly.Load()
obj.Method3(); // calls Assembly.Load()

or would it be better to load the assembly (and possibly GetType) only once in a separate method, store the reference to a class Assembly property and inside methods (Method1, Method2, Method3..) use this reference instead of always calling Assembly.Load()? This way, the code would look something like:

obj.LoadMyAssembly(); // calls Assembly.Load() and uses obj.MyAssembly property to store the reference
obj.Method1() // doesn't call Assembly.Load(), uses obj.MyAssembly instead
obj.Method2() // doesn't call Assembly.Load(), uses obj.MyAssembly instead
obj.Method3() // doesn't call Assembly.Load(), uses obj.MyAssembly instead

Does it make any difference? Domains etc. are never changed (or even used) inside the code.

  • 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-18T01:24:15+00:00Added an answer on June 18, 2026 at 1:24 am

    There is no big difference as the assembly will be loaded in the same context. Then, if the assembly is already loaded, it won’t reload it even if you call Assembly.LoadFrom(path);

    However, if you already know that all the method are in the same assembly, it could be better to call Assembly.LoadFrom only once.

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

Sidebar

Related Questions

I have one main class with several inherited members who all overload the same
I have a class that currently has several methods that take integer parameters. These
I have an interface, IMessage and a class which have several methods for creating
I have a class library containing several structures each consisting of several value and
I have a connection class which has several async methods such as SendText, SendImage
Sometimes we have several classes that have some methods with the same signature, but
Say we have a class with several protected and/or public methods. I need to
I have already developed class1.py, class2.py, etc. with functions implemented inside each class. e.g.
I have a class containing several properties (all are strings if it makes any
I have a class that has several member classes as attributes. The constructor of

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.