I am using CSharpCodeProvider
to compile C# into a dynamic assembly which contains methods that are called by an external software.
Let's take the following code string that I am compiling dynamically:
public static class Foo
{
public static object Bar(a, b) {
return NameSpace.Type.Method(a, b); // Need to call original/compiling assembly
}
}
What I really want to do when calling NameSpace.Type.Method
, is to call a method inside the assembly that originally compiled the C# code (i.e. the one using the CSharpCodeProvider
).
That said, I cannot use ReferencedAssemblies.Add
to pass it into the CSharpCodeProvider
. This is because my assembly (DLL) is wrapped in such a way that it is dynamically loaded - i.e. it exists nowhere on the file system.
Is there any other way to call a method on the compiling assembly?
Post-Closure Edit:
The referenced question uses ReferencedAssemblies.Add
which, as I stated above, I am unable to use due to the fact that the calling assembly does not actually exist on the file system and only in memory.
Furthermore, the referenced question refers to the scenario of calling one dynamically compiled assembly from another. My scenario is different in that I need to call the original (compiling) assembly - and it does not exist as a DLL on the system since it is loaded from within a packed module by a third-party application.