Sorry, did not figure out how to better formulate the question. I understand with reflection. I have my own pseudo-WAMP protocol bike =) I want to remotely call methods using RPC. And since I understand reflection, I want to make the application extensible. Those. so that later I could just write a plugin library. Throw it into the folder with the wamp-server and use it remotely.

Actually, the problem arose when I use a link to some other library in my library. The server does not see the second library by itself, and therefore it cannot execute the method from my library.

How besides my library to connect also those to which mine refers?

Method that is now:

private string CallInvoke(WebSocketSession session, Call call) { try { string filepath = Environment.CurrentDirectory + "/Plugins/" + call.PluginFileName; //Если файл плагина не найден if (!File.Exists(filepath)) { CallError callError = new CallError(call.CallId, "Plugin file not found.\r\n(" + filepath + ")"); return JsonSerialize(callError); } Assembly asm = Assembly.LoadFile(filepath); Type _class = null; MethodInfo _method = null; var types = asm.GetTypes(); //Если в плагине нет нужного класса if (types.Count(x => x.Name == call.ClassName) == 0) { CallError callError = new CallError(call.CallId, "Class \"" + call.ClassName + "\" not found in assembly \"" + asm.FullName + "\"."); return JsonSerialize(callError); } _class = types.Single(x => x.Name == call.ClassName); var methodInfos = _class.GetMethods(); //Если в классе нет нужного метода if (methodInfos.Count(x => x.Name == call.MethodName) == 0) { CallError callError = new CallError(call.CallId, "Method \"" + call.MethodName + "\" not found in class \"" + call.ClassName + "\"."); return JsonSerialize(callError); } _method = methodInfos.Single(x => x.Name == call.MethodName); object result = null; if (call.Params is null) result = _method.Invoke(null, null); else result = _method.Invoke(null, new object[] { call.Params }); CallResult callResult = new CallResult(call.CallId, result); return JsonSerialize(callResult); }catch(Exception ex) { CallError callError = new CallError(call.CallId, ex.Message); return JsonSerialize(callError); } } 

    1 answer 1

    .NET does not see the dependent library because it is not in the application directory.

    The easiest method is to put plugins with all dependencies directly into the application directory, and not to steam. And to load assembly through Assembly.Load , it is the most correct way. If you really, really want, you can install the assembly probing path in the app.config:

     <configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <probing privatePath="Plugins"/> </assemblyBinding> </runtime> </configuration> 

    (and still use Assembly.Load ).

    More details here: How to set the structure of the output project?

    • Not really. The essence of the plugins is that they do not recompile the main project for each plugin. - Alexander Lee
    • Found such a thing: Assembly.GetReferencedAssemblies (). I do not quite understand how to use them. After loading the assembly, you need to somehow specify the method being called? Or does it just hang in the memory of demand? - Alexander Lee
    • @AlexanderLi: Why not? What exactly does not fit? - VladD
    • Because it is necessary to recompile the main project whenever I want to add a plugin that uses the new library. Or not? - Alexander Lee
    • @AleksandrLee: In theory, no, you can start a Solution for each plug-in, if you want. - VladD