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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:21:07+00:00 2026-05-28T07:21:07+00:00

This one is driving me crazy. AssemblyDefinition asm1 = AssemblyDefinition.ReadAssembly(example); AssemblyDefinition asm2 = AssemblyDefinition.ReadAssembly(example2);

  • 0

This one is driving me crazy.

AssemblyDefinition asm1 = AssemblyDefinition.ReadAssembly(example);
AssemblyDefinition asm2 = AssemblyDefinition.ReadAssembly(example2);
asm2.MainModule.Types.Add(asm1.MainModule.Types[0]);

Whenever I try to execute the above code I get this error ‘Type already attached’
I decided to look this error at MonoCecil source and I found it throws this error because the Type’s MainMoudle isn’t asm2 MainModules. So I decided to Copy that Type to a new one.

TypeDefinition type2 = new TypeDefinition("", "type2",  Mono.Cecil.TypeAttributes.Class);
foreach (MethodDefinition md in asm2.Methods )
{
        type2.Methods.Add(md);
}

And then add this type to my assembly normally but this throws another error, ‘Specified method is not supported.’.
Any thoughts why I am getting this error?

Edit: Just to add, the type I’m trying to add contains some methods which uses pointers. Might this be the problem? As far as I know mono supports that but not mixed mode.

  • 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-28T07:21:07+00:00Added an answer on May 28, 2026 at 7:21 am

    I’m afraid there’s no built in, easy way to do this.

    When you read an assembly with Cecil, every piece of metadata is glued together by the Module the metadata is defined in. You can’t simply take a method from a module, and add it into another one.

    To achieve this, you need to clone the MethodDefinition into a MethodDefinition tied to the other module. Again, there’s nothing built-in yet for this.

    I suggest you have a look at IL-Repack, which is an open-source ILMerge clone. It does exactly that, it takes types from different modules, and clone them into another one.

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

Sidebar

Related Questions

This one is driving me crazy. Here's the XAML: <UserControl x:Class=SilverlightApplication1.Page xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml> <Grid
This is driving me crazy. I have this one php file on a test
I've been driving myself crazy over the past few days over this one. We've
This is a really simple one but it's driving me crazy. I want to
This one is driving me crazy:-) Lets say I have some test xaml code:
This one has been driving me crazy today. Since upgrading to Grails 1.2 and
Does this happen to any one of you? It is driving me crazy: On
This one's driving me crazy... I have a loop which adds an event listener
I know the general guidelines to double-postbacks, but this one is driving me nuts
No luck at MSDN with this one, which is driving me nuts. I us

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.