Hey, I think that the problem is that you delete the method definition, but not its usage. If a method calls your DecryptString method, you'll likely face this exception, because the method has been detached from the module, but it still is referenced in the assembly.
So you'll need to go over each method body and decide what to do with that invocation. Jb On Wed, Jan 29, 2020 at 9:05 AM Jirka Šáda <[email protected]> wrote: > I have an assembly that contains a type named EncryptedStrings, and inside > it is a method called DecryptString. I wanted to remove this method from > the type and write the modified assembly back. I wrote this very simple > code for it: > > var file = @"path-to-file.exe"; > var ass = AssemblyDefinition.ReadAssembly(file); // load assembly > var type = ass.MainModule.GetType("EncryptedStrings"); // find the type > var method = type.Methods.First(meth => meth.Name == "DecryptString"); // > find the method in the > type type.Methods.Remove(method); // remove the method > ass.Write("fixed.exe"); // write assembly back > > However, when I run this code, I get an exception saying: > > System.ArgumentException: Member 'System.String > DecryptString(System.String)' is declared in another module and needs to > be imported > > > I have no idea what it wants from me... The method IS defined in that > module, so what am I supposed to import? > > What should I do to fix this and delete the method from the type? > > Many thanks, I a noob, started using Cecil yesterday > > -- > -- > -- > 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]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/mono-cecil/6146c1b4-6087-4ae9-9318-36808d48a95c%40googlegroups.com > <https://groups.google.com/d/msgid/mono-cecil/6146c1b4-6087-4ae9-9318-36808d48a95c%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- -- -- 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]. To view this discussion on the web visit https://groups.google.com/d/msgid/mono-cecil/CABsHH9Lf-z%2B2Oj5%3Da-9sjH8_eL%3DAP9c%3DCJXzW-XKrxjx%2BFRULA%40mail.gmail.com.
