You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2017/11/21 12:10:03 UTC

[09/47] ignite git commit: IGNITE-5343 .NET: Work with JNI directly, get rid of C++ layer

IGNITE-5343 .NET: Work with JNI directly, get rid of C++ layer

This closes #2985


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/ec38564a
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/ec38564a
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/ec38564a

Branch: refs/heads/ignite-zk
Commit: ec38564a83ecddd520f5227d904468c04720389a
Parents: 46c480b
Author: Pavel Tupitsyn <pt...@apache.org>
Authored: Tue Nov 14 17:17:56 2017 +0300
Committer: Pavel Tupitsyn <pt...@apache.org>
Committed: Tue Nov 14 17:17:56 2017 +0300

----------------------------------------------------------------------
 .../Apache.Ignite.AspNet.csproj                 |   3 +-
 .../Apache.Ignite.Core.Tests.csproj             |   2 +
 .../Cache/CacheConfigurationTest.cs             |   7 +
 .../Cache/MemoryMetricsTest.cs                  |   1 +
 .../Cache/PersistentStoreTestObsolete.cs        |   6 +-
 .../Compute/ComputeApiTestFullFooter.cs         |   2 +
 .../ConsoleRedirectTest.cs                      |  45 +-
 .../Apache.Ignite.Core.Tests/DeploymentTest.cs  | 137 +++--
 .../Apache.Ignite.Core.Tests/ExecutableTest.cs  |  18 +-
 .../IgniteConfigurationTest.cs                  |   1 +
 .../IgniteStartStopTest.cs                      |  12 +-
 .../MultiAppDomainTest.cs                       | 171 +++++++
 .../Process/ListDataReader.cs                   |  52 ++
 .../Apache.Ignite.Core.Tests/TestUtils.cs       |  18 +-
 .../Apache.Ignite.Core.csproj                   |  57 +--
 .../dotnet/Apache.Ignite.Core/Ignition.cs       |  26 +-
 .../Apache.Ignite.Core/Impl/ExceptionUtils.cs   |  20 +-
 .../dotnet/Apache.Ignite.Core/Impl/Ignite.cs    |   4 +-
 .../Apache.Ignite.Core/Impl/IgniteManager.cs    |  79 +--
 .../Apache.Ignite.Core/Impl/IgniteUtils.cs      |  82 +--
 .../Impl/PlatformJniTarget.cs                   | 248 ++++++---
 .../Impl/Unmanaged/IUnmanagedTarget.cs          |  42 --
 .../Impl/Unmanaged/IgniteJniNativeMethods.cs    |  96 ----
 .../Impl/Unmanaged/Jni/AppDomains.cs            | 135 +++++
 .../Impl/Unmanaged/Jni/CallbackDelegates.cs     |  52 ++
 .../Impl/Unmanaged/Jni/Callbacks.cs             | 292 +++++++++++
 .../Impl/Unmanaged/Jni/ConsoleWriter.cs         |  40 ++
 .../Impl/Unmanaged/Jni/Env.cs                   | 500 +++++++++++++++++++
 .../Impl/Unmanaged/Jni/EnvDelegates.cs          | 109 ++++
 .../Impl/Unmanaged/Jni/EnvInterface.cs          | 263 ++++++++++
 .../Impl/Unmanaged/Jni/GlobalRef.cs             |  87 ++++
 .../Impl/Unmanaged/Jni/JniResult.cs             |  35 ++
 .../Impl/Unmanaged/Jni/Jvm.cs                   | 335 +++++++++++++
 .../Impl/Unmanaged/Jni/JvmDelegates.cs          |  31 ++
 .../Impl/Unmanaged/Jni/JvmInterface.cs          |  40 ++
 .../Impl/Unmanaged/Jni/MethodId.cs              | 157 ++++++
 .../Impl/Unmanaged/Jni/NativeMethod.cs          |  48 ++
 .../Impl/Unmanaged/UnmanagedCallbackHandlers.cs |  38 --
 .../Impl/Unmanaged/UnmanagedCallbacks.cs        | 236 ++-------
 .../Impl/Unmanaged/UnmanagedContext.cs          |  53 --
 .../Unmanaged/UnmanagedNonReleaseableTarget.cs  |  70 ---
 .../Impl/Unmanaged/UnmanagedTarget.cs           |  77 ---
 .../Impl/Unmanaged/UnmanagedUtils.cs            | 257 ++++------
 .../dotnet/Apache.Ignite.Core/build-common.ps1  |  77 ---
 .../Apache.Ignite.EntityFramework.csproj        |   3 +-
 .../Apache.Ignite.Log4Net.csproj                |   4 +-
 modules/platforms/dotnet/Apache.Ignite.ndproj   |   8 +-
 modules/platforms/dotnet/Apache.Ignite.sln      | 143 ------
 .../dotnet/Apache.Ignite/IgniteRunner.cs        |   8 +-
 modules/platforms/dotnet/DEVNOTES.txt           |  15 +-
 50 files changed, 2939 insertions(+), 1303 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/ec38564a/modules/platforms/dotnet/Apache.Ignite.AspNet/Apache.Ignite.AspNet.csproj
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.AspNet/Apache.Ignite.AspNet.csproj b/modules/platforms/dotnet/Apache.Ignite.AspNet/Apache.Ignite.AspNet.csproj
index 4508776..ade81cc 100644
--- a/modules/platforms/dotnet/Apache.Ignite.AspNet/Apache.Ignite.AspNet.csproj
+++ b/modules/platforms/dotnet/Apache.Ignite.AspNet/Apache.Ignite.AspNet.csproj
@@ -25,7 +25,7 @@
     <DefineConstants>TRACE;DEBUG;CODE_ANALYSIS</DefineConstants>
     <DebugType>full</DebugType>
     <PlatformTarget>AnyCPU</PlatformTarget>
-    <RunCodeAnalysis>true</RunCodeAnalysis>
+    <RunCodeAnalysis>false</RunCodeAnalysis>
     <ErrorReport>prompt</ErrorReport>
     <CodeAnalysisRuleSet>Apache.Ignite.AspNet.ruleset</CodeAnalysisRuleSet>
     <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
@@ -39,6 +39,7 @@
     <CodeAnalysisRuleSet>Apache.Ignite.AspNet.ruleset</CodeAnalysisRuleSet>
     <DocumentationFile>bin\Release\Apache.Ignite.AspNet.XML</DocumentationFile>
     <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
+    <RunCodeAnalysis>false</RunCodeAnalysis>
   </PropertyGroup>
   <PropertyGroup>
     <ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec38564a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
index 6c7e2b8..2ef6db1 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
@@ -161,10 +161,12 @@
     <Compile Include="Common\IgniteGuidTest.cs" />
     <Compile Include="Deployment\RuntimeDependencyFunc.cs" />
     <Compile Include="EventsTestLocalListeners.cs" />
+    <Compile Include="Process\ListDataReader.cs" />
     <Compile Include="Log\ConcurrentMemoryTarget.cs" />
     <Compile Include="Log\DefaultLoggerTest.cs" />
     <Compile Include="Log\Log4NetLoggerTest.cs" />
     <Compile Include="Log\NLogLoggerTest.cs" />
+    <Compile Include="MultiAppDomainTest.cs" />
     <Compile Include="Plugin\Cache\CacheJavaPluginConfiguration.cs" />
     <Compile Include="Plugin\Cache\CacheJavaPluginTest.cs" />
     <Compile Include="Plugin\PluginTest.cs" />

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec38564a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs
index b5d8367..9593777 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs
@@ -81,10 +81,17 @@ namespace Apache.Ignite.Core.Tests.Cache
                             Name = "myMemPolicy",
                             InitialSize = 77 * 1024 * 1024,
                             MaxSize = 99 * 1024 * 1024
+                        },
+                        new MemoryPolicyConfiguration
+                        {
+                            Name = MemoryConfiguration.DefaultDefaultMemoryPolicyName,
+                            InitialSize = 55 * 1024 * 1024,
+                            MaxSize = 88 * 1024 * 1024
                         }
                     }
                 },
 #pragma warning restore 618
+                DataStorageConfiguration = null,
                 SpringConfigUrl = "Config\\cache-default.xml"
             };
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec38564a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/MemoryMetricsTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/MemoryMetricsTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/MemoryMetricsTest.cs
index 7ccee94..67319f4 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/MemoryMetricsTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/MemoryMetricsTest.cs
@@ -102,6 +102,7 @@ namespace Apache.Ignite.Core.Tests.Cache
         {
             var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration())
             {
+                DataStorageConfiguration = null,
                 MemoryConfiguration = new MemoryConfiguration
                 {
                     DefaultMemoryPolicyName = MemoryPolicyWithMetrics,

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec38564a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/PersistentStoreTestObsolete.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/PersistentStoreTestObsolete.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/PersistentStoreTestObsolete.cs
index a6b9b3b..63a9f47 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/PersistentStoreTestObsolete.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/PersistentStoreTestObsolete.cs
@@ -60,7 +60,8 @@ namespace Apache.Ignite.Core.Tests.Cache
                     WalStorePath = Path.Combine(_tempDir, "WalStore"),
                     WalArchivePath = Path.Combine(_tempDir, "WalArchive"),
                     MetricsEnabled = true
-                }
+                },
+                DataStorageConfiguration = null
             };
 
             const string cacheName = "persistentCache";
@@ -116,7 +117,8 @@ namespace Apache.Ignite.Core.Tests.Cache
         {
             var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration())
             {
-                PersistentStoreConfiguration = new PersistentStoreConfiguration()
+                PersistentStoreConfiguration = new PersistentStoreConfiguration(),
+                DataStorageConfiguration = null
             };
 
             // Default config, inactive by default (IsActiveOnStart is ignored when persistence is enabled).

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec38564a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/ComputeApiTestFullFooter.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/ComputeApiTestFullFooter.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/ComputeApiTestFullFooter.cs
index a0d54e4..cc86db7 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/ComputeApiTestFullFooter.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/ComputeApiTestFullFooter.cs
@@ -61,6 +61,8 @@ namespace Apache.Ignite.Core.Tests.Compute
 
             File.WriteAllText(path, text);
 
+            Assert.IsTrue(File.Exists(path));
+
             return path;
         }
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec38564a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ConsoleRedirectTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ConsoleRedirectTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ConsoleRedirectTest.cs
index 3ab5ed3..ed556b4 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ConsoleRedirectTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ConsoleRedirectTest.cs
@@ -52,10 +52,10 @@ namespace Apache.Ignite.Core.Tests
             _stdErr = Console.Error;
 
             _outSb = new StringBuilder();
-            Console.SetOut(new StringWriter(_outSb));
+            Console.SetOut(new MyStringWriter(_outSb));
 
             _errSb = new StringBuilder();
-            Console.SetError(new StringWriter(_errSb));
+            Console.SetError(new MyStringWriter(_errSb));
         }
 
         /// <summary>
@@ -64,8 +64,12 @@ namespace Apache.Ignite.Core.Tests
         [TearDown]
         public void TearDown()
         {
+            MyStringWriter.Throw = false;
+
             Console.SetOut(_stdOut);
             Console.SetError(_stdErr);
+
+            Ignition.StopAll(true);
         }
 
         /// <summary>
@@ -81,6 +85,18 @@ namespace Apache.Ignite.Core.Tests
         }
 
         /// <summary>
+        /// Tests the exception in console writer.
+        /// </summary>
+        [Test]
+        public void TestExceptionInWriterPropagatesToJavaAndBack()
+        {
+            MyStringWriter.Throw = true;
+
+            var ex = Assert.Throws<IgniteException>(() => Ignition.Start(TestUtils.GetTestConfiguration()));
+            Assert.AreEqual("foo", ex.Message);
+        }
+
+        /// <summary>
         /// Tests startup error in Java.
         /// </summary>
         [Test]
@@ -145,8 +161,11 @@ namespace Apache.Ignite.Core.Tests
                     LoaderOptimization = LoaderOptimization.MultiDomainHost
                 });
 
+                var type = typeof(IgniteRunner);
+                Assert.IsNotNull(type.FullName);
+
                 var runner = (IIgniteRunner)childDomain.CreateInstanceAndUnwrap(
-                    typeof(IgniteRunner).Assembly.FullName, typeof(IgniteRunner).FullName);
+                    type.Assembly.FullName, type.FullName);
 
                 runner.Run();
             }
@@ -174,5 +193,25 @@ namespace Apache.Ignite.Core.Tests
                 // Will be stopped automatically on domain unload.
             }
         }
+
+        private class MyStringWriter : StringWriter
+        {
+            public static bool Throw { get; set; }
+
+            public MyStringWriter(StringBuilder sb) : base(sb)
+            {
+                // No-op.
+            }
+
+            public override void Write(string value)
+            {
+                if (Throw)
+                {
+                    throw new Exception("foo");
+                }
+
+                base.Write(value);
+            }
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec38564a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/DeploymentTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/DeploymentTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/DeploymentTest.cs
index 1d80c60..eb329af 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/DeploymentTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/DeploymentTest.cs
@@ -32,6 +32,9 @@ namespace Apache.Ignite.Core.Tests
     /// </summary>
     public class DeploymentTest
     {
+        /** */
+        private string _tempFolder;
+
         /// <summary>
         /// Tests the custom deployment where IGNITE_HOME can't be resolved, and there is a user-defined classpath.
         /// </summary>
@@ -39,35 +42,12 @@ namespace Apache.Ignite.Core.Tests
         public void TestCustomDeployment()
         {
             // Create temp folder
-            var folder = IgniteUtils.GetTempDirectoryName();
-
-            // Copy jars
-            var home = IgniteHome.Resolve(null);
-
-            var jarNames = new[] {@"\ignite-core-", @"\cache-api-1.0.0.jar", @"\modules\spring\" };
-
-            var jars = Directory.GetFiles(home, "*.jar", SearchOption.AllDirectories)
-                .Where(jarPath => jarNames.Any(jarPath.Contains)).ToArray();
-
-            Assert.Greater(jars.Length, 3);
-
-            foreach (var jar in jars)
-            {
-                var fileName = Path.GetFileName(jar);
-                Assert.IsNotNull(fileName);
-                File.Copy(jar, Path.Combine(folder, fileName), true);
-            }
+            var folder = _tempFolder;
+            DeployTo(folder);
 
             // Build classpath
             var classpath = string.Join(";", Directory.GetFiles(folder).Select(Path.GetFileName));
 
-            // Copy .NET binaries
-            foreach (var asm in new[] {typeof(IgniteRunner).Assembly, typeof(Ignition).Assembly, GetType().Assembly})
-            {
-                Assert.IsNotNull(asm.Location);
-                File.Copy(asm.Location, Path.Combine(folder, Path.GetFileName(asm.Location)));
-            }
-
             // Copy config
             var springPath = Path.GetFullPath("config\\compute\\compute-grid2.xml");
             var springFile = Path.GetFileName(springPath);
@@ -88,38 +68,97 @@ namespace Apache.Ignite.Core.Tests
 
             Assert.IsNotNull(proc);
 
-            try
-            {
-                VerifyNodeStarted(exePath);
-            }
-            finally
+            VerifyNodeStarted(exePath);
+        }
+
+        /// <summary>
+        /// Tests missing JARs.
+        /// </summary>
+        [Test]
+        public void TestMissingJarsCauseProperException()
+        {
+            // Create temp folder
+            var folder = _tempFolder;
+            DeployTo(folder);
+
+            // Build classpath
+            var classpath = string.Join(";",
+                Directory.GetFiles(folder).Where(x => !x.Contains("ignite-core-")).Select(Path.GetFileName));
+
+            // Start a node and check the exception.
+            var exePath = Path.Combine(folder, "Apache.Ignite.exe");
+            var reader = new ListDataReader();
+
+            var proc = IgniteProcess.Start(exePath, string.Empty, args: new[]
             {
-                proc.Kill();
-
-                Assert.IsTrue(
-                    TestUtils.WaitForCondition(() =>
-                    {
-                        try
-                        {
-                            Directory.Delete(folder, true);
-                            return true;
-                        }
-                        catch (Exception)
-                        {
-                            return false;
-                        }
-                    }, 1000), "Failed to remove temp directory: " + folder);
-            }
+                "-jvmClasspath=" + classpath,
+                "-J-ea",
+                "-J-Xms512m",
+                "-J-Xmx512m"
+            }, outReader: reader);
+
+            // Wait for process to fail.
+            Assert.IsNotNull(proc);
+            Assert.IsTrue(proc.WaitForExit(10000));
+            Assert.IsTrue(proc.HasExited);
+            Assert.AreEqual(-1, proc.ExitCode);
+
+            // Check error message.
+            Assert.AreEqual("ERROR: Apache.Ignite.Core.Common.IgniteException: Java class is not found " +
+                            "(did you set IGNITE_HOME environment variable?): " +
+                            "org/apache/ignite/internal/processors/platform/PlatformIgnition",
+                reader.GetOutput().First());
         }
 
         /// <summary>
-        /// Fixture tear down.
+        /// Sets up the test.
         /// </summary>
-        [TestFixtureTearDown]
-        public void TestFixtureTearDown()
+        [SetUp]
+        public void SetUp()
+        {
+            _tempFolder = IgniteUtils.GetTempDirectoryName();
+        }
+
+        /// <summary>
+        /// Tears down the test.
+        /// </summary>
+        [TearDown]
+        public void TearDown()
         {
             Ignition.StopAll(true);
             IgniteProcess.KillAll();
+
+            Directory.Delete(_tempFolder, true);
+        }
+
+        /// <summary>
+        /// Deploys binaries to specified folder
+        /// </summary>
+        private void DeployTo(string folder)
+        {
+            // Copy jars.
+            var home = IgniteHome.Resolve(null);
+
+            var jarNames = new[] {@"\ignite-core-", @"\cache-api-1.0.0.jar", @"\modules\spring\"};
+
+            var jars = Directory.GetFiles(home, "*.jar", SearchOption.AllDirectories)
+                .Where(jarPath => jarNames.Any(jarPath.Contains)).ToArray();
+
+            Assert.Greater(jars.Length, 3);
+
+            foreach (var jar in jars)
+            {
+                var fileName = Path.GetFileName(jar);
+                Assert.IsNotNull(fileName);
+                File.Copy(jar, Path.Combine(folder, fileName), true);
+            }
+
+            // Copy .NET binaries
+            foreach (var asm in new[] {typeof(IgniteRunner).Assembly, typeof(Ignition).Assembly, GetType().Assembly})
+            {
+                Assert.IsNotNull(asm.Location);
+                File.Copy(asm.Location, Path.Combine(folder, Path.GetFileName(asm.Location)));
+            }
         }
 
         /// <summary>

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec38564a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ExecutableTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ExecutableTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ExecutableTest.cs
index 8f422f4..b885d28 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ExecutableTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ExecutableTest.cs
@@ -320,10 +320,7 @@ namespace Apache.Ignite.Core.Tests
                 Assert.IsTrue(proc.Join(30000, out exitCode));
                 Assert.AreEqual(-1, exitCode);
 
-                lock (reader.List)
-                {
-                    Assert.AreEqual(err, reader.List.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x)));
-                }
+                Assert.AreEqual(err, reader.GetOutput().FirstOrDefault(x => !string.IsNullOrWhiteSpace(x)));
             };
 
             checkError("blabla", "ERROR: Apache.Ignite.Core.Common.IgniteException: Missing argument value: " +
@@ -477,18 +474,5 @@ namespace Apache.Ignite.Core.Tests
             /// </summary>
             public int JvmMaxMemoryMb { get; set; }
         }
-
-        private class ListDataReader : IIgniteProcessOutputReader
-        {
-            public readonly List<string> List = new List<string>();
-
-            public void OnOutput(System.Diagnostics.Process proc, string data, bool err)
-            {
-                lock (List)
-                {
-                    List.Add(data);
-                }
-            }
-        }
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec38564a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationTest.cs
index f68371a..6e09704 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationTest.cs
@@ -249,6 +249,7 @@ namespace Apache.Ignite.Core.Tests
             // When Spring XML is used, .NET overrides Spring.
             var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration())
             {
+                DataStorageConfiguration = null,
                 SpringConfigUrl = @"config\spring-test.xml",
                 NetworkSendRetryDelay = TimeSpan.FromSeconds(45),
                 MetricsHistorySize = 57

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec38564a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteStartStopTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteStartStopTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteStartStopTest.cs
index 529128a..aa292ab 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteStartStopTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteStartStopTest.cs
@@ -229,7 +229,7 @@ namespace Apache.Ignite.Core.Tests
                 JvmClasspath = TestUtils.CreateTestClasspath()
             };
 
-            for (var i = 0; i < 20; i++)
+            for (var i = 0; i < 50; i++)
             {
                 Console.WriteLine("Iteration: " + i);
 
@@ -239,16 +239,12 @@ namespace Apache.Ignite.Core.Tests
 
                 if (i % 2 == 0) // Try to stop ignite from another thread.
                 {
-                    var t = new Thread(() => {
-                        grid.Dispose();
-                    });
-
-                    t.Start();
-
-                    t.Join();
+                    Task.Factory.StartNew(() => grid.Dispose()).Wait();
                 }
                 else
+                {
                     grid.Dispose();
+                }
 
                 GC.Collect(); // At the time of writing java references are cleaned from finalizer, so GC is needed.
             }

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec38564a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/MultiAppDomainTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/MultiAppDomainTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/MultiAppDomainTest.cs
new file mode 100644
index 0000000..0157255
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/MultiAppDomainTest.cs
@@ -0,0 +1,171 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Core.Tests
+{
+    using System;
+    using System.Collections.Generic;
+    using Apache.Ignite.Core.Cache.Configuration;
+    using NUnit.Framework;
+
+    /// <summary>
+    /// Tests Ignite behavior in multi-AppDomain scenario.
+    /// Such a scenario occurs within IIS, for example, or within application plugins.
+    /// </summary>
+    [Category(TestUtils.CategoryIntensive)]
+    public class MultiAppDomainTest
+    {
+        /** */
+        public const string CacheName = "cache";
+
+        /** */
+        private readonly List<AppDomain> _domains = new List<AppDomain>();
+
+        /// <summary>
+        /// Tears down the test.
+        /// </summary>
+        [TearDown]
+        public void TearDown()
+        {
+            Ignition.StopAll(true);
+
+            UnloadDomains();
+        }
+
+        /// <summary>
+        /// Tests the IIS behavior:
+        /// when application is restarted, new AppDomain is started while old one is still running.
+        /// </summary>
+        [Test]
+        public void TestIisBehavior()
+        {
+            var ignite = Ignition.Start(GetConfig());
+            
+            var cache = ignite.CreateCache<int, int>(new CacheConfiguration
+            {
+                Name =  CacheName,
+                CacheMode = CacheMode.Replicated  // Use Replicated to avoid data loss due to node stop.
+            });
+
+            cache[1] = 1;
+
+            // Check same domain.
+            new DomainRunner().RunTest();
+
+            var type = typeof(DomainRunner);
+            Assert.IsNotNull(type.FullName);
+
+            // Start and stop domains.
+            for (var i = 0; i < 10; i++)
+            {
+                var domain = CreateDomain(i);
+
+                var runner = (DomainRunner) domain.CreateInstanceAndUnwrap(type.Assembly.FullName, type.FullName);
+                runner.RunTest();
+
+                // Verify node start.
+                var expectedNodeCount = Math.Min(i + 3, 7);
+                Assert.AreEqual(expectedNodeCount, ignite.GetCluster().GetNodes().Count);
+
+                // Current AppDomain does not see other instances.
+                Assert.AreEqual(2, Ignition.GetAll().Count);
+
+                if (i > 3)
+                {
+                    var oldDomain = _domains[i - 3];
+                    _domains[i - 3] = null;
+
+                    AppDomain.Unload(oldDomain);
+
+                    // Verify node exit.
+                    TestUtils.WaitForCondition(
+                        () => ignite.GetCluster().GetNodes().Count == expectedNodeCount - 1, 5000);
+                }
+            }
+
+            UnloadDomains();
+
+            // Verify node exit: only two nodes from current domain should be there.
+            TestUtils.WaitForCondition(() => ignite.GetCluster().GetNodes().Count == 2, 5000);
+        }
+
+        /// <summary>
+        /// Creates the domain.
+        /// </summary>
+        private AppDomain CreateDomain(int i)
+        {
+            var domain = AppDomain.CreateDomain("TestIisBehavior-" + i, null, new AppDomainSetup
+            {
+                ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
+                ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile,
+                ApplicationName = AppDomain.CurrentDomain.SetupInformation.ApplicationName,
+                LoaderOptimization = LoaderOptimization.MultiDomainHost
+            });
+
+            _domains.Add(domain);
+
+            return domain;
+        }
+
+        /// <summary>
+        /// Unloads the domains.
+        /// </summary>
+        private void UnloadDomains()
+        {
+            foreach (var appDomain in _domains)
+            {
+                if (appDomain != null)
+                {
+                    AppDomain.Unload(appDomain);
+                }
+            }
+
+            _domains.Clear();
+        }
+
+        /// <summary>
+        /// Gets the configuration.
+        /// </summary>
+        private static IgniteConfiguration GetConfig()
+        {
+            return new IgniteConfiguration(TestUtils.GetTestConfiguration())
+            {
+                AutoGenerateIgniteInstanceName = true
+            };
+        }
+
+        /// <summary>
+        /// Class to instantiate in another domain.
+        /// </summary>
+        private class DomainRunner : MarshalByRefObject
+        {
+            /// <summary>
+            /// Runs the test.
+            /// </summary>
+            public void RunTest()
+            {
+                var cfg = GetConfig();
+
+                // No need to stop: this will happen on domain unload.
+                var ignite = Ignition.Start(cfg);
+                
+                var cache = ignite.GetCache<int, int>(CacheName);
+                Assert.AreEqual(1, cache[1]);
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec38564a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Process/ListDataReader.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Process/ListDataReader.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Process/ListDataReader.cs
new file mode 100644
index 0000000..e201c96
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Process/ListDataReader.cs
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Core.Tests.Process
+{
+    using System.Collections.Generic;
+    using System.Diagnostics;
+    using System.Linq;
+
+    /// <summary>
+    /// Reads process output into a list.
+    /// </summary>
+    public class ListDataReader : IIgniteProcessOutputReader
+    {
+        /** Target list. */
+        private readonly List<string> _list = new List<string>();
+
+        /** <inheritdoc /> */
+        public void OnOutput(Process proc, string data, bool err)
+        {
+            lock (_list)
+            {
+                _list.Add(data);
+            }
+        }
+
+        /// <summary>
+        /// Gets the output.
+        /// </summary>
+        public IList<string> GetOutput()
+        {
+            lock (_list)
+            {
+                return _list.ToList();
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec38564a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs
index 28e7ae8..03e8bf7 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs
@@ -26,6 +26,7 @@ namespace Apache.Ignite.Core.Tests
     using System.Linq;
     using System.Threading;
     using Apache.Ignite.Core.Cluster;
+    using Apache.Ignite.Core.Configuration;
     using Apache.Ignite.Core.Discovery.Tcp;
     using Apache.Ignite.Core.Discovery.Tcp.Static;
     using Apache.Ignite.Core.Impl;
@@ -63,8 +64,8 @@ namespace Apache.Ignite.Core.Tests
             : new List<string>
             {
                 "-XX:+HeapDumpOnOutOfMemoryError",
-                "-Xms512m",
-                "-Xmx512m",
+                "-Xms64m",
+                "-Xmx99m",
                 "-ea",
                 "-DIGNITE_ATOMIC_CACHE_DELETE_HISTORY_SIZE=1000",
                 "-DIGNITE_QUIET=true"
@@ -345,7 +346,18 @@ namespace Apache.Ignite.Core.Tests
                 Localhost = "127.0.0.1",
                 JvmOptions = TestJavaOptions(jvmDebug),
                 JvmClasspath = CreateTestClasspath(),
-                IgniteInstanceName = name
+                IgniteInstanceName = name,
+                DataStorageConfiguration = new DataStorageConfiguration
+                {
+                    DefaultDataRegionConfiguration = new DataRegionConfiguration
+                    {
+                        Name = DataStorageConfiguration.DefaultDataRegionName,
+                        InitialSize = 128 * 1024 * 1024,
+                        MaxSize = Environment.Is64BitProcess
+                            ? DataRegionConfiguration.DefaultMaxSize
+                            : 256 * 1024 * 1024
+                    }
+                }
             };
         }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec38564a/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj b/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
index 852c071..165a57e 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
@@ -69,7 +69,7 @@
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
     <DocumentationFile>bin\Debug\Apache.Ignite.Core.XML</DocumentationFile>
     <PlatformTarget>AnyCPU</PlatformTarget>
-    <RunCodeAnalysis>true</RunCodeAnalysis>
+    <RunCodeAnalysis>false</RunCodeAnalysis>
     <CodeAnalysisRuleSet>Apache.Ignite.Core.ruleset</CodeAnalysisRuleSet>
     <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
   </PropertyGroup>
@@ -82,6 +82,7 @@
     <CodeAnalysisRuleSet>Apache.Ignite.Core.ruleset</CodeAnalysisRuleSet>
     <DebugType>none</DebugType>
     <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
+    <RunCodeAnalysis>false</RunCodeAnalysis>
   </PropertyGroup>
   <ItemGroup>
     <Reference Include="System" />
@@ -132,8 +133,22 @@
     <Compile Include="Impl\IPlatformTargetInternal.cs" />
     <Compile Include="Impl\DataRegionMetrics.cs" />
     <Compile Include="Impl\PersistentStore\PersistentStoreMetrics.cs" />
+    <Compile Include="Impl\Unmanaged\Jni\AppDomains.cs" />
+    <Compile Include="Impl\Unmanaged\Jni\CallbackDelegates.cs" />
+    <Compile Include="Impl\Unmanaged\Jni\Callbacks.cs" />
+    <Compile Include="Impl\Unmanaged\Jni\ConsoleWriter.cs" />
+    <Compile Include="Impl\Unmanaged\Jni\EnvDelegates.cs" />
+    <Compile Include="Impl\Unmanaged\Jni\Env.cs" />
+    <Compile Include="Impl\Unmanaged\Jni\EnvInterface.cs" />
+    <Compile Include="Impl\Unmanaged\Jni\JvmInterface.cs" />
     <Compile Include="Impl\PlatformDisposableTargetAdapter.cs" />
     <Compile Include="Impl\PlatformJniTarget.cs" />
+    <Compile Include="Impl\Unmanaged\Jni\GlobalRef.cs" />
+    <Compile Include="Impl\Unmanaged\Jni\MethodId.cs" />
+    <Compile Include="Impl\Unmanaged\Jni\NativeMethod.cs" />
+    <Compile Include="Impl\Unmanaged\Jni\JniResult.cs" />
+    <Compile Include="Impl\Unmanaged\Jni\Jvm.cs" />
+    <Compile Include="Impl\Unmanaged\Jni\JvmDelegates.cs" />
     <Compile Include="PersistentStore\CheckpointWriteOrder.cs" />
     <Compile Include="PersistentStore\IPersistentStoreMetrics.cs" />
     <Compile Include="PersistentStore\Package-Info.cs" />
@@ -497,14 +512,8 @@
     <Compile Include="Impl\Transactions\TransactionImpl.cs" />
     <Compile Include="Impl\Transactions\TransactionMetricsImpl.cs" />
     <Compile Include="Impl\Transactions\TransactionsImpl.cs" />
-    <Compile Include="Impl\Unmanaged\IgniteJniNativeMethods.cs" />
-    <Compile Include="Impl\Unmanaged\IUnmanagedTarget.cs" />
-    <Compile Include="Impl\Unmanaged\UnmanagedCallbackHandlers.cs" />
     <Compile Include="Impl\Unmanaged\UnmanagedCallbackOp.cs" />
     <Compile Include="Impl\Unmanaged\UnmanagedCallbacks.cs" />
-    <Compile Include="Impl\Unmanaged\UnmanagedContext.cs" />
-    <Compile Include="Impl\Unmanaged\UnmanagedNonReleaseableTarget.cs" />
-    <Compile Include="Impl\Unmanaged\UnmanagedTarget.cs" />
     <Compile Include="Impl\Unmanaged\UnmanagedUtils.cs" />
     <Compile Include="Interop\IPlatformTarget.cs" />
     <Compile Include="Interop\JavaObject.cs" />
@@ -571,39 +580,10 @@
     <Compile Include="Transactions\TransactionState.cs" />
     <Compile Include="Transactions\TransactionTimeoutException.cs" />
   </ItemGroup>
-  <ItemGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
-    <EmbeddedResource Include="$(SolutionDir)\x64\Debug\ignite.jni.dll">
-      <Link>resources\debug\x64\ignite.jni.dll</Link>
-    </EmbeddedResource>
-  </ItemGroup>
-  <ItemGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
-    <EmbeddedResource Include="$(SolutionDir)\x64\Release\ignite.jni.dll">
-      <Link>resources\release\x64\ignite.jni.dll</Link>
-    </EmbeddedResource>
-  </ItemGroup>
-  <ItemGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
-    <EmbeddedResource Include="$(SolutionDir)\Win32\Debug\ignite.jni.dll">
-      <Link>resources\debug\x86\ignite.jni.dll</Link>
-    </EmbeddedResource>
-  </ItemGroup>
-  <ItemGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
-    <EmbeddedResource Include="$(SolutionDir)\Win32\Release\ignite.jni.dll">
-      <Link>resources\release\x86\ignite.jni.dll</Link>
-    </EmbeddedResource>
-  </ItemGroup>
-  <ItemGroup Condition="'$(Platform)' == 'AnyCPU'">
-    <EmbeddedResource Include="$(ProjectDir)..\..\cpp\jni\project\vs\x64\$(Configuration)\ignite.jni.dll">
-      <Link>resources\x64\ignite.jni.dll</Link>
-    </EmbeddedResource>
-    <EmbeddedResource Include="$(ProjectDir)..\..\cpp\jni\project\vs\Win32\$(Configuration)\ignite.jni.dll" Condition="'$(Configuration)' == 'Release' Or Exists('$(ProjectDir)..\..\cpp\jni\project\vs\Win32\$(Configuration)\ignite.jni.dll')">
-      <Link>resources\x86\ignite.jni.dll</Link>
-    </EmbeddedResource>
-  </ItemGroup>
   <ItemGroup>
     <None Include="Apache.Ignite.Core.ruleset" />
     <None Include="Apache.Ignite.Core.nuspec" />
     <None Include="Apache.Ignite.Core.Schema.nuspec" />
-    <None Include="build-common.ps1" />
     <None Include="NuGet\Uninstall.ps1" />
     <None Include="NuGet\PostBuild.ps1" />
     <None Include="NuGet\Install.ps1" />
@@ -614,11 +594,6 @@
     </None>
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
-  <PropertyGroup Condition="'$(Platform)' == 'AnyCPU'">
-    <PreBuildEvent>cd "$(ProjectDir)"
-	set COMPLUS_ApplicationMigrationRuntimeActivationConfigPath=$(ProjectDir)
-	PowerShell.exe -executionpolicy remotesigned -File build-common.ps1 -Configuration $(ConfigurationName) -msbuildexe "$(MSBuildBinPath)\msbuild.exe"</PreBuildEvent>
-  </PropertyGroup>
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
        Other similar extension points exist, see Microsoft.Common.targets.
   <Target Name="BeforeBuild">

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec38564a/modules/platforms/dotnet/Apache.Ignite.Core/Ignition.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Ignition.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Ignition.cs
index 4e5eae5..bc14fdd 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Ignition.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Ignition.cs
@@ -40,6 +40,7 @@ namespace Apache.Ignite.Core
     using Apache.Ignite.Core.Impl.Log;
     using Apache.Ignite.Core.Impl.Memory;
     using Apache.Ignite.Core.Impl.Unmanaged;
+    using Apache.Ignite.Core.Impl.Unmanaged.Jni;
     using Apache.Ignite.Core.Lifecycle;
     using Apache.Ignite.Core.Log;
     using Apache.Ignite.Core.Resource;
@@ -209,7 +210,7 @@ namespace Apache.Ignite.Core
         /// Starts Ignite with given configuration.
         /// </summary>
         /// <returns>Started Ignite.</returns>
-        public static unsafe IIgnite Start(IgniteConfiguration cfg)
+        public static IIgnite Start(IgniteConfiguration cfg)
         {
             IgniteArgumentCheck.NotNull(cfg, "cfg");
 
@@ -228,9 +229,8 @@ namespace Apache.Ignite.Core
                 // 2. Create context.
                 IgniteUtils.LoadDlls(cfg.JvmDllPath, log);
 
-                var cbs = new UnmanagedCallbacks(log);
-
-                IgniteManager.CreateJvmContext(cfg, cbs, log);
+                var cbs = IgniteManager.CreateJvmContext(cfg, log);
+                var env = cbs.Jvm.AttachCurrentThread();
                 log.Debug("JVM started.");
 
                 var gridName = cfg.IgniteInstanceName;
@@ -248,8 +248,7 @@ namespace Apache.Ignite.Core
                 try
                 {
                     // 4. Initiate Ignite start.
-                    UU.IgnitionStart(cbs.Context, cfg.SpringConfigUrl, gridName, ClientMode, cfg.Logger != null);
-
+                    UU.IgnitionStart(env, cfg.SpringConfigUrl, gridName, ClientMode, cfg.Logger != null, cbs.IgniteId);
 
                     // 5. At this point start routine is finished. We expect STARTUP object to have all necessary data.
                     var node = _startup.Ignite;
@@ -268,7 +267,7 @@ namespace Apache.Ignite.Core
 
                     return node;
                 }
-                catch (Exception)
+                catch (Exception ex)
                 {
                     // 1. Perform keys cleanup.
                     string name = _startup.Name;
@@ -283,7 +282,7 @@ namespace Apache.Ignite.Core
 
                     // 2. Stop Ignite node if it was started.
                     if (interopProc != null)
-                        UU.IgnitionStop(interopProc.Target.Context, gridName, true);
+                        UU.IgnitionStop(gridName, true);
 
                     // 3. Throw error further (use startup error if exists because it is more precise).
                     if (_startup.Error != null)
@@ -293,7 +292,14 @@ namespace Apache.Ignite.Core
                             _startup.Error);
                     }
 
-                    throw;
+                    var jex = ex as JavaException;
+
+                    if (jex == null)
+                    {
+                        throw;
+                    }
+
+                    throw ExceptionUtils.GetException(null, jex);
                 }
                 finally
                 {
@@ -456,7 +462,7 @@ namespace Apache.Ignite.Core
         /// <param name="stream">Stream.</param>
         [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope",
             Justification = "PlatformJniTarget is passed further")]
-        internal static void OnStart(IUnmanagedTarget interopProc, IBinaryStream stream)
+        internal static void OnStart(GlobalRef interopProc, IBinaryStream stream)
         {
             try
             {

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec38564a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/ExceptionUtils.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/ExceptionUtils.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/ExceptionUtils.cs
index b81d04b..0dab997 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/ExceptionUtils.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/ExceptionUtils.cs
@@ -126,10 +126,26 @@ namespace Apache.Ignite.Core.Impl
             BinaryReader reader = null, Exception innerException = null)
         {
             // Set JavaException as immediate inner.
-            innerException = new JavaException(clsName, msg, stackTrace, innerException);
+            var jex = new JavaException(clsName, msg, stackTrace, innerException);
 
+            return GetException(igniteInt, jex, reader);
+        }
+
+        /// <summary>
+        /// Creates exception according to native code class and message.
+        /// </summary>
+        /// <param name="igniteInt">The ignite.</param>
+        /// <param name="innerException">Java exception.</param>
+        /// <param name="reader">Error data reader.</param>
+        /// <returns>Exception.</returns>
+        public static Exception GetException(IIgniteInternal igniteInt, JavaException innerException,
+            BinaryReader reader = null)
+        {
             var ignite = igniteInt == null ? null : igniteInt.GetIgnite();
 
+            var msg = innerException.JavaMessage;
+            var clsName = innerException.JavaClassName;
+
             ExceptionFactory ctor;
 
             if (Exs.TryGetValue(clsName, out ctor))
@@ -157,7 +173,7 @@ namespace Apache.Ignite.Core.Impl
                     "variable?): " + msg, innerException);
 
             if (ClsCachePartialUpdateErr.Equals(clsName, StringComparison.OrdinalIgnoreCase))
-                return ProcessCachePartialUpdateException(igniteInt, msg, stackTrace, reader);
+                return ProcessCachePartialUpdateException(igniteInt, msg, innerException.Message, reader);
 
             // Predefined mapping not found - check plugins.
             if (igniteInt != null && igniteInt.PluginProcessor != null)

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec38564a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs
index 78b7c74..ae751a4 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs
@@ -378,7 +378,7 @@ namespace Apache.Ignite.Core.Impl
         /// Internal stop routine.
         /// </summary>
         /// <param name="cancel">Cancel flag.</param>
-        internal unsafe void Stop(bool cancel)
+        internal void Stop(bool cancel)
         {
             var jniTarget = _proc as PlatformJniTarget;
 
@@ -387,7 +387,7 @@ namespace Apache.Ignite.Core.Impl
                 throw new IgniteException("Ignition.Stop is not supported in thin client.");
             }
 
-            UU.IgnitionStop(jniTarget.Target.Context, Name, cancel);
+            UU.IgnitionStop(Name, cancel);
 
             _cbs.Cleanup();
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec38564a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteManager.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteManager.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteManager.cs
index ee54218..fd067b9 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteManager.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteManager.cs
@@ -22,18 +22,17 @@ namespace Apache.Ignite.Core.Impl
     using System.Diagnostics.CodeAnalysis;
     using System.Globalization;
     using System.Linq;
-    using System.Runtime.InteropServices;
     using System.Text;
     using Apache.Ignite.Core.Impl.Common;
     using Apache.Ignite.Core.Impl.Memory;
     using Apache.Ignite.Core.Impl.Unmanaged;
+    using Apache.Ignite.Core.Impl.Unmanaged.Jni;
     using Apache.Ignite.Core.Log;
-    using UU = Apache.Ignite.Core.Impl.Unmanaged.UnmanagedUtils;
 
     /// <summary>
     /// Native interface manager.
     /// </summary>
-    public static unsafe class IgniteManager
+    internal static class IgniteManager
     {
         /** Java Command line argument: Xms. Case sensitive. */
         private const string CmdJvmMinMemJava = "-Xms";
@@ -44,9 +43,6 @@ namespace Apache.Ignite.Core.Impl
         /** Monitor for DLL load synchronization. */
         private static readonly object SyncRoot = new object();
 
-        /** First created context. */
-        private static void* _ctx;
-
         /** Configuration used on JVM start. */
         private static JvmConfiguration _jvmCfg;
 
@@ -57,10 +53,9 @@ namespace Apache.Ignite.Core.Impl
         /// Create JVM.
         /// </summary>
         /// <param name="cfg">Configuration.</param>
-        /// <param name="cbs">Callbacks.</param>
-        /// <param name="log"></param>
-        /// <returns>Context.</returns>
-        internal static void CreateJvmContext(IgniteConfiguration cfg, UnmanagedCallbacks cbs, ILogger log)
+        /// <param name="log">Logger</param>
+        /// <returns>Callback context.</returns>
+        internal static UnmanagedCallbacks CreateJvmContext(IgniteConfiguration cfg, ILogger log)
         {
             lock (SyncRoot)
             {
@@ -79,16 +74,19 @@ namespace Apache.Ignite.Core.Impl
                 }
 
                 // 2. Create unmanaged pointer.
-                void* ctx = CreateJvm(cfg, cbs);
+                var jvm = CreateJvm(cfg);
+                jvm.EnableJavaConsoleWriter();
 
-                cbs.SetContext(ctx);
+                var cbs = new UnmanagedCallbacks(log, jvm);
+                jvm.RegisterCallbacks(cbs);
 
-                // 3. If this is the first JVM created, preserve it.
-                if (_ctx == null)
+                // 3. If this is the first JVM created, preserve configuration.
+                if (_jvmCfg == null)
                 {
-                    _ctx = ctx;
                     _jvmCfg = jvmCfg;
                 }
+
+                return cbs;
             }
         }
         
@@ -101,63 +99,18 @@ namespace Apache.Ignite.Core.Impl
         }
 
         /// <summary>
-        /// Blocks until JVM stops.
-        /// </summary>
-        public static void DestroyJvm()
-        {
-            lock (SyncRoot)
-            {
-                if (_ctx != null)
-                {
-                    UU.DestroyJvm(_ctx);
-
-                    _ctx = null;
-                }
-            }
-        }
-
-        /// <summary>
         /// Create JVM.
         /// </summary>
         /// <returns>JVM.</returns>
-        private static void* CreateJvm(IgniteConfiguration cfg, UnmanagedCallbacks cbs)
+        private static Jvm CreateJvm(IgniteConfiguration cfg)
         {
             var cp = Classpath.CreateClasspath(cfg);
 
             var jvmOpts = GetMergedJvmOptions(cfg);
-            
-            var opts = new sbyte*[1 + jvmOpts.Count];
 
-            int idx = 0;
-                
-            opts[idx++] = IgniteUtils.StringToUtf8Unmanaged(cp);
+            jvmOpts.Add(cp);
 
-            foreach (string cfgOpt in jvmOpts)
-                opts[idx++] = IgniteUtils.StringToUtf8Unmanaged(cfgOpt);
-
-            try
-            {
-                IntPtr mem = Marshal.AllocHGlobal(opts.Length * 8);
-
-                fixed (sbyte** opts0 = opts)
-                {
-                    PlatformMemoryUtils.CopyMemory(opts0, mem.ToPointer(), opts.Length * 8);
-                }
-
-                try
-                {
-                    return UU.CreateContext(mem.ToPointer(), opts.Length, cbs.CallbacksPointer);
-                }
-                finally
-                {
-                    Marshal.FreeHGlobal(mem);
-                }
-            }
-            finally
-            {
-                foreach (sbyte* opt in opts)
-                    Marshal.FreeHGlobal((IntPtr)opt);
-            }
+            return Jvm.GetOrCreate(jvmOpts);
         }
 
         /// <summary>

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec38564a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteUtils.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteUtils.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteUtils.cs
index e439208..38eda1b 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteUtils.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteUtils.cs
@@ -33,7 +33,6 @@ namespace Apache.Ignite.Core.Impl
     using Apache.Ignite.Core.Impl.Binary;
     using Apache.Ignite.Core.Impl.Cluster;
     using Apache.Ignite.Core.Impl.Common;
-    using Apache.Ignite.Core.Impl.Unmanaged;
     using Apache.Ignite.Core.Log;
     using Microsoft.Win32;
     using BinaryReader = Apache.Ignite.Core.Impl.Binary.BinaryReader;
@@ -69,9 +68,6 @@ namespace Apache.Ignite.Core.Impl
         /** File: jvm.dll. */
         internal const string FileJvmDll = "jvm.dll";
 
-        /** File: Ignite.Jni.dll. */
-        internal const string FileIgniteJniDll = "ignite.jni.dll";
-        
         /** Prefix for temp directory names. */
         private const string DirIgniteTmp = "Ignite_";
         
@@ -136,9 +132,6 @@ namespace Apache.Ignite.Core.Impl
             // 1. Load JNI dll.
             LoadJvmDll(configJvmDllPath, log);
 
-            // 2. Load GG JNI dll.
-            UnmanagedUtils.Initialize();
-
             _loaded = true;
         }
 
@@ -238,7 +231,7 @@ namespace Apache.Ignite.Core.Impl
         /// Formats the Win32 error.
         /// </summary>
         [ExcludeFromCodeCoverage]
-        public static string FormatWin32Error(int errorCode)
+        private static string FormatWin32Error(int errorCode)
         {
             if (errorCode == NativeMethods.ERROR_BAD_EXE_FORMAT)
             {
@@ -252,9 +245,7 @@ namespace Apache.Ignite.Core.Impl
             if (errorCode == NativeMethods.ERROR_MOD_NOT_FOUND)
             {
                 return "DLL could not be loaded (126: ERROR_MOD_NOT_FOUND). " +
-                       "This can be caused by missing dependencies. " +
-                       "Make sure that Microsoft Visual C++ 2010 Redistributable Package is installed " +
-                       "(https://www.microsoft.com/en-us/download/details.aspx?id=14632).";
+                       "This can be caused by missing dependencies. ";
             }
 
             return string.Format("{0}: {1}", errorCode, new Win32Exception(errorCode).Message);
@@ -340,75 +331,6 @@ namespace Apache.Ignite.Core.Impl
         }
 
         /// <summary>
-        /// Unpacks an embedded resource into a temporary folder and returns the full path of resulting file.
-        /// </summary>
-        /// <param name="resourceName">Resource name.</param>
-        /// <param name="fileName">Name of the resulting file.</param>
-        /// <returns>
-        /// Path to a temp file with an unpacked resource.
-        /// </returns>
-        public static string UnpackEmbeddedResource(string resourceName, string fileName)
-        {
-            var dllRes = Assembly.GetExecutingAssembly().GetManifestResourceNames()
-                .Single(x => x.EndsWith(resourceName, StringComparison.OrdinalIgnoreCase));
-
-            return WriteResourceToTempFile(dllRes, fileName);
-        }
-
-        /// <summary>
-        /// Writes the resource to temporary file.
-        /// </summary>
-        /// <param name="resource">The resource.</param>
-        /// <param name="name">File name prefix</param>
-        /// <returns>Path to the resulting temp file.</returns>
-        private static string WriteResourceToTempFile(string resource, string name)
-        {
-            // Dll file name should not be changed, so we create a temp folder with random name instead.
-            var file = Path.Combine(GetTempDirectoryName(), name);
-
-            using (var src = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource))
-            using (var dest = File.OpenWrite(file))
-            {
-                // ReSharper disable once PossibleNullReferenceException
-                src.CopyTo(dest);
-
-                return file;
-            }
-        }
-
-        /// <summary>
-        /// Tries to clean temporary directories created with <see cref="GetTempDirectoryName"/>.
-        /// </summary>
-        internal static void TryCleanTempDirectories()
-        {
-            var dt = DateTime.Now;
-
-            foreach (var dir in Directory.EnumerateDirectories(Path.GetTempPath(), DirIgniteTmp + "*"))
-            {
-                if ((dt - Directory.GetCreationTime(dir)).TotalMinutes < 1)
-                {
-                    // Do not clean up recently created temp directories:
-                    // they may be used by currently starting up nodes.
-                    // This is a workaround for multiple node startup problem, see IGNITE-5730.
-                    continue;
-                }
-
-                try
-                {
-                    Directory.Delete(dir, true);
-                }
-                catch (IOException)
-                {
-                    // Expected
-                }
-                catch (UnauthorizedAccessException)
-                {
-                    // Expected
-                }
-            }
-        }
-
-        /// <summary>
         /// Creates a uniquely named, empty temporary directory on disk and returns the full path of that directory.
         /// </summary>
         /// <returns>The full path of the temporary directory.</returns>

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec38564a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/PlatformJniTarget.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/PlatformJniTarget.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/PlatformJniTarget.cs
index c7d9ab4..c0fcea4 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/PlatformJniTarget.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/PlatformJniTarget.cs
@@ -25,11 +25,12 @@ namespace Apache.Ignite.Core.Impl
     using System.Threading;
     using System.Threading.Tasks;
     using Apache.Ignite.Core.Binary;
+    using Apache.Ignite.Core.Common;
     using Apache.Ignite.Core.Impl.Binary;
     using Apache.Ignite.Core.Impl.Binary.IO;
     using Apache.Ignite.Core.Impl.Common;
     using Apache.Ignite.Core.Impl.Memory;
-    using Apache.Ignite.Core.Impl.Unmanaged;
+    using Apache.Ignite.Core.Impl.Unmanaged.Jni;
     using Apache.Ignite.Core.Interop;
     using BinaryReader = Apache.Ignite.Core.Impl.Binary.BinaryReader;
     using BinaryWriter = Apache.Ignite.Core.Impl.Binary.BinaryWriter;
@@ -55,7 +56,7 @@ namespace Apache.Ignite.Core.Impl
             };
         
         /** Unmanaged target. */
-        private readonly IUnmanagedTarget _target;
+        private readonly GlobalRef _target;
 
         /** Marshaller. */
         private readonly Marshaller _marsh;
@@ -65,7 +66,7 @@ namespace Apache.Ignite.Core.Impl
         /// </summary>
         /// <param name="target">Target.</param>
         /// <param name="marsh">Marshaller.</param>
-        public PlatformJniTarget(IUnmanagedTarget target, Marshaller marsh)
+        public PlatformJniTarget(GlobalRef target, Marshaller marsh)
         {
             Debug.Assert(target != null);
             Debug.Assert(marsh != null);
@@ -77,7 +78,7 @@ namespace Apache.Ignite.Core.Impl
         /// <summary>
         /// Gets the target.
         /// </summary>
-        public IUnmanagedTarget Target
+        public GlobalRef Target
         {
             get { return _target; }
         }
@@ -88,43 +89,71 @@ namespace Apache.Ignite.Core.Impl
         /** <inheritdoc /> */
         public long InStreamOutLong(int type, Action<IBinaryStream> writeAction)
         {
-            using (var stream = IgniteManager.Memory.Allocate().GetStream())
+            try
             {
-                writeAction(stream);
+                using (var stream = IgniteManager.Memory.Allocate().GetStream())
+                {
+                    writeAction(stream);
 
-                return UU.TargetInStreamOutLong(_target, type, stream.SynchronizeOutput());
+                    return UU.TargetInStreamOutLong(_target, type, stream.SynchronizeOutput());
+                }
+            }
+            catch (JavaException jex)
+            {
+                throw ConvertException(jex);
             }
         }
 
         /** <inheritdoc /> */
         public IPlatformTargetInternal InStreamOutObject(int type, Action<IBinaryStream> writeAction)
         {
-            using (var stream = IgniteManager.Memory.Allocate().GetStream())
+            try
             {
-                writeAction(stream);
+                using (var stream = IgniteManager.Memory.Allocate().GetStream())
+                {
+                    writeAction(stream);
 
-                var target = UU.TargetInStreamOutObject(_target, type, stream.SynchronizeOutput());
+                    var target = UU.TargetInStreamOutObject(_target, type, stream.SynchronizeOutput());
 
-                return target == null ? null : new PlatformJniTarget(target, _marsh);
+                    return target == null ? null : new PlatformJniTarget(target, _marsh);
+                }
+            }
+            catch (JavaException jex)
+            {
+                throw ConvertException(jex);
             }
         }
 
         /** <inheritdoc /> */
         public IPlatformTargetInternal OutObjectInternal(int type)
         {
-            return GetPlatformTarget(UU.TargetOutObject(_target, type));
+            try
+            {
+                return GetPlatformTarget(UU.TargetOutObject(_target, type));
+            }
+            catch (JavaException jex)
+            {
+                throw ConvertException(jex);
+            }
         }
 
         /** <inheritdoc /> */
         public T OutStream<T>(int type, Func<IBinaryStream, T> readAction)
         {
-            using (var stream = IgniteManager.Memory.Allocate().GetStream())
+            try
             {
-                UU.TargetOutStream(_target, type, stream.MemoryPointer);
+                using (var stream = IgniteManager.Memory.Allocate().GetStream())
+                {
+                    UU.TargetOutStream(_target, type, stream.MemoryPointer);
 
-                stream.SynchronizeInput();
+                    stream.SynchronizeInput();
 
-                return readAction(stream);
+                    return readAction(stream);
+                }
+            }
+            catch (JavaException jex)
+            {
+                throw ConvertException(jex);
             }
         }
 
@@ -132,16 +161,23 @@ namespace Apache.Ignite.Core.Impl
         public TR InStreamOutStream<TR>(int type, Action<IBinaryStream> writeAction, 
             Func<IBinaryStream, TR> readAction)
         {
-            using (var outStream = IgniteManager.Memory.Allocate().GetStream())
-            using (var inStream = IgniteManager.Memory.Allocate().GetStream())
+            try
             {
-                writeAction(outStream);
+                using (var outStream = IgniteManager.Memory.Allocate().GetStream())
+                using (var inStream = IgniteManager.Memory.Allocate().GetStream())
+                {
+                    writeAction(outStream);
 
-                UU.TargetInStreamOutStream(_target, type, outStream.SynchronizeOutput(), inStream.MemoryPointer);
+                    UU.TargetInStreamOutStream(_target, type, outStream.SynchronizeOutput(), inStream.MemoryPointer);
 
-                inStream.SynchronizeInput();
+                    inStream.SynchronizeInput();
 
-                return readAction(inStream);
+                    return readAction(inStream);
+                }
+            }
+            catch (JavaException jex)
+            {
+                throw ConvertException(jex);
             }
         }
 
@@ -149,33 +185,40 @@ namespace Apache.Ignite.Core.Impl
         public TR InStreamOutLong<TR>(int type, Action<IBinaryStream> outAction, Func<IBinaryStream, long, TR> inAction, 
             Func<IBinaryStream, Exception> readErrorAction)
         {
-            Debug.Assert(readErrorAction != null);
-
-            using (var stream = IgniteManager.Memory.Allocate().GetStream())
+            try
             {
-                outAction(stream);
+                Debug.Assert(readErrorAction != null);
 
-                var res = UU.TargetInStreamOutLong(_target, type, stream.SynchronizeOutput());
+                using (var stream = IgniteManager.Memory.Allocate().GetStream())
+                {
+                    outAction(stream);
 
-                if (res != PlatformTargetAdapter.Error && inAction == null)
-                    return default(TR);  // quick path for void operations
+                    var res = UU.TargetInStreamOutLong(_target, type, stream.SynchronizeOutput());
 
-                stream.SynchronizeInput();
+                    if (res != PlatformTargetAdapter.Error && inAction == null)
+                        return default(TR);  // quick path for void operations
 
-                stream.Seek(0, SeekOrigin.Begin);
+                    stream.SynchronizeInput();
 
-                if (res != PlatformTargetAdapter.Error)
-                {
-                    return inAction != null ? inAction(stream, res) : default(TR);
-                }
+                    stream.Seek(0, SeekOrigin.Begin);
 
-                throw readErrorAction(stream);
+                    if (res != PlatformTargetAdapter.Error)
+                    {
+                        return inAction != null ? inAction(stream, res) : default(TR);
+                    }
+
+                    throw readErrorAction(stream);
+                }
+            }
+            catch (JavaException jex)
+            {
+                throw ConvertException(jex);
             }
         }
 
         /** <inheritdoc /> */
         [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
-        public unsafe TR InObjectStreamOutObjectStream<TR>(int type, Action<IBinaryStream> writeAction, 
+        public TR InObjectStreamOutObjectStream<TR>(int type, Action<IBinaryStream> writeAction, 
             Func<IBinaryStream, IPlatformTargetInternal, TR> readAction, IPlatformTargetInternal arg)
         {
             PlatformMemoryStream outStream = null;
@@ -199,8 +242,8 @@ namespace Apache.Ignite.Core.Impl
                     inPtr = inStream.MemoryPointer;
                 }
 
-                var res = UU.TargetInObjectStreamOutObjectStream(_target, type, 
-                    ((PlatformJniTarget)arg).Target.Target, outPtr, inPtr);
+                var res = UU.TargetInObjectStreamOutObjectStream(_target, type,
+                    ((PlatformJniTarget) arg).Target, outPtr, inPtr);
 
                 if (readAction == null)
                     return default(TR);
@@ -212,6 +255,10 @@ namespace Apache.Ignite.Core.Impl
                 return readAction(inStream, target);
 
             }
+            catch (JavaException jex)
+            {
+                throw ConvertException(jex);
+            }
             finally
             {
                 try
@@ -246,7 +293,7 @@ namespace Apache.Ignite.Core.Impl
         /// <param name="convertFunc">The function to read future result from stream.</param>
         /// <returns>Created future.</returns>
         [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
-        private Future<T> GetFuture<T>(Func<long, int, IUnmanagedTarget> listenAction, bool keepBinary = false,
+        private Future<T> GetFuture<T>(Func<long, int, GlobalRef> listenAction, bool keepBinary = false,
             Func<BinaryReader, T> convertFunc = null)
         {
             var futType = FutureType.Object;
@@ -262,7 +309,7 @@ namespace Apache.Ignite.Core.Impl
 
             var futHnd = _marsh.Ignite.HandleRegistry.Allocate(fut);
 
-            IUnmanagedTarget futTarget;
+            GlobalRef futTarget;
 
             try
             {
@@ -323,22 +370,36 @@ namespace Apache.Ignite.Core.Impl
         /** <inheritdoc /> */
         public long InLongOutLong(int type, long val)
         {
-            return UU.TargetInLongOutLong(_target, type, val);
+            try
+            {
+                return UU.TargetInLongOutLong(_target, type, val);
+            }
+            catch (JavaException jex)
+            {
+                throw ConvertException(jex);
+            }
         }
 
         /** <inheritdoc /> */
         [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods")]
         public long InStreamOutLong(int type, Action<IBinaryRawWriter> writeAction)
         {
-            using (var stream = IgniteManager.Memory.Allocate().GetStream())
+            try
             {
-                var writer = _marsh.StartMarshal(stream);
+                using (var stream = IgniteManager.Memory.Allocate().GetStream())
+                {
+                    var writer = _marsh.StartMarshal(stream);
 
-                writeAction(writer);
+                    writeAction(writer);
 
-                FinishMarshal(writer);
+                    FinishMarshal(writer);
 
-                return UU.TargetInStreamOutLong(_target, type, stream.SynchronizeOutput());
+                    return UU.TargetInStreamOutLong(_target, type, stream.SynchronizeOutput());
+                }
+            }
+            catch (JavaException jex)
+            {
+                throw ConvertException(jex);
             }
         }
 
@@ -347,20 +408,27 @@ namespace Apache.Ignite.Core.Impl
         public T InStreamOutStream<T>(int type, Action<IBinaryRawWriter> writeAction, 
             Func<IBinaryRawReader, T> readAction)
         {
-            using (var outStream = IgniteManager.Memory.Allocate().GetStream())
-            using (var inStream = IgniteManager.Memory.Allocate().GetStream())
+            try
             {
-                var writer = _marsh.StartMarshal(outStream);
+                using (var outStream = IgniteManager.Memory.Allocate().GetStream())
+                using (var inStream = IgniteManager.Memory.Allocate().GetStream())
+                {
+                    var writer = _marsh.StartMarshal(outStream);
 
-                writeAction(writer);
+                    writeAction(writer);
 
-                FinishMarshal(writer);
+                    FinishMarshal(writer);
 
-                UU.TargetInStreamOutStream(_target, type, outStream.SynchronizeOutput(), inStream.MemoryPointer);
+                    UU.TargetInStreamOutStream(_target, type, outStream.SynchronizeOutput(), inStream.MemoryPointer);
 
-                inStream.SynchronizeInput();
+                    inStream.SynchronizeInput();
 
-                return readAction(_marsh.StartUnmarshal(inStream));
+                    return readAction(_marsh.StartUnmarshal(inStream));
+                }
+            }
+            catch (JavaException jex)
+            {
+                throw ConvertException(jex);
             }
         }
 
@@ -368,20 +436,27 @@ namespace Apache.Ignite.Core.Impl
         [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods")]
         public IPlatformTarget InStreamOutObject(int type, Action<IBinaryRawWriter> writeAction)
         {
-            using (var stream = IgniteManager.Memory.Allocate().GetStream())
+            try
             {
-                var writer = _marsh.StartMarshal(stream);
+                using (var stream = IgniteManager.Memory.Allocate().GetStream())
+                {
+                    var writer = _marsh.StartMarshal(stream);
 
-                writeAction(writer);
+                    writeAction(writer);
 
-                FinishMarshal(writer);
+                    FinishMarshal(writer);
 
-                return GetPlatformTarget(UU.TargetInStreamOutObject(_target, type, stream.SynchronizeOutput()));
+                    return GetPlatformTarget(UU.TargetInStreamOutObject(_target, type, stream.SynchronizeOutput()));
+                }
+            }
+            catch (JavaException jex)
+            {
+                throw ConvertException(jex);
             }
         }
 
         /** <inheritdoc /> */
-        public unsafe T InObjectStreamOutObjectStream<T>(int type, IPlatformTarget arg, 
+        public T InObjectStreamOutObjectStream<T>(int type, IPlatformTarget arg, 
             Action<IBinaryRawWriter> writeAction, Func<IBinaryRawReader, IPlatformTarget, T> readAction)
         {
             PlatformMemoryStream outStream = null;
@@ -417,6 +492,10 @@ namespace Apache.Ignite.Core.Impl
                 return readAction(_marsh.StartUnmarshal(inStream), GetPlatformTarget(res));
 
             }
+            catch (JavaException jex)
+            {
+                throw ConvertException(jex);
+            }
             finally
             {
                 try
@@ -437,13 +516,20 @@ namespace Apache.Ignite.Core.Impl
         [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods")]
         public T OutStream<T>(int type, Func<IBinaryRawReader, T> readAction)
         {
-            using (var stream = IgniteManager.Memory.Allocate().GetStream())
+            try
             {
-                UU.TargetOutStream(_target, type, stream.MemoryPointer);
+                using (var stream = IgniteManager.Memory.Allocate().GetStream())
+                {
+                    UU.TargetOutStream(_target, type, stream.MemoryPointer);
 
-                stream.SynchronizeInput();
+                    stream.SynchronizeInput();
 
-                return readAction(_marsh.StartUnmarshal(stream));
+                    return readAction(_marsh.StartUnmarshal(stream));
+                }
+            }
+            catch (JavaException jex)
+            {
+                throw ConvertException(jex);
             }
         }
 
@@ -476,7 +562,14 @@ namespace Apache.Ignite.Core.Impl
                         FinishMarshal(writer);
                     }
 
-                    UU.TargetInStreamAsync(_target, type, stream.SynchronizeOutput());
+                    try
+                    {
+                        UU.TargetInStreamAsync(_target, type, stream.SynchronizeOutput());
+                    }
+                    catch (JavaException jex)
+                    {
+                        throw ConvertException(jex);
+                    }
                 }
             }, false, convertFunc).Task;
         }
@@ -505,7 +598,14 @@ namespace Apache.Ignite.Core.Impl
                         FinishMarshal(writer);
                     }
 
-                    return UU.TargetInStreamOutObjectAsync(_target, type, stream.SynchronizeOutput());
+                    try
+                    {
+                        return UU.TargetInStreamOutObjectAsync(_target, type, stream.SynchronizeOutput());
+                    }
+                    catch (JavaException jex)
+                    {
+                        throw ConvertException(jex);
+                    }
                 }
             }, false, convertFunc).GetTask(cancellationToken);
         }
@@ -513,7 +613,7 @@ namespace Apache.Ignite.Core.Impl
         /// <summary>
         /// Gets the platform target.
         /// </summary>
-        private IPlatformTargetInternal GetPlatformTarget(IUnmanagedTarget target)
+        private IPlatformTargetInternal GetPlatformTarget(GlobalRef target)
         {
             return target == null ? null : new PlatformJniTarget(target, _marsh);
         }
@@ -521,9 +621,17 @@ namespace Apache.Ignite.Core.Impl
         /// <summary>
         /// Gets the target pointer.
         /// </summary>
-        private static unsafe void* GetTargetPtr(IPlatformTarget target)
+        private static GlobalRef GetTargetPtr(IPlatformTarget target)
+        {
+            return target == null ? null : ((PlatformJniTarget) target)._target;
+        }
+
+        /// <summary>
+        /// Converts the exception.
+        /// </summary>
+        private Exception ConvertException(JavaException jex)
         {
-            return target == null ? null : ((PlatformJniTarget) target)._target.Target;
+            return ExceptionUtils.GetException(_marsh.Ignite, jex);
         }
 
         #endregion

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec38564a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/IUnmanagedTarget.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/IUnmanagedTarget.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/IUnmanagedTarget.cs
deleted file mode 100644
index 235f20d..0000000
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/IUnmanagedTarget.cs
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-namespace Apache.Ignite.Core.Impl.Unmanaged
-{
-    using System;
-
-    /// <summary>
-    /// Unmanaged target.
-    /// </summary>
-    internal unsafe interface IUnmanagedTarget : IDisposable
-    {
-        /// <summary>
-        /// Context.
-        /// </summary>
-        void* Context { get; }
-
-        /// <summary>
-        /// Target.
-        /// </summary>
-        void* Target { get; }
-
-        /// <summary>
-        /// Creates new instance with same context and different target.
-        /// </summary>
-        IUnmanagedTarget ChangeTarget(void* target);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec38564a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/IgniteJniNativeMethods.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/IgniteJniNativeMethods.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/IgniteJniNativeMethods.cs
deleted file mode 100644
index f96157c..0000000
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/IgniteJniNativeMethods.cs
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-namespace Apache.Ignite.Core.Impl.Unmanaged
-{
-    using System.Runtime.InteropServices;
-    using System.Security;
-
-    /// <summary>
-    /// Ignite JNI native methods.
-    /// </summary>
-    [SuppressUnmanagedCodeSecurity]
-    internal static unsafe class IgniteJniNativeMethods
-    {
-        [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteReallocate")]
-        public static extern int Reallocate(long memPtr, int cap);
-
-        [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteIgnitionStart")]
-        public static extern void IgnitionStart(void* ctx, sbyte* cfgPath, sbyte* gridName, int factoryId, 
-            long dataPtr);
-
-        [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteIgnitionStop")]
-        [return: MarshalAs(UnmanagedType.U1)]
-        public static extern bool IgnitionStop(void* ctx, sbyte* gridName, [MarshalAs(UnmanagedType.U1)] bool cancel);
-
-        [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteTargetInLongOutLong")]
-        public static extern long TargetInLongOutLong(void* ctx, void* target, int opType, long val);
-
-        [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteTargetInStreamOutLong")]
-        public static extern long TargetInStreamOutLong(void* ctx, void* target, int opType, long memPtr);
-
-        [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteTargetInStreamOutStream")]
-        public static extern void TargetInStreamOutStream(void* ctx, void* target, int opType, long inMemPtr,
-            long outMemPtr);
-
-        [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteTargetInStreamOutObject")]
-        public static extern void* TargetInStreamOutObject(void* ctx, void* target, int opType, long memPtr);
-
-        [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteTargetInObjectStreamOutObjectStream")]
-        public static extern void* TargetInObjectStreamOutObjectStream(void* ctx, void* target, int opType,
-            void* arg, long inMemPtr, long outMemPtr);
-
-        [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteTargetOutStream")]
-        public static extern void TargetOutStream(void* ctx, void* target, int opType, long memPtr);
-
-        [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteTargetOutObject")]
-        public static extern void* TargetOutObject(void* ctx, void* target, int opType);
-
-        [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteTargetInStreamAsync")]
-        public static extern void TargetInStreamAsync(void* ctx, void* target, int opType, long memPtr);
-
-        [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteTargetInStreamOutObjectAsync")]
-        public static extern void* TargetInStreamOutObjectAsync(void* ctx, void* target, int opType, long memPtr);
-
-        [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteAcquire")]
-        public static extern void* Acquire(void* ctx, void* target);
-
-        [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteRelease")]
-        public static extern void Release(void* target);
-
-        [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteThrowToJava")]
-        public static extern void ThrowToJava(void* ctx, char* msg);
-
-        [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteHandlersSize")]
-        public static extern int HandlersSize();
-
-        [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteCreateContext")]
-        public static extern void* CreateContext(void* opts, int optsLen, void* cbs);
-
-        [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteDeleteContext")]
-        public static extern void DeleteContext(void* ptr);
-
-        [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteDestroyJvm")]
-        public static extern void DestroyJvm(void* ctx);
-
-        [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteSetConsoleHandler")]
-        public static extern void SetConsoleHandler(void* consoleHandler);
-
-        [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteRemoveConsoleHandler")]
-        public static extern int RemoveConsoleHandler(void* consoleHandler);
-    }
-}
\ No newline at end of file