Skip to content

Unable to load DLL 'CpuMathNative' #4870

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

Closed
santosh-gokul opened this issue Feb 21, 2020 · 24 comments
Closed

Unable to load DLL 'CpuMathNative' #4870

santosh-gokul opened this issue Feb 21, 2020 · 24 comments
Labels
P1 Priority of the issue for triage purpose: Needs to be fixed soon.

Comments

@santosh-gokul
Copy link

santosh-gokul commented Feb 21, 2020

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.

@actopozipc
Copy link

actopozipc commented Feb 21, 2020

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

@gvashishtha gvashishtha added the P1 Priority of the issue for triage purpose: Needs to be fixed soon. label Feb 21, 2020
@gvashishtha
Copy link
Contributor

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

@santosh-gokul
Copy link
Author

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..

@ArnieBerg
Copy link

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

@eerhardt
Copy link
Member

@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.

@ArnieBerg
Copy link

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.

@eerhardt
Copy link
Member

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’d 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.

@ArnieBerg
Copy link

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

@eerhardt
Copy link
Member

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.

@ArnieBerg
Copy link

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

AutoAssign.Framework.zip

@eerhardt
Copy link
Member

@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.

@ntpthinh
Copy link

ntpthinh commented Apr 8, 2020

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

@eerhardt
Copy link
Member

eerhardt commented Apr 8, 2020

@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

@harishsk
Copy link
Contributor

harishsk commented Apr 8, 2020

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

@harishsk harishsk closed this as completed Apr 8, 2020
@ntpthinh
Copy link

ntpthinh commented Apr 9, 2020

@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.

@eerhardt
Copy link
Member

eerhardt commented Apr 9, 2020

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

@ntpthinh
Copy link

ntpthinh commented Apr 10, 2020

@eerhardt I assume I did

    <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

@eerhardt
Copy link
Member

eerhardt commented Apr 10, 2020

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.

@ntpthinh
Copy link

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

@harishsk
Copy link
Contributor

@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?

@ntpthinh
Copy link

@harishsk I tried but it did not work.

@eerhardt
Copy link
Member

@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.

@andrewkittredge
Copy link
Contributor

@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.

@eerhardt
Copy link
Member

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.

@ghost ghost locked as resolved and limited conversation to collaborators Mar 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P1 Priority of the issue for triage purpose: Needs to be fixed soon.
Projects
None yet
Development

No branches or pull requests

8 participants