Click here to Skip to main content
15,886,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to allow the user to code for my application by using a template project that compiles into a DLL file that the main program will look for.

Lets say I have:
mainapp.exe
userscode.dll
And all of the other DLLS that C# generates.

In mainapp.exe, there would be a function like:

C#
namespace MyApp {
    class ThisClass {
        public static void CallThisFunctionExternally()
        {
            Console.WriteLine("This function has been called by the User's DLL file!")
        }
    }
}


and the user's code would be:

C#
namespace UsersCode {
    class UserClass {
         public static void CallMainFunction()
         {
             //Load main program's namespace
             MyApp.ThisClass.CallThisFunctionExternally();
         }
    }
}


I don't want the code to run on the DLL, I want it to run as if it were called from inside the main program.

Thank you!



I've tried to use `Assembly.LoadFrom(path)` but I couldn't figure out how to use it and I'm not sure it would do what I want.

What I have tried:

I've tried to use Assembly.LoadFrom(path) but I couldn't figure out how to use it and I'm not sure it would do what I want.
Posted
Updated 7-Jun-23 13:20pm
v2
Comments
PIEBALDconsult 7-Jun-23 19:02pm    
I'm confused. Do you have things backward there?
[no name] 7-Jun-23 19:24pm    
You "inject" (a reference to) the calling program, into the dll, by calling into the dll, using an interface defined in the dll.

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/interface

1 solution

What you are doing here is mnearly the same as asked here ; How do I get parent's property from child class?[^]

It is the wrong way of dependency and was very clearly answered by OriginalGriff.
The MainApp can use something from the used and integrated DLL - but how should be the dependency the other way round ? If you want to do it like this your class-library is no more independant from the MainApp - and that makes no sense.

What you could do is :
- create another Library which could be used either from the MainApp and also from the other Library ...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900