I have a winforms app that is using reflection to load up assembly X. It runs great from my local machine, but craps out when run from a network share. I created a code group granting full trust(for testing only) to assemblies from the share (by specifying the url property). The app now launches up. However, it bombs when I try to perform an operation that requires X to access a dependent assembly Y with the following error:
Could not load file or assembly 'Bloomberg.Api, Version=1.8.0.3,
Culture=neutral, PublicKeyToken=65c07ea3148235aa' or one of its dependencies. Failed to grant minimum
permission requests. (Exception from HRESULT: 0x80131417)
I am loading assembly X into an appdomain using the following code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.IO;
using System.Reflection;
using TCPSecurityMaster;
using System.Windows.Forms;
using System.Security.Policy;
using System.Security;
using System.Security.Permissions;
namespace SecurityMasterReflectionTest
{
class Program
{
static void Main(string[] args)
{
try
{
AppDomainSetup ads = new AppDomainSetup();
ads.ApplicationBase = ConfigurationManager.AppSettings["SecurityMasterBinDir"];
ads.ConfigurationFile = Assembly.GetEntryAssembly().Location + ".config";
AppDomain newAD = AppDomain.CreateDomain("SM", null, ads);
string dir = ConfigurationManager.AppSettings["SecurityMasterBinDir"];
string asmName = dir + "\\" + ConfigurationManager.AppSettings["SecurityMasterFacadeAssemblyName"];
string typeName = ConfigurationManager.AppSettings["SecurityMasterFacadeClassName"];
if (File.Exists(asmName))
{
object obj = (ISecurityMasterAPI)newAD.CreateInstanceFromAndUnwrap(asmName, typeName);
ISecurityMasterAPI api = obj as ISecurityMasterAPI;
api.Initialize();
Form f = api.GetSecurityDetailDialog(35516);
f.ShowDialog();// this works, but a subsequent operation that requires assembly Y to be loaded doesn't
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
I would have imagined that granting full trust to all assemblies under the network share would have taken care of any CAS issues. Any hints appreciated.
-- UPDATE
In my code group, I had specified permission set as 'Everything' instead of 'Full Trust'. Changing to 'Full Trust' fixed the error. However, I am still mystified that I have to tweak CAS just for using reflection, while non-reflection code works fine over the network. Isn't there a programmatic way of saying "I fully trust this assembly I loaded over the network."? Any light shed on this appreciated.