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.