I'm running into a strange issue in IronPython when I use a custom AppDomain and PermissionSet. For some reason, casting doubles to floats is not working correctly when the PermissionSet is not Unrestricted and I build targeting x64 platforms. When I build targeting x86 platforms or use PermissionState.Unrestricted, the issue goes away. I have also tried starting from PermissionState.None and adding every permission listed here as Unrestricted and it still doesn't work. I am using IronPython 2.7.4 for .NET 4.0. Below is a simple program that reproduces the problem. Any idea what's going on here?
using IronPython.Hosting;
using System;
using System.Security;
using System.Security.Permissions;
namespace TestApp
{
public class Program
{
private const string Test = @"
from System import Console
num = float(10.0)
Console.WriteLine(num)
";
public static void Main(string[] args)
{
// Prints 10 always
var permissionSet1 = new PermissionSet(PermissionState.Unrestricted);
RunTest(permissionSet1);
// Prints 0 on x64 builds
var permissionSet2 = new PermissionSet(PermissionState.None);
permissionSet2.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
RunTest(permissionSet2);
Console.ReadKey();
}
private static void RunTest(PermissionSet permissionSet)
{
var appDomainSetup = new AppDomainSetup { ApplicationBase = "." };
var evidence = AppDomain.CurrentDomain.Evidence;
var appDomain = AppDomain.CreateDomain("ScriptingSandbox", evidence, appDomainSetup, permissionSet);
var scriptEngine = Python.CreateEngine(appDomain);
var scriptSource = scriptEngine.CreateScriptSourceFromString(Test);
scriptSource.Execute();
}
}
}