Replies: 1 comment 3 replies
-
Hi, I'm not exactly sure I understand what the issue or what the question is :) Cecil and Roslyn being two different APIs there is no mapping between a Cecil assembly and a Roslyn assembly. Cecil also only reads and writes binaries, so it doesn't necessarily know where system assemblies are. Again, I'm not quite sure how to help :) |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I'm new to the forum, I did some DLL patching for .NET in the past using dnSpy and wanted to automate the patch for the future, so I looked into Mono.Cecil and Microsoft.CodeAnalysis.CSharp.
I'm interested in compiling some code into an existing dll in code and then save the new assembly.
For obvious reasons I made minimal changes in the current assembly methods (add a call, skip a check and so on) and those must be done in IL, but, I used to add methods to existing classes using dnSpy interface.
Apparently this requires building C# code to generate IL to then copy into the assembly with Cecil and I faced a problem, Roslyn requires
MetadataReference
of the assemblies used in the code (reasonable assumption), but I found only load from file as an option, although those assembly references are present in the target assembly tooassembly.MainModule.AssemblyReferences
.I wanted to use those pre-existing references in the compiled code (since method name/version etc. is all present in the original assembly).
This is important because I'm using Cecil in .NET core (for cross platform reasons) to patch a .NET4 dll so assemblies are not the same (e.g. using typeof(Console).Assembly and so on does not result in the correct bindings).
Thanks in advance for the help, here is some reference code:
Beta Was this translation helpful? Give feedback.
All reactions