Executing R.net in the same appdomain works great. Now, I want to have it run in a separate restricted appdomain. This throws the following exception:
System.TypeLoadException was unhandled
HResult=-2146233054
Message=Inheritance security rules violated by type: 'RDotNet.NativeLibrary.UnmanagedDll'. Derived types must either match the security accessibility of the base type or be less accessible.
Source=RBugReplication
TypeName=RDotNet.NativeLibrary.UnmanagedDll
StackTrace:
Here is the code the replicates the issue. All projects are built against .net 4.0. The project references RDotNet and RDotNet.Native library located in its 'lib' folder.
Thanks,
Vitaly
System.TypeLoadException was unhandled
HResult=-2146233054
Message=Inheritance security rules violated by type: 'RDotNet.NativeLibrary.UnmanagedDll'. Derived types must either match the security accessibility of the base type or be less accessible.
Source=RBugReplication
TypeName=RDotNet.NativeLibrary.UnmanagedDll
StackTrace:
at RBugReplication.Program.CreateREngine()
at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
at RBugReplication.Program.Main(String[] args) in c:\Users\For\Documents\Visual Studio 2013\Projects\RBugReplication\RBugReplication\Program.cs:line 35
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: Here is the code the replicates the issue. All projects are built against .net 4.0. The project references RDotNet and RDotNet.Native library located in its 'lib' folder.
class Program
{
static void Main(string[] args)
{
SetupPath();
var ps = new PermissionSet(PermissionState.None);
ps.AddPermission(new SecurityPermission(PermissionState.Unrestricted));
ps.AddPermission(new FileIOPermission(PermissionState.Unrestricted));
ps.AddPermission(new ReflectionPermission(PermissionState.Unrestricted));
ps.AddPermission(new EnvironmentPermission(PermissionState.Unrestricted));
var appDomain = AppDomain.CreateDomain(
"sandbox",
new Evidence(),
AppDomain.CurrentDomain.SetupInformation,
ps);
appDomain.DoCallBack(LoadAssemblies);
appDomain.DoCallBack(CreateREngine);
}
public static void SetupPath()
{
var oldPath = Environment.GetEnvironmentVariable("PATH");
var rPath = @"C:\Program Files\R\R-3.0.2\bin\x64";
var newPath = string.Format("{0}{1}{2}", rPath, Path.PathSeparator, oldPath);
Environment.SetEnvironmentVariable("PATH", newPath);
}
private static void LoadAssemblies()
{
LoadDll(@"..\..\lib\RDotNet.NativeLibrary.dll");
LoadDll(@"..\..\lib\RDotNet.dll");
}
private static void LoadDll(string libFileName)
{
var absoluteLibPath = Path.GetFullPath(libFileName);
if (File.Exists(Environment.CurrentDirectory + "\\" + Path.GetFileName(libFileName)) == false)
File.Copy(absoluteLibPath, Environment.CurrentDirectory + "\\" + Path.GetFileName(libFileName));
Assembly.LoadFile(absoluteLibPath);
}
private static void CreateREngine()
{
var e = REngine.CreateInstance("test");
}
}
Has anybody seen this issue in the past? Any help would be appreciated.Thanks,
Vitaly