什么是编组,我们为什么需要它?
我发现很难相信我不能通过int
电线从C#发送到C并且必须对其进行编组.为什么C#只能通过一个起始和终止信号发送32位,告诉C代码它已经收到了int
?
如果有任何好的教程或网站关于我们为什么需要编组以及如何使用它,那将是很好的.
我有一个应用程序加载DLL来执行特定的处理部分
Example : "Application.dll" loading "Process.dll"
Run Code Online (Sandbox Code Playgroud)
Process.dll在运行时使用反射动态加载,而不是在应用程序中引用.
处理完成后,需要在服务器上重新编译DLL并稍后再次加载.
为了做到这一点,我需要释放它,否则我收到以下消息:"无法将文件"Process.dll"复制到"Process.dll".进程无法访问文件'Process.dll',因为它是被另一个进程使用."
所以问题是:如何Process.dll
在重新加载之前以编程方式从我的应用程序中释放/释放/卸载.当然,重点是在不停止应用程序的情况下执行此操作.
编辑1:
建议的解决方案是这样的:
AppDomain newDomain4Process = AppDomain.CreateDomain("newDomain4Process");
Assembly processLibrary = newDomain4Process.Load("Process.dll");
AppDomain.Unload(newDomain4Process);
Run Code Online (Sandbox Code Playgroud)
我仍然遇到的问题是,虽然我给出了正确的完整路径,但我得到了一个FileNotFound Exception
.这篇文章的答案也没有预期的效果.
编辑2:
这篇文章救了我的命,这里是代码:
class ProxyDomain : MarshalByRefObject
{
public Assembly GetAssembly(string AssemblyPath)
{
try
{
return Assembly.LoadFrom(AssemblyPath);
}
catch (Exception ex)
{
throw ex;
}
}
}
ProxyDomain pd = new ProxyDomain();
Assembly a = pd.GetAssembly(FullDLLPath);
Run Code Online (Sandbox Code Playgroud)
编辑3:
我没有访问AppDomain并使用之前的解决方案卸载它.当我使用经典的AppDomain创建方法时,我感觉到阿列克谢的警告:AppDomain.Unload
"似乎"工作,但程序集仍然被加载(模块视图).所以我仍然以某种方式遇到问题,因为我无法真正有效地卸载DLL.