here is code that replicates it...
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms.VisualStyles;
using System.Reflection;
namespace cecil_bug
{
public class MyTestClass
{
public VisualStyleElement m_TabElement = null; //Tab
control visual element
public void DoSomething()
{
m_TabElement = VisualStyleElement.Tab.TabItem.Normal;
}
}
class Program
{
static void Main(string[] args)
{
Mono.Cecil.AssemblyDefinition ad_s =
Mono.Cecil.AssemblyFactory.GetAssembly(System.Reflection.Assembly.GetExecutingAssembly().Location);
Mono.Cecil.AssemblyDefinition ad =
Mono.Cecil.AssemblyFactory.DefineAssembly("bug_dll",
Mono.Cecil.AssemblyKind.Dll);
ad.MainModule.Inject(ad_s.MainModule.Types["cecil_bug.MyTestClass"]);
byte[] ba;
Mono.Cecil.AssemblyFactory.SaveAssembly(ad, out ba);
Assembly a = Assembly.Load(ba);
Type t = a.GetType("cecil_bug.MyTestClass");
ConstructorInfo ci = t.GetConstructors(BindingFlags.Public
| BindingFlags.Instance)[0];
object o = ci.Invoke(BindingFlags.CreateInstance, null,
null, System.Globalization.CultureInfo.CurrentCulture);
t.GetMethod("DoSomething").Invoke(o, null);
}
}
}
this code results in new assembly that contains single class, problem
is that nested type that have been used in it is corrupted... injected
type reflected method looks like this:
public void DoSomething()
{
base.m_TabElement = TabItem.get_Normal();
}
see the difference?
and there will be type load exception for TabItem as it cannot be
found!!
--~--~---------~--~----~------------~-------~--~----~
--
mono-cecil
-~----------~----~----~----~------~----~------~--~---