Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DLL Not Found Exception #252

Closed
eduardobellotto opened this issue May 25, 2019 · 15 comments
Closed

DLL Not Found Exception #252

eduardobellotto opened this issue May 25, 2019 · 15 comments

Comments

@eduardobellotto
Copy link

Hi.

I've created a new project in Windows 10 VS 2019 targeting .NET Framework 4.6.2.

Then, I've installed the Tensorflow.NET Nuget Package version 0.8.0.

In Program class, I've inserted using Tensorflow;.

In Main method, I've inserted the code var a = tf.constant(3);.

When I run the code, I receive the exception: DllNotFoundException: Unable to load DLL 'tensorflow': The specified module could not be found..

I've found the closed issue #144 (Cannot load Tensorflow DLL error), but I was not able to solve the problem after reading it.

There is a TensorFlow.NET.dll file in ..\bin\Debug folder, but there is no TensorFlow.dll file in that folder.

I've found a TensorFlow.dll file in ..\packages\TensorFlow.NET.0.8.0\tensorflowlib\runtimes\win-x64 folder.

I've tried to copy this file to the ..\bin\Debug folder, but the error persisted.

I've tried the same with VS 2017 and received the same exception.

Could you help me?

Thanks in advance.

@Oceania2018
Copy link
Member

@eduardobellotto Try to install another redist provided by Microsoft https://www.nuget.org/packages/Microsoft.ML.TensorFlow.Redist

PM> Install-Package Microsoft.ML.TensorFlow.Redist

@eduardobellotto
Copy link
Author

eduardobellotto commented May 25, 2019

Hi @Oceania2018

I've installed the Microsoft.ML.TensorFlow.Redist version 0.12.0, but I still have the same exception.

@kerryjiang
Copy link
Member

kerryjiang commented May 25, 2019

Hello @eduardobellotto, just make sure the package reference is there and do a full build:

<PackageReference Include="Microsoft.ML.TensorFlow.Redist" Version="0.12.0" />

@kerryjiang
Copy link
Member

@Oceania2018 it seems this problem always be an obstacle for the beginners of TF.NET. I forgot this issue many times as well.

@eduardobellotto
Copy link
Author

eduardobellotto commented May 25, 2019

Hi @kerryjiang.

I've migrate the Package.config format to the PackageReference format and the reference is OK:

  <ItemGroup>
    <PackageReference Include="Microsoft.ML.TensorFlow.Redist">
      <Version>0.12.0</Version>
    </PackageReference>
    <PackageReference Include="TensorFlow.NET">
      <Version>0.8.0</Version>
    </PackageReference>
  </ItemGroup>

I also created a brand new project with the default package management PackageReference format.

The project was created with the same right reference above.

But the exception continues in both cases.

Thanks again.

@Oceania2018
Copy link
Member

@eduardobellotto .NET 4.7.2 is the first version of the full .NET Framework that is fully .NET Standard 2.0 compliant without any additional dependencies. Can you try to upgrade your .NET Framework first?

@eduardobellotto
Copy link
Author

Hi @Oceania2018.

I've created a new project targeting .NET Framework 4.7.2 with the Nugets Microsoft.ML.TensorFlow.Redist and TensorFlow.NET correctly installed, but the same exception occurred.

Thanks once more.

@Oceania2018
Copy link
Member

@eduardobellotto This is what my files look like:

image

@tradexdev
Copy link

@eduardobellotto This is what my files look like:

image

Hi

I copy the "tensorflow.dll" file to Debug folder to test. I worked in that case. It is not the solution, but a small hack lets say. Problem is why it is not found originally.

image

@eduardobellotto
Copy link
Author

eduardobellotto commented May 26, 2019

Hi @Oceania2018 and @tradexdev.

I've discovered that this copy and paste solution works just for a .NET Core project.

I have a .NET Framework 4.6.2 project that has some dependencies to this framework and I would like to use TensorFlow in that project.

I've tried to create a solution with two different projects: a .NET Framework 4.6.2 and a .NET Core 2.0 project, but the Visual Studio does not permit us to reference the two projects directly.

I've found a workaround way to create that dependency in this link: https://www.youtube.com/watch?v=qc2WFaMfdp8&t=485s and I've followed this example.

It is interesting that TensorFlow works then we call the method from the own .NET Core application, but throws the exception when we try to call the same method of the same .NET Core app class from the .NET Framework application.

I have already tried to create an intermediate .NET Standard library project, referenced by the other two projects, but it has trown the same exception.

I'd like to ask you a favor.

Could you create a project from scratch, with .NET Framework 4.6.2 and the Nuget packages cited above and see if it works on your computers?

I would like to know if the problem with the .NET Framework would also occur on your computer, so if it is a problem with the .NET Framework.

Thank you very much for the help!

@Oceania2018
Copy link
Member

@eduardobellotto Just make sure you're running x64 platform.

image

image

image

@eduardobellotto
Copy link
Author

Bingo!

Its working now!

For those who are facing the same difficulty, just follow these steps:

  1. In the top menu, click on the Any CPU dropdown and select the option Configuration Manager:

image

  1. Under the Active solution platform label, select the option <New...>:

image

  1. In the pop up window, just click on the OK button:

image

  1. The option x64 will be selected in the top menu:

image

  1. Install both NuGet Packages cited above:

image

As Haiping has shown above, the application is working fine:

image

Thank you very much @Oceania2018, @kerryjiang and @tradexdev, for the great help!

@eformx
Copy link

eformx commented Aug 31, 2019

That almost worked for me. Added using static Tensorflow.Binding; and then it worked.

@ntpthinh
Copy link

ntpthinh commented May 26, 2020

In my cases, everything works fine when running on my computer, but the exception raises when I bring the Debug folder to other computers. Does it happen because of lacking environment? If yes, please help me out some possible fixes.

At first, the message is 'Unable to load DLL 'tensorflow''. Then after I installed C++ Redistributed in the client's computer, the message changed to "Unable to load DLL 'tensorflow': A dynamic link library (DLL) initialization failed. I did build in x64.

@NarwhalRoger
Copy link

I had same issues but every time I solved one with advices from this thread, I was getting other errors which went deeper and deeper into the system until it had already nothing to do with TensorFlow anymore. What helped me is to create completely new project ad install a bit older versions of NuGet packages (I used Microsoft.ML 1.6, Microsoft.ML.ImageAnalytics 1.6, Microsoft.ML.Visions 1.6 and SciSharp.TensorFlow.Redist 2.3.1.

These are versions of packages which VS 2022 ML Model Builder uses, and there everything works ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants