Replies: 1 comment 4 replies
-
You don't need to import fields if they're in the assembly you're modifying. They're already there. You only need to import external references. The following line: m2.Module.GetType("ModController").Fields.Add(m2.Module.ImportReference(typeof(ModController).GetField("Instance")).Resolve()); is trying to add a field which already exists in the list of fields. It also assumes the assembly you're modifying is using the same runtime as the code that's running Cecil. Have you tried the following? m2.Module.GetType("ModController").Fields.Single(i => i.Name == "Instance") |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi guys, I hope someone of you can help me with that one.
I did figure out how to "overwrite" a function inside a library, but I can't get it to work with a Field that is inside the same Type as the function I did overwrite.
I know I have to "import" the field somehow, but I can't figure out how.
If i do
it would tell me "Member already attached", so I probably do something wrong. I did read the "import" part inside the documentation, but I don't quite understand it, and it doesn't talk about Fields.
Without this part, when i call target.write("filename") it would throw an exception:
The code that will overwrite the old function is this one here:
I just don't get how to import "Instance" (which is a custom object)...
I hope anyone can help me on this one, as this seems to be the only problem by now. I did try to find more informations about that specific exception, but most "solutions" I've found were for other things than Fields.
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions