问题描述
我有一个&我内置的方法在运行时编译并成功执行.我的问题是如何卸载/重新分配该程序集,以便可以再次运行代码并重新生成程序集,而不必重新启动应用程序.我在尝试时与正在使用的文件发生命名冲突.我的程序集被编译为"dyn.dll".
这是我实例化它的方式:
I have a class & method I built in code and compiled at runtime and successfully execute. My question is how do i unload/deallocate that assembly so I can rerun the code again and rebuild the assembly without having to restart the app. I am getting a naming conflict with a file in use when I try. My assembly is compiled as "dyn.dll".
Here is how I instantiate it:
parms.OutputAssembly = "Dyn.dll";
CompilerResults results = provider.CompileAssemblyFromSource(parms, SourceCode);
if (results.Errors.Count > 0)
foreach (CompilerError ce in results.Errors)
MessageBox.Show(ce.ToString());
else
{
Assembly assem = Assembly.LoadFile(Application.StartupPath + "\\dyn.dll");
AssemblyName assemName = assem.GetName();
Type [] t = assem.GetTypes();
MethodInfo [] mi = t[0].GetMethods();
obj = t[0].InvokeMember("GetRunTimeData", BindingFlags.InvokeMethod,
null, null, new Object[] { pcs, milePostFormat, new DataAccess() });
bs.DataSource = obj;
}
第二个问题是,如果我在内存中生成该程序集,那么我似乎无法获得该程序集的句柄,因此我现在正在创建实际文件.
谢谢
A second question would be I cannot seem to get a handle on this assembly if I generate it in memory so I am creating the actual file for now. what aa I missing to do this all in memory?
Thanks
推荐答案
这篇关于卸载动态组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!