How to make a DLL optional in a .Net app
We have an app the requires Full Trust because of a Chilkat .NET 3.5 DLL This has not been a huge issue, however we would like to submit our app to the: Windows Web Applicatio开发者_运维问答n Gallery and it must be Medium Trust.
So to make it medium trust all we need to do is
- remove the reference to the DLL
- comment out the methods that tie into that code
Rather than making 2 different versions of the app, what is the best approach to remove the reference to the DLL for one version of the app?
thanks!
That’s not a simple one, but my first thoughts on this would be to abstract it out with and interface and late bind it in, but you must remember to check you have full trust when you load it or it might not work.
static class Program
{
static void Main(string[] args)
{
Assembly asm = Assembly.Load("ExampleAssembly, Version=1.0.0.0, Culture=en, PublicKeyToken=a5d015c7d5a0b012");
IFullTrustAddin addin = asm.CreateInstance("Namespace.MyChilkatWrapper") as IFullTrustAddin;
if (addin == null)
return;
addin.DoSomething();
}
}
interface IFullTrustAddin
{
void DoSomething();
}
精彩评论