Loading Assemblies from a .Net Application in a 'Sandbox Environment'

半腔热情 提交于 2019-11-30 10:31:54

Normally, you might just live with

AppDomain newDomain = AppDomain.CreateDomain(name);
Assembly asm = newDomain.Load(System.IO.File.ReadAllBytes(name));

But one interesting point is, the AppDomain.Load method will load the assembly to the new app domain, as well as to the current domain.

A more elegant solution is to use System.AddIn namespace in 3.5. - http://msdn.microsoft.com/en-us/magazine/cc163476.aspx

Then, you can actually specify the trust level for your addin, using the AddinSecurityLevel like

//Activate the selected AddInToken in a new
//application domain with the Internet trust level.
Calculator CalcAddIn = selectedToken.Activate<Calculator>(AddInSecurityLevel.Internet);

See http://msdn.microsoft.com/en-us/library/bb355219.aspx for details.

What you're looking to do is basically running Assemblies in a separate Application Domain. Check out this page on MSDN for a good starting point. It's actually quite east to do:

http://msdn.microsoft.com/en-us/library/ms173139(VS.80).aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!