MySql.Data.dll is a signed dll and changing it with mono would result in an 
unsigned dll. 
+ check your GAC, probably if you have MySQL driver installed in may have 
put MySql.Data.dll in a GAC, so .NET would try to use version from GAC.

On Monday, February 29, 2016 at 6:53:37 PM UTC+2, Gray wrote:
>
> HI,
>
> I am Injecting code into the MySql.Data.dll with Mono.cecil,but it doesn't 
> work.It seemed to be working - if I decompile the assemblies with ILSpy 
> they show the injected code is there.
> I just want to add Console.WriteLine("run method Open") into Method Opne();
>
> static void Main(string[] args)
>         {
>             AssemblyDefinition asm = 
> AssemblyDefinition.ReadAssembly("F:\\MySql.Data.dll");
>             foreach (TypeDefinition type in asm.MainModule.Types)
>             {   
> //           
>                 if (type.Name.Equals("MySqlConnection"))
>                 {                
>                     foreach (MethodDefinition method in type.Methods)
>                     {  
> //                   
>                         if (method.Name == "Open")
>                         {                                                 
>                                                       
>                       var ilProcessor = method.Body.GetILProcessor();     
>                                                       
>                                 var firstInstruction = 
> ilProcessor.Body.Instructions[0];
> Instruction insStr = ilProcessor.Create(OpCodes.Ldstr, "run method Ope"); 
>                                
>                                 ilProcessor.InsertBefore(firstInstruction, 
> insStr);
>               MethodReference refernce = 
> asm.MainModule.ImportReference(typeof(Console).GetMethod("WriteLine",
>               new Type[] { typeof(string) }));
>                 Instruction insCall = ilProcessor.Create(OpCodes.Call, 
> refernce);
> ilProcessor.InsertAfter(insStr,insCall);
>                         }
>                     }//end for MethodDefinition  
>                 }
>             }//end for TypeDefinition            
>             asm.Write("F:\\MySql.Data.dll"); 
>        }
>
> I write a test code to run the mehod "Open" ,but it doesn't print "run 
> method Open" even "Console.WriteLine("run method Open");" has been in mehod 
> "Open".
> Can you please help me to resolve the error. 
>
> Thanks,
> Gray
>

-- 
-- 
--
mono-cecil
--- 
You received this message because you are subscribed to the Google Groups 
"mono-cecil" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to