Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi everyone! My question how to reslove this problem : System.ArgumentException: 'A null StrongName was found in the full trust assembly list.'. Here is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Security;
using System.Security.Policy;
using System.Security.Permissions;
using System.Reflection;
using System.Runtime.Remoting;
using System.Threading.Tasks;

class Sandboxer : MarshalByRefObject
{

    const string pathToUntrusted = @"C:\\Users\\Ugljesa\\source\\repos\\UkiSandbox.UKI.COMPUTERS\\UkiSandbox\\bin\\Debug";
    const string untrustedAssembly = @"C:\\Users\\Ugljesa\\Desktop\\mynew.snk";
    const string untrustedClass = "UntrustedCode.UntrustedClass";
    const string entryPoint = "IsFibonacci";

    private static Object[] parameters = { 45 };
    static void Main()
    {



        Console.BackgroundColor = ConsoleColor.DarkGreen;
        Console.ForegroundColor = ConsoleColor.Black;
        Console.Title = "UkiSandbox - Running app on :   " + pathToUntrusted;
        Console.WriteLine("UkiSandbox is running. Specified location is:          " + pathToUntrusted);



        AppDomainSetup adSetup = new AppDomainSetup();
        adSetup.ApplicationBase = Path.GetFullPath(pathToUntrusted);


        PermissionSet permSet = new PermissionSet(PermissionState.None);
        permSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));


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


        AppDomain newDomain = AppDomain.CreateDomain("Sandbox", evidence, 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();
        }
    }
}


And problem in this line code (two):
StrongName fullTrustAssembly = typeof(Sandboxer).Assembly.Evidence.GetHostEvidence<StrongName>();


        AppDomain newDomain = AppDomain.CreateDomain("Sandbox", evidence, adSetup, permSet, fullTrustAssembly);
.
And problem is this: System.ArgumentException: 'A null StrongName was found in the full trust assembly list.'. How to reslove this? Thanks advance.

What I have tried:

I'am don't know what to do. I'am tryed something steps: RESULT: FAILED.
Posted
Updated 6-Jul-21 0:14am

1 solution

As it says here How to: Run Partially Trusted Code in a Sandbox | Microsoft Docs[^]
Quote:
Code Access Security (CAS) is not supported in .NET Core, .NET 5, or later versions. CAS is not supported by versions of C# later than 7.0.
 
Share this answer
 
Comments
[no name] 6-Jul-21 6:34am    
RickZeeland, i'am have a C# 7.0, but can't ran? I'am used a link to develop a sandbox for you sended to me. And i'am working in visual studio 2017
RickZeeland 6-Jul-21 7:52am    
Ah, then that can not be the problem :)
[no name] 6-Jul-21 7:57am    
I'am downloaded today Visual Studio (older) :-]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900