在完全信任程序集列表沙箱应用程序中找到空的强名称 [英] A null strongname was found in the full trust assembly list sandbox application

查看:68
本文介绍了在完全信任程序集列表沙箱应用程序中找到空的强名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论何时运行,我都在.net中开发了沙箱应用程序

错误"  

I had develop the sandbox application in .net.whenever run the application i get the 

error "  

"

在行上发生错误

AppDomain newDomain = AppDomain.CreateDomain("Sandbox", null, adSetup, permSet, fullTrustAssembly);

我的应用程序:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;  
using System.Threading.Tasks;

namespace UntrustedCode
{
    public class UntrustedClass 
    {
        public static bool IsFibonacci(int number)
        {
            File.ReadAllText("C:\\TEMP\\file.txt");
            return false;
        } 
    }
}

在沙箱中运行应用程序:

<pre>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Security;
using System.Security.Policy;
using System.Security.Permissions;
using System.Reflection;
using System.Runtime.Remoting;  

namespace Sandboxer 
{
    class Sandboxer : MarshalByRefObject
    {
        const string pathToUntrusted = @"C:\Users\Amma\Documents\visual studio 2012\Projects\UntrustedCode\UntrustedCode\bin\Debug";
        const string untrustedAssembly = "UntrustedCode";
        const string untrustedClass = "UntrustedCode.UntrustedClass";
        const string entryPoint = "IsFibonacci";
        private static Object[] parameters = { 11 };  
        static void Main(string[] args)
        {
            
            AppDomainSetup adSetup = new AppDomainSetup();
            adSetup.ApplicationBase = Path.GetFullPath(pathToUntrusted);

            
            PermissionSet permSet = new PermissionSet(PermissionState.None);
            permSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
            
            StrongName fullTrustAssembly = typeof(Sandboxer).Assembly.Evidence.GetHostEvidence<StrongName>();

  
            AppDomain newDomain = AppDomain.CreateDomain("Sandbox", null, adSetup, permSet, fullTrustAssembly);

            
            ObjectHandle handle = Activator.CreateInstanceFrom(
                newDomain, typeof(Sandboxer).Assembly.ManifestModule.FullyQualifiedName,
                typeof(Sandboxer).FullName
                );
           
            Sandboxer newDomainInstance = (Sandboxer)handle.Unwrap();
            newDomainInstance.ExecuteUntrustedCode(untrustedAssembly, untrustedClass, entryPoint, parameters);  
        }
        public void ExecuteUntrustedCode(string assemblyName, string typeName, string entryPoint, Object[] parameters)
        {
            
            MethodInfo target = Assembly.Load(assemblyName).GetType(typeName).GetMethod(entryPoint);
            try
            {
                
                bool retVal = (bool)target.Invoke(null, parameters);
            }
            catch (Exception ex)
            {
               
                (new PermissionSet(PermissionState.Unrestricted)).Assert();
                Console.WriteLine("SecurityException caught:\n{0}", ex.ToString());
                CodeAccessPermission.RevertAssert();
                Console.ReadLine();
            }
        }  








    }
}

为什么会出现错误.

我签署了带有强力名称的程序集,该代码在代码中显得很重要

  StrongName fullTrustAssembly = typeof(Sandboxer).Assembly.Evidence.GetHostEvidence<StrongName>();



请帮助我.



please help me.




推荐答案

请帮助我.解决错误


这篇关于在完全信任程序集列表沙箱应用程序中找到空的强名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆