Skip to content

.NET 4.7 CpuMathNative.dll not found #137

Closed

Description

@katterfelto
  • Windows 10 Pro x64
  • .NET Framework 4.7 Console App in Visual Studio 2017 15.7.1

I followed the steps on the 'Get Started' page (https://www.microsoft.com/net/learn/apps/machine-learning-and-ai/ml-dotnet/get-started/windows). But I created a .NET 4.7 console app.

When I run the application the following exception is thrown on line 70 of Program.cs

I have located the missing DLL in the packages folder. If I manually copy the file into the output folder of my project the application runs as expected.

============== Exception Information ==============
System.Reflection.TargetInvocationException
HResult=0x80131604
Message=Exception has been thrown by the target of an invocation.
Source=mscorlib
StackTrace:
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.ML.Runtime.EntryPoints.EntryPointNode.Run()
at Microsoft.ML.Runtime.EntryPoints.EntryPointGraph.RunNode(EntryPointNode node)
at Microsoft.ML.Runtime.EntryPoints.JsonUtils.GraphRunner.RunAllNonMacros()
at Microsoft.ML.Runtime.EntryPoints.JsonUtils.GraphRunner.RunAll()
at Microsoft.ML.LearningPipeline.TrainTInput,TOutput
at myApp.Program.Main(String[] args) in C:\Users\Dave\Documents\Visual Studio 2017\Projects\MLTests\Iris\Program.cs:line 70

Inner Exception 1:
TargetInvocationException: Exception has been thrown by the target of an invocation.

Inner Exception 2:
DllNotFoundException: Unable to load DLL 'CpuMathNative': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

Activity

  1. pareion commented on May 13, 2018

    @pareion

    I followed some of the suggetions from this page and got it to work with that tutorial
    #93

  2. aklcraigc commented on May 14, 2018

    @aklcraigc

    @pareion I'm getting the same problem, what specifically do you think fixed the problem.

  3. tobiasw2 commented on May 14, 2018

    @tobiasw2

    I can confirm this issue. Besides the mentioned workaround (manually copying the missing file) it also works to switch the "TargetFramework" property from "net47" to "netcoreapp2.0". Therefore it seems to be related with using .NET Framework.

  4. eerhardt commented on May 14, 2018

    @eerhardt
    Member

    I've seen 2 cases where this error happens:

    1. When you use packages.config instead of <PackageReference> in your .csproj. This issue is tracked by Microsoft.ML NuGet package doesn't work with packages.config #93, and a fix should be made soon to the daily builds.
    2. On .NET Framework, if you are targeting Any CPU. ML.NET only supports x64, so if you are using the desktop/full .NET Framework, ensure you change Any CPU to x64, since there are only x64 native assemblies.
  5. pareion commented on May 15, 2018

    @pareion

    @aklcraigc I manually changed the .csproj file by adding the line
    <PackageReference Include="Microsoft.ML" Version="0.1.0" />
    And then changed the targeting to x64

  6. aklcraigc commented on May 15, 2018

    @aklcraigc

    @pareion Thanks, that did the trick.

  7. markusweimer commented on May 16, 2018

    @markusweimer

    @DaisyDave, did the suggestions in this issue work for you? If so, we can close the issue :)

  8. katterfelto commented on May 16, 2018

    @katterfelto
    Author

    @markusweimer Sorry for the lack of updates. The suggestions solved that error but there was a minor issue with the solutiion, I'm not sure whether this was because I didn't start from scratch and still had things in my packages folder. Below are the steps I took.

    • I removed the packages added via NuGet from the solution.
    • Switched VS Tools->Options to use 'PackageReference' for package management.
    • I then re-added Microsoft.ML from NuGet.

    There was one minor issue, it did not add any of the dependancies it had during the initial attempt. I ended up having to manual add the json package to get the app to run. As I said at the top I'm not sure if this was because I didn't start totally from scratch.

    You can close this issue for me but if you are not going to or can't fix the package.config issue perhaps adding something to the getting started page would be an idea.

  9. claudiobottari commented on May 16, 2018

    @claudiobottari

    I just tried the aforementioned"PackageReference" workaround but I still getting the error. I had to switch to net462 which I assume is the source of the issue.

  10. eerhardt commented on May 16, 2018

    @eerhardt
    Member

    @claudiobottari - are you using VS 2015 or VS 2017? Would it be possible to share your .csproj so I can take a look?

  11. claudiobottari commented on May 16, 2018

    @claudiobottari

    VS 2017

    csproj attached
    Sample.zip

  12. eerhardt commented on May 16, 2018

    @eerhardt
    Member

    @claudiobottari - the issue is that ML.NET only supports x64, and you are attempting to use AnyCPU. You can change the following:

    <RuntimeIdentifier>AnyCPU</RuntimeIdentifier>
    ||
    V
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>

    And remove the line

    <PlatformTarget>AnyCPU</PlatformTarget>

    That should fix your project. When fixing #93, I am also adding a build error message to help people in this situation know that they need to target x64.

  13. claudiobottari commented on May 16, 2018

    @claudiobottari

    Thank you, my project works now

  14. tobiasw2 commented on May 16, 2018

    @tobiasw2

    My issue seems to be solved too. I already used "PackageReference" and x64. But I was setting x64 as PlatformTarget. Tried it with RuntimeIdentifier and finally the CpuMathNative.dll exists in the output folder of my project. Everything seems to work now.

  15. katterfelto commented on May 16, 2018

    @katterfelto
    Author

    I have retested by setting up a new project and then adding Microsoft.ML using NuGet using Visual Studio set to manage packages via PackageReference. There were no errors.

  16. katterfelto commented on May 16, 2018

    @katterfelto
    Author

    I'm going to close my issue.

  17. Dineshkumar-Ponnusamy commented on May 29, 2018

    @Dineshkumar-Ponnusamy

    Adding, <PackageReference Include="Microsoft.ML" Version="0.1.0" /> inside the <ItemGroup> of *.csproj worked for me.

  18. pjmelvin commented on Dec 23, 2019

    @pjmelvin

    I had to copy the file from the reference location in the ML download to the bin directory after the build to get this to work... bother.

  19. ghost locked as resolved and limited conversation to collaborators on Mar 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions