From 9f8f3d87d005963bc057fec16b5f02955c492dfe Mon Sep 17 00:00:00 2001 From: Yaohui Liu Date: Tue, 16 May 2023 03:22:16 +0800 Subject: [PATCH] fix: error caused by dll check in c_api. --- src/TensorFlowNET.Core/APIs/c_api.cs | 15 --------------- src/TensorFlowNET.Core/tensorflow.cs | 12 ++++++++++++ .../TensorFlowNET.Graph.UnitTest.csproj | 1 + .../Tensorflow.Keras.UnitTest.csproj | 1 + .../Tensorflow.Native.UnitTest.csproj | 1 + .../Tensorflow.Hub.Unittest.csproj | 1 + 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/TensorFlowNET.Core/APIs/c_api.cs b/src/TensorFlowNET.Core/APIs/c_api.cs index 587470e3..10f678e0 100644 --- a/src/TensorFlowNET.Core/APIs/c_api.cs +++ b/src/TensorFlowNET.Core/APIs/c_api.cs @@ -45,21 +45,6 @@ namespace Tensorflow { public const string TensorFlowLibName = "tensorflow"; - static c_api() - { - try - { - var handle = TF_Version(); - } - catch (DllNotFoundException) - { - throw new RuntimeError("Tensorflow.NET cannot find a backend. Please install one of the following packages for your program: " + - "SciSharp.TensorFlow.Redist, SciSharp.TensorFlow.Redist-Linux-GPU, SciSharp.TensorFlow.Redist-Windows-GPU. For more details, " + - "please visit https://github.com/SciSharp/TensorFlow.NET. If it still not work after installing the backend, please submit an " + - "issue to https://github.com/SciSharp/TensorFlow.NET/issues"); - } - } - public static string StringPiece(IntPtr handle) { return handle == IntPtr.Zero ? String.Empty : Marshal.PtrToStringAnsi(handle); diff --git a/src/TensorFlowNET.Core/tensorflow.cs b/src/TensorFlowNET.Core/tensorflow.cs index 67530ddb..dc4e48da 100644 --- a/src/TensorFlowNET.Core/tensorflow.cs +++ b/src/TensorFlowNET.Core/tensorflow.cs @@ -86,6 +86,18 @@ namespace Tensorflow OpDefLib = new OpDefLibrary(); InitGradientEnvironment(); + + try + { + var handle = c_api.TF_Version(); + } + catch (DllNotFoundException) + { + throw new RuntimeError("Tensorflow.NET cannot find a backend. Please install one of the following packages for your program: " + + "SciSharp.TensorFlow.Redist, SciSharp.TensorFlow.Redist-Linux-GPU, SciSharp.TensorFlow.Redist-Windows-GPU. For more details, " + + "please visit https://github.com/SciSharp/TensorFlow.NET. If it still not work after installing the backend, please submit an " + + "issue to https://github.com/SciSharp/TensorFlow.NET/issues"); + } } public string VERSION => c_api.StringPiece(c_api.TF_Version()); diff --git a/test/TensorFlowNET.Graph.UnitTest/TensorFlowNET.Graph.UnitTest.csproj b/test/TensorFlowNET.Graph.UnitTest/TensorFlowNET.Graph.UnitTest.csproj index 52adf24c..c353832a 100644 --- a/test/TensorFlowNET.Graph.UnitTest/TensorFlowNET.Graph.UnitTest.csproj +++ b/test/TensorFlowNET.Graph.UnitTest/TensorFlowNET.Graph.UnitTest.csproj @@ -35,6 +35,7 @@ + diff --git a/test/TensorFlowNET.Keras.UnitTest/Tensorflow.Keras.UnitTest.csproj b/test/TensorFlowNET.Keras.UnitTest/Tensorflow.Keras.UnitTest.csproj index 71684918..d744c336 100644 --- a/test/TensorFlowNET.Keras.UnitTest/Tensorflow.Keras.UnitTest.csproj +++ b/test/TensorFlowNET.Keras.UnitTest/Tensorflow.Keras.UnitTest.csproj @@ -24,6 +24,7 @@ + diff --git a/test/TensorFlowNET.Native.UnitTest/Tensorflow.Native.UnitTest.csproj b/test/TensorFlowNET.Native.UnitTest/Tensorflow.Native.UnitTest.csproj index 05d1e56f..9fec0e6d 100644 --- a/test/TensorFlowNET.Native.UnitTest/Tensorflow.Native.UnitTest.csproj +++ b/test/TensorFlowNET.Native.UnitTest/Tensorflow.Native.UnitTest.csproj @@ -55,6 +55,7 @@ + diff --git a/test/TensorflowNET.Hub.Unittest/Tensorflow.Hub.Unittest.csproj b/test/TensorflowNET.Hub.Unittest/Tensorflow.Hub.Unittest.csproj index f52ed1e1..4c3918e4 100644 --- a/test/TensorflowNET.Hub.Unittest/Tensorflow.Hub.Unittest.csproj +++ b/test/TensorflowNET.Hub.Unittest/Tensorflow.Hub.Unittest.csproj @@ -17,6 +17,7 @@ +