0

My project is using .NET core "7.0" and the targeted module is "4.8" and when I try to import "GetString" method and inject it to the module using Dnlib, it references the higher version "7.0" instead of "4.8" and the output exe will crash because it can't find that higher reference dll.

....
....
body.Instructions.Add(new Instruction(OpCodes.Call, module.Import(typeof(Encoding).GetMethod("get_UTF8", new Type[] { }))));
.....
.....
body.Instructions.Add(new Instruction(OpCodes.Callvirt, module.Import(typeof(System.Text.Encoding).GetMethod("GetString", new Type[] { typeof(byte[]), typeof(Int32), typeof(Int32) }))));

Higher version

Any Idea how to import the right version.

Wael
  • 3
  • 4
  • .NET (Core) 7 can't use .NET Framework libraries. Whatever `Dnlib` is, you'll have to find a version that targets either .NET Core or .NET Standard. If it's your own project it should be modified to target .NET Standard 2.0 or .NET Core 6 – Panagiotis Kanavos Jan 16 '23 at 13:58
  • I know because it's working fine if both projects are using the same framework, but I hoped that Dnlib can somehow import it from another 4.8 exe or Dll and not the runtime. – Wael Jan 16 '23 at 14:11
  • .NET 7 is .NET *Core* 7, a completely different runtime. If by dnlib you mean [this package](https://www.nuget.org/packages/dnlib#readme-body-tab), it has a version that targets .NET Standard 2.0. – Panagiotis Kanavos Jan 16 '23 at 14:17

0 Answers0