private MethodReference GetCalleeMethod() { Debug.Assert(Assembly != null); ModuleDefinition module = Assembly.MainModule; string methodName; TypeDefinition moduleInitializerClass; if (string.IsNullOrEmpty(ModuleInitializer)) { methodName = "Run"; moduleInitializerClass = Find(module.Types, t => t.Name == "ModuleInitializer"); if (moduleInitializerClass == null) { LogError(Errors.NoModuleInitializerTypeFound()); return(null); } } else { if (!ModuleInitializer.Contains("::")) { LogError(Errors.InvalidFormatForModuleInitializer()); return(null); } string typeName = ModuleInitializer.Substring(0, ModuleInitializer.IndexOf("::")); methodName = ModuleInitializer.Substring(typeName.Length + 2); moduleInitializerClass = Find(module.Types, t => t.FullName == typeName); if (moduleInitializerClass == null) { LogError(Errors.TypeNameDoesNotExist(typeName)); return(null); } } // Don't do load this type because it will add a reference to mscorlib 2.0 // and this brings problems if the original .dll was targetting something else. //TypeReference voidRef = module.Import(typeof(void)); MethodDefinition callee = Find(moduleInitializerClass.Methods, m => m.Name == methodName && m.Parameters.Count == 0); if (callee == null) { LogError(Errors.NoSuitableMethodFoundInType(methodName, moduleInitializerClass.FullName)); return(null); } if (callee.IsPrivate || callee.IsFamily) { LogError(Errors.ModuleInitializerMayNotBePrivate()); return(null); } if (!callee.ReturnType.FullName.Equals("System.Void")) //Comparing the objects themselves doesn't work as of Mono.Cecil 0.9 for some reason... { LogError(Errors.ModuleInitializerMustBeVoid()); return(null); } voidTypeRef = callee.ReturnType; return(callee); }