在.NET Core 2.0 Preview 1中使用R.NET.Community

时间:2022-08-31 08:50:57

For a while, I've been hoping to use R.NET.Community in a .NET Core app. Obviously though with the NuGet package not having been ported to .NET Core, that's been a non-starter. However, with the .NET Core 2.0 Preview 1 announcement that you can reference .NET Framework libraries from .NET Core, I gave this another go:

有一段时间,我一直希望在.NET Core应用程序中使用R.NET.Community。显然虽然NuGet包没有移植到.NET Core,但这是一个非首发。但是,随着.NET Core 2.0 Preview 1的发布,您可以从.NET Core引用.NET Framework库,我又说了一遍:

using RDotNet;

namespace RDotNetCore2
{
    class Program
    {
        static void Main(string[] args)
        {
            REngine.SetEnvironmentVariables();
            var engine = REngine.GetInstance();
        }
    }
}

Creating this as a .NET Core 2.0 app in the new Visual Studio 2017 Preview, this at least gets as far as compiling and running, but errors at the GetInstance call:

在新的Visual Studio 2017预览版中将其创建为.NET Core 2.0应用程序,这至少可以进行编译和运行,但GetInstance调用时会出现错误:

Could not load file or assembly 'System.Security.Permissions, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

无法加载文件或程序集'System.Security.Permissions,Version = 0.0.0.0,Culture = neutral,PublicKeyToken = cc7b13ffcd2ddd51'。该系统找不到指定的文件。

Is there anything I can do to fix this, or this just one of those bits which isn't supported in .NET Core (which I suspect may be likely due to the fact that CAS isn't supported on .NET Core)?

有什么我可以做的来解决这个问题,或者这只是.NET Core中不支持的那些内容之一(我怀疑可能是由于.NET Core不支持CAS的事实)?

1 个解决方案

#1


1  

Are you sure this is a Framework version problem?

您确定这是一个Framework版本问题吗?

There isn't a System.Security.Permissions file in the 4.x version of .net (although there is a namespace). There is a dll with this name in .net Core 2.0, though (containing, for example, the PrincipalPermissions class. In .net 4.7, this class is implemented in mscorlib.dll).

4.x版本的.net中没有System.Security.Permissions文件(尽管有一个命名空间)。但是.net Core 2.0中有一个带有此名称的dll(例如,包含PrincipalPermissions类。在.net 4.7中,此类在mscorlib.dll中实现)。

It's probably worth having a look at your project references before you conclude that this isn't going to work. If you can add a reference there to the dll (which presumably you should have had installed with the Core 2.0 runtime), that might solve the problem.

在得出结论认为这不起作用之前,可能值得查看一下您的项目参考。如果你可以在那里添加一个引用到dll(可能你应该已经安装了Core 2.0运行时),这可能会解决问题。

#1


1  

Are you sure this is a Framework version problem?

您确定这是一个Framework版本问题吗?

There isn't a System.Security.Permissions file in the 4.x version of .net (although there is a namespace). There is a dll with this name in .net Core 2.0, though (containing, for example, the PrincipalPermissions class. In .net 4.7, this class is implemented in mscorlib.dll).

4.x版本的.net中没有System.Security.Permissions文件(尽管有一个命名空间)。但是.net Core 2.0中有一个带有此名称的dll(例如,包含PrincipalPermissions类。在.net 4.7中,此类在mscorlib.dll中实现)。

It's probably worth having a look at your project references before you conclude that this isn't going to work. If you can add a reference there to the dll (which presumably you should have had installed with the Core 2.0 runtime), that might solve the problem.

在得出结论认为这不起作用之前,可能值得查看一下您的项目参考。如果你可以在那里添加一个引用到dll(可能你应该已经安装了Core 2.0运行时),这可能会解决问题。