问题描述
我正在将代码从.Net Framework 4.8升级到.Net 5.0。 有用的升级之一涉及在不重新启动应用程序的情况下即时加载和卸载程序集的可能性。到目前为止,我已经设法在c#中为加载程序集编写了以下函数。
但是,关于google的有关如何系统地执行此操作的信息,例如作为插件mod,很少或什至根本不存在管理应用程序执行期间加载/卸载的程序集!!!因此,我们非常感谢您的帮助。
private static FormCustomized loadLayout(global::System.String layoutFilename,global::System.String layoutNameSpace)
{
FormCustomized mainForm = default;
Type typeMainLayout = default;
FileInfo layoutFile;
layoutFile = new FileInfo(layoutFilename);
layoutFile.Refresh();
if (!layoutFile.Exists)
{
MessageBox.Show("Layout file not found. You need to reinstall the program");
return default;
}
try
{
Assembly assemblyRaw = Assembly.LoadFrom(layoutFilename);
AssemblyLoadContext context = AssemblyLoadContext.Default;
Assembly assembly = context.LoadFromAssemblyPath(layoutFilename);
Type typeMainLayoutIni = assembly.GetType(layoutNameSpace + ".initializeLayoutClass");
Object iniClass = Activator.CreateInstance(typeMainLayoutIni,true);
MethodInfo methodInfo = typeMainLayoutIni.GetMethod("AssembliesToLoadAtStart");
enVars.assemblies = (Dictionary<string,Environment.environmentAssembliesClass>)methodInfo.Invoke(iniClass,default);
typeMainLayout = assembly.GetType(layoutNameSpace + ".mainAppLayoutForm");
mainForm = Activator.CreateInstance(typeMainLayout,enVars) as FormCustomized;
}
catch (Exception ex)
{
return default;
}
return default;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)