dimanche 6 octobre 2019

Is it possible to add a new dependency to a .dll without changing the source code?

I have two dotnetcore2.1 projects. First project calls a method of the second project via reflection.

using System;
using System.Reflection;

namespace experiment1
{
    class Program
    {
        static void Main(string[] args)
        {
            Type _type = Type.GetType("experiment2.Program");
            object _object = Activator.CreateInstance(_type);
            MethodInfo info = _type.GetMethod("SecondProjectsMethod");
            info.Invoke(_object, new object[]{});
        }
    }
}

I can't give any reference to the Second Project nor changes its code. How can I make this call successfully without adding a Reference to the First Project? I tried to add records to the first project's deps-file and execute the first program like this:

dotnet exec --depsfile experiment1.deps.json experiment1.dll

It didn't work. Is it even possible to do this by changing deps-file or any other config? Or should I manipulate .dll file somehow? Which direction I should go?





Aucun commentaire:

Enregistrer un commentaire