Machinelearning: Unable to load DLL 'CpuMathNative'

Created on 21 Feb 2020  路  24Comments  路  Source: dotnet/machinelearning

System information

  • Windows 10
  • **.NET Framework 4.7.2

Issue

Unable to load DLL 'CpuMathNative'

What did you do?:

Created a new .net standard project, added ML.NET from nuget and added the project to my existing solution (.net Framework 4.7.2). Set to Any x64.

P1

Most helpful comment

For some reasons you have to copy the DLL to the directory with the exe in it. You can find it in projectname/packages/Microsoft.ML.CpuMath/runtimes/win-x64/nativeassets/netstandard2.0

Worked Bro... Thanks a ton..

All 24 comments

For some reasons you have to copy the DLL to the directory with the exe in it. You can find it in projectname/packages/Microsoft.ML.CpuMath/runtimes/win-x64/nativeassets/netstandard2.0

Same as #4483 @harishsk if we get some bandwidth, can we have someone look into this?

For some reasons you have to copy the DLL to the directory with the exe in it. You can find it in projectname/packages/Microsoft.ML.CpuMath/runtimes/win-x64/nativeassets/netstandard2.0

Worked Bro... Thanks a ton..

I've been all over the Internet trying to resolve this issue. What a wacky solution! But it works.

@ArnieBerg have you tried one of the workarounds I listed here or here?

We shipped a bug in version 1.4.0 that broke this scenario. We've fixed it in the latest preview releases. Can you try either using 1.3.1 or 1.5.0-preview2? If you have problems with those versions, please let me know.

Another easy way to fix this is to use Use PackageReference instead of packages.config in your .csproj. See https://docs.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference for more info.

Yes, I was aware of those other posts and took those steps as well as the use of PackageReference, all to no avail. I am on 1.4.0 of the Microsoft.ML libs.

What version of visual studio are you using? Did you set your Platform to x86 or x64?

Can you share your project and I can take a look to see if there is anything fix that needs to be made here?

I鈥檇 recommend using 1.5.0-preview2 version. It has all the functionality of 1.4.0, plus some preview features not in 1.4.0. So anything you are trying to use in 1.4.0 will work exactly the same in 1.5.0-preview2.

My project is set to x64. I was on 1.5.0-preview2 initially but walked that back after running into this grief. I will move back to the preview2. Project attached.

RoomKing.AIFramework.zip

Thanks, @ArnieBerg. However, the project you attached is a class library. It isn't an application:

image

Can you share the project that produces an .exe that consumes this class library as well? That is the project that needs to be set to x64.

This is the calling app. It is targeting 64 bit platform.

AutoAssign.Framework.zip

@ArnieBerg - I noticed that you don't have

    <PackageReference Include="Microsoft.ML">
      <Version>1.4.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.ML.CpuMath">
      <Version>1.4.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.ML.LightGbm">
      <Version>1.4.0</Version>
    </PackageReference>

In your AutoAssign.Framework.csproj. Can you add those in the .exe as well? I believe that should solve your issue.

Also - be sure you are setting <PlatformTarget>x64</PlatformTarget> for both Debug and Release. I see you are missing that in Release in your .csproj.

I want to use ml.net embedded class library as a plugin in another application. I followed all the fix above but it seems not work although it works with normal windows application.

The exceptions are Unable to load DLL 'tensorflow' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E) and the same for 'CpuMathNative.'
When I add these two dll explicitly to the application, it works but show warning about assembly manifest of these two files.

How can I solve this problem? Thank you in advanced

@pthinh14 - for the tensorflow one, you need to explicitly reference the SciSharp.TensorFlow.Redist package. See https://github.com/dotnet/machinelearning/blob/master/docs/api-reference/tensorflow-usage.md

@eerhardt Thanks for responding.
@pthinh14 I am closing the issue. Please reopen if @eerhardt's response doesn't help and you need more clarification.

@eerhardt that application keeps saying Unable to load DLL 'tensorflow' or one of its dependencies although I did reference SciSharp.TensorFlow.Redist. I'm not sure if explicitly add tensorflow.dll to my managed code is a good idea. Hope to see your view on that.

Did you reference SciSharp.TensorFlow.Redist from your application's .csproj?

@eerhardt I assume I did
<ItemGroup> <PackageReference Include="FluentValidation"> <Version>8.6.2</Version> </PackageReference> <PackageReference Include="Microsoft.ML.ImageAnalytics"> <Version>1.4.0</Version> </PackageReference> <PackageReference Include="Microsoft.ML.TensorFlow"> <Version>1.4.0</Version> </PackageReference> <PackageReference Include="Microsoft.VisualStudio.OLE.Interop"> <Version>7.10.6071</Version> </PackageReference> <PackageReference Include="NLog"> <Version>4.7.0</Version> </PackageReference> <PackageReference Include="SciSharp.TensorFlow.Redist"> <Version>2.1.0</Version> </PackageReference> </ItemGroup>

I did the same and it works for a normal WPF application but when I move to class library and inject it to another application, it keeps showing this message

Did you also tell your application to target x64?

It might be easiest if you zip your repro app and post it. Or if you create a git repo with an application showing the issue.

Yes, I did. I tried many proposed solutions but they seem not working in this case.
Please have a look at https://github.com/pthinh14/restructure-model-tool

@pthinh14 ML.NET hasn't been tested with Scisharp.TensorFlow.Redist version 2.1.0.

We are currently on version 1.14.0. Can you try that version?

@harishsk I tried but it did not work.

@pthinh14 - The project you linked above is not an application - it is a Class Library. When I said "application" above, I specifically meant the project that outputs an .exe.

@eerhardt Do projects that reference projects that reference the ml.net nuget packages have to reference the nuget packages themselves?

We have a asp.net site that references a project that uses the ml.net packages. Both of our projects are set to x64. Periodically it stops working with the Unable to load DLL 'CpuMathNative' error.

From what I've noticed it depends on what kind of .csproj you are using with all of them.

If you are using the traditional .csproj style (you don't have <Project Sdk="Microsoft.NET.Sdk"> at the top) and are using packages.config, then yes you need all the references in the application .csproj.

If you are using the traditional .csproj style and are using <PackageReference in your application's .csproj, then you shouldn't need to.

If you are using <Project Sdk="Microsoft.NET.Sdk"> style .csproj, then everything should just work with referencing other projects that reference ml.net nuget packages and not having to copy the <PackageReference into the application's .csproj.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JakeRadMSFT picture JakeRadMSFT  路  3Comments

sethreidnz picture sethreidnz  路  3Comments

aslotte picture aslotte  路  3Comments

daholste picture daholste  路  4Comments

maxt3r picture maxt3r  路  3Comments