Answer the question
In order to leave comments, you need to log in
How to forward an interface through dynamic in C#?
Good day! I am writing a program with plugins. All plugins are classes that implement the KrotAPI.IKrotPlugin interface. The KrotAPI namespace is taken from the krotapi.cs file common to all plugin projects. The same file is attached to the host project. The procedure for loading a plugin by a host is as follows:
dynamic LoadPlugin(Assembly asm)
{
foreach (Type type in asm.GetTypes())
{
if (type.GetInterface("KrotAPI.IKrotPlugin") != null)
{
PluginType = type;
dynamic inst = Activator.CreateInstance(type);
KrotAPI.IKrotPlugin inst2 = inst as KrotAPI.IKrotPlugin;
if (inst2 == null) return inst;
Console.WriteLine("Есть привязка к стандартному API.");
return inst2;
}
}
throw new Exception("Нет плагинов Крота в сборке.");
}
int HostEar(string Command, Dictionary<string, object> Arguments, out object Result)
Microsoft.CSharp.RuntimeBinder.RuntimeBinder
Internal Compiler Exception
An unexpected exception occurred while binding a dynamic operation
Answer the question
In order to leave comments, you need to log in
Solved by statically linking both the host and the plugins, with an assembly containing the interface.
stackoverflow.com/questions/42376539/how-to-access...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question