1

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();
        }
    }
}
  • 2
    "is not working correctly" gives us almost no information. What happens? – Jon Skeet Jun 05 '14 at 16:19
  • 2
    In the comments it says it writes 10 on one test, and zero in the next. Obviously would have been better to state this in the question for clarity. – Daniel Kelley Jun 05 '14 at 16:21
  • At a first stab I could not reproduce your issue. What .NET run-time version are you executing this on? Do you just change **Build/Platform Target** to **x64** for it to break? – Simon Opelt Jun 05 '14 at 16:47
  • Looking in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full I see Release is 378389 and Version is 4.5.50709. I am running in Visual Studio 2012 and switching the Build/Platform Target from x86 to x64 to cause the issue. In x64 with PermissionState.Unrestricted it will work. – user3711977 Jun 05 '14 at 17:06
  • @SimonOpelt Do you have IronPython installed on your machine? I was able to reproduce after I uninstalled IronPython and used the IronPython nuget package. It behaved correctly (two 10s printed) before I uninstalled. Reinstalling gives the correct behavior. – user815512 Jun 05 '14 at 17:31
  • The truly weird thing is that Python (and IronPython) floats *are* doubles. `float(10.0)` should be a no-op. – Jeff Hardy Jun 11 '14 at 10:06

0 Answers0