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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:03:48+00:00 2026-06-14T16:03:48+00:00

This sounds like such an obvious thing but I am having a lot of

  • 0

This sounds like such an obvious thing but I am having a lot of difficulty. Basically, what I’m doing is generating a method using Reflection.Emit and I then want to call it. So far, I have the method building and such, but I can’t get a reference to the method after it’s built because “The invoked member is not supported before the type is created.”

Here is what I basically do:

AssemblyBuilder assembly;
ModuleBuilder module;
TypeBuilder containerTypeBuilder;
Type containerType;
var name = new AssemblyName();
name.Name = "DynamicWrapper";
var domain = Thread.GetDomain();
assembly = domain.DefineDynamicAssembly(name, AssemblyBuilderAccess.RunAndSave);
module = assembly.DefineDynamicModule(assembly.GetName().Name, false);
containerTypeBuilder = module.DefineType("__DynamicWrapperType",
                              TypeAttributes.Public | TypeAttributes.Class |
                              TypeAttributes.AutoClass |
                              TypeAttributes.AnsiClass | TypeAttributes.BeforeFieldInit |
                              TypeAttributes.AutoLayout, typeof(object));
//build method
var mb = containerTypeBuilder.DefineMethod("generatedmethod" + (unique++),
                              MethodAttributes.Public | MethodAttributes.Static, typeof (int),
                              new Type[] {});
//build method body and all that
.....
var type=module.GetType("__DynamicWrapperType");
var info=type.GetMethod(mb.Name, BindingFlags.Static | BindingFlags.Public); //error here

How do I take my freshly built method and load it up so that I can invoke it?

Also, I’ve tried mb.Invoke, but that yields “The invoked member is not supported in a dynamic module.”

  • 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-14T16:03:49+00:00Added an answer on June 14, 2026 at 4:03 pm

    If you are creating individual method(s), then DynamicMethod is a much better choice (especially since your method is static) – you just useCreateDelegate (specifying the delegate type), cast to that delegate, and invoke. It is also less overhead, and collectible.

    But if you are forced to use MethodBuilder: you must use CreateType on the TypeBuilder, then use reflection on the now real type (returned from CreateType).

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

Sidebar

Related Questions

It sounds like such a easy task but I am finding this very hard
This sounds like such a dumb question but I've spent too long looking for
This sounds like a really simple question, but I am new to PHP. If
This sounds like a problem many others have posted about, but there's a nuance
I know this sounds like a homework assignment, but it isn't. Lately I've been
I know this sounds like a dumb question but I need to ask this.
I apologise if any of this sounds like a broken record but I've trawled
This probably sounds like a terrible idea at first glance, but here is my
This may sounds like a stupid question but can't find anything on google, probably
I found this answer and it sounds like almost exactly what I'm doing. I

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.