private static MethodInfo GetCustomActionMethod( Session session, string assemblyName, string className, string methodName) { Assembly customActionAssembly; Type customActionClass = null; Exception caughtEx = null; try { //customActionAssembly = AppDomain.CurrentDomain.Load(assemblyName); var context = new CustomLoadContext(); customActionAssembly = context.LoadFromFile(assemblyName); customActionClass = customActionAssembly.GetType(className, true, true); } catch (IOException ex) { caughtEx = ex; } catch (BadImageFormatException ex) { caughtEx = ex; } catch (TypeLoadException ex) { caughtEx = ex; } catch (ReflectionTypeLoadException ex) { caughtEx = ex; } catch (SecurityException ex) { caughtEx = ex; } if (caughtEx != null) { session.Log("Error: could not load custom action class " + className + " from assembly: " + assemblyName); session.Log(caughtEx.ToString()); return(null); } MethodInfo[] methods = customActionClass.GetTypeInfo().GetMethods( BindingFlags.Public | BindingFlags.Static); foreach (MethodInfo method in methods) { if (method.Name == methodName && CustomActionProxy.MethodHasCustomActionSignature(method)) { return(method); } } session.Log("Error: custom action method \"" + methodName + "\" is missing or has the wrong signature."); return(null); }
private static IEmbeddedUI InstantiateUI(Session session, string uiClass) { int assemblySplit = uiClass.IndexOf('!'); if (assemblySplit < 0) { session.Log("Error: invalid embedded UI assembly and class:" + uiClass); return(null); } string assemblyName = uiClass.Substring(0, assemblySplit); EmbeddedUIProxy.uiClass = uiClass.Substring(assemblySplit + 1); Assembly uiAssembly; try { var context = new CustomLoadContext(); //uiAssembly = AppDomain.CurrentDomain.Load(assemblyName); uiAssembly = context.LoadFromFile(assemblyName); // This calls out to CustomActionProxy.DebugBreakEnabled() directly instead // of calling EmbeddedUIProxy.DebugBreakEnabled() because we don't compose a // class.method name for this breakpoint. if (CustomActionProxy.DebugBreakEnabled(new string[] { "EmbeddedUI" })) { System.Diagnostics.Debugger.Launch(); } var type = uiAssembly.GetType(EmbeddedUIProxy.uiClass); //return (IEmbeddedUI) uiAssembly.CreateInstance(EmbeddedUIProxy.uiClass); return((IEmbeddedUI)Activator.CreateInstance(type)); } catch (Exception ex) { session.Log("Error: could not load embedded UI class " + EmbeddedUIProxy.uiClass + " from assembly: " + assemblyName); session.Log(ex.ToString()); return(null); } }