Search code examples
.netmonoironpython.net-corepython.net

How to use IronPython with .Net Core 1.0


I'm trying to add IronPython to a .Net Core 1.0 web app, but having issues able to access the ScriptRuntime class. When I try to add using IronPython; I get errors saying that IronPython could not be found.

I also get errors about ScriptRuntime does not exist in the current context

Note: Currently using Visual Studio Code on OSX 10.11

The following are t of the dependencies and framework sections of my project.json:

{
  "version": "1.0.0-*",
  "dependencies": {
    "EntityFramework.Commands": "7.0.0-rc1-final",
    "EntityFramework.Sqlite": "7.0.0-rc1-final",
    "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
    "Microsoft.AspNet.Authentication.Cookies": "1.0.0-rc1-final",
    "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-rc1-final",
    "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-final",
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
    "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
    "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
    "Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final",
    "Microsoft.Dnx.Runtime": "1.0.0-rc1-final",
    "Microsoft.Extensions.CodeGenerators.Mvc": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
    "Microsoft.NETCore.Platforms": "1.0.1-*",
    "Newtonsoft.Json": "8.0.3",
    "IronPython": "2.7.5",
    "IronPython.StdLib": "2.7.5"
  },
  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel",
    "ef": "EntityFramework.Commands"
  },
  "frameworks": {
    "dnx451": {},
    "dnxcore50": {}
  },
}

And in my controller I have the following using statements:

using System.IO;
using System.Diagnostics;
using Microsoft.AspNet.Authorization;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc;
using Microsoft.Net.Http.Headers;
using Newtonsoft.Json.Linq;
using MatrixSynthesisWebApp.Models;
using System.Dynamic;
using System.Runtime.CompilerServices;
using IronPython;

Solution

  • I believe it's not possible to use the IronPython NuGet package on .Net Core. That package is compiled for .Net Framework (and Silverlight), which means it's not usable from .Net Core.

    You might consider requesting IronPython to be ported to netstandard, which is usable from .Net Core, on the project's Github site.

    EDIT: It seems recent versions of the IronPython NuGet package support .Net Core 2.x. So it looks like this should work now.