1

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.

cs31415
  • 169
  • 3
  • 12

2 Answers2

1

After DLL are uploaded on internet and downloaded, they go in trust issues. Those needs to explicitly unblocked by going into Properties and click the "unblock" button and the problem may be solved.

enter image description here

Vaibhav Jain
  • 1,939
  • 26
  • 36
0

I received the same error in powershell, when I ran the line below:

Add-Type -Path WinSCPnet.dll

All I had to do to fix this issue is update powershell to v3.

http://www.microsoft.com/en-us/download/details.aspx?id=34595

When I tried to Adjust Zone Security settings(https://social.msdn.microsoft.com/Forums/en-US/d5135c8b-7629-464b-9078-8c179010ea82/minimum-permission-requests?forum=vblanguage), I couldn't find the .Net Framework Configuration tool. I think I couldn't find it, because my default .Net framework is 4.0.

JPlatts
  • 39
  • 4
  • If you have a new question, please ask it by clicking the [Ask Question](http://stackoverflow.com/questions/ask) button. Include a link to this question if it helps provide context. – deW1 Jun 17 '15 at 20:24
  • Is that what I am supposed to do even though I don't have a question? It's more of an answer to a question that hasn't been asked. – JPlatts Jun 17 '15 at 20:51
  • 1
    @JPlatts Yes, you can ask and answer your own question if you think it would help the community. Since this question is not tagged PowerShell, your answer is irrelevant in the context even though the error is the same. This particular error occurs in many different places, and trying to describe every possible fix in one thread would get out of hand very quickly (in the same way that describing all possible reasons for an HTTP 404 error without specifying an environment). – Dan Bechard Jun 01 '16 at 15:25