Machinelearning: Microsoft.ML NuGet package doesn't work with packages.config

Created on 9 May 2018  路  19Comments  路  Source: dotnet/machinelearning

Original Title

Impossible to run Iris classification test

System information

  • OS version/distro:
    Windows 10.0.17134
  • .NET Version (eg., dotnet --info):
    Product Information:
    Version: 2.1.200
    Commit SHA-1 hash: 2edba8d7f1

Issue

  • What did you do?
    Try Iris tutorial

  • What happened?
    Runtime error:

System.Reflection.TargetInvocationException
HResult=0x80131604
Message=Eccezione generata dalla destinazione di una chiamata.
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 IrsiExample.Program.Main(String[] args) in C:\Users\gvolpi\source\repos\MLNetTest1\IrsiExample\Program.cs:line 69

Inner Exception 1:
TargetInvocationException: Eccezione generata dalla destinazione di una chiamata.

Inner Exception 2:
DllNotFoundException: Impossibile caricare la DLL 'CpuMathNative': Impossibile trovare il modulo specificato. (Eccezione da HRESULT: 0x8007007E).

  • What did you expect?

Source code / logs

Code copy/pasted from github

bug

Most helpful comment

Reopening. We've regressed the packages.config support with #4096.

If anyone runs into this with version 1.4.0, there are 2 separate workarounds. You can do either of the following, and it will work around the issue:

  1. Use PackageReference instead of packages.config.
  2. Alternatively, in your .csproj, add the following:
    <Content Include="..\packages\Microsoft.ML.CpuMath.1.4.0\runtimes\win-x64\nativeassets\netstandard2.0\*.dll" Condition="'$(PlatformTarget)' == 'x64'">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <Visible>false</Visible>
      <Link>%(Filename)%(Extension)</Link>
    </Content>
    <Content Include="..\packages\Microsoft.ML.CpuMath.1.4.0\runtimes\win-x86\nativeassets\netstandard2.0\*.dll" Condition="'$(PlatformTarget)' == 'x86'">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <Visible>false</Visible>
      <Link>%(Filename)%(Extension)</Link>
    </Content>
  </ItemGroup>

(NOTE: if your packages folder is somewhere other than ..\packages, you will need to adjust the path above.)

All 19 comments

Hi @guivo,

Can you give some more insight in how you referenced ML.NET? Did you use a <PackageReference Include="Microsoft.ML" Version="0.1.0" /> in your .csproj?

Are you on the desktop .NET Framework? If so, you need to switch your project to be built for x64 architecture. Currently, ML.NET only supports x64 processes since we have some C++ native code (the "CpuMathNative" assembly from above) and are only building it for x64 currently.

Hi @eerhardt , I have done the test creating a desktop C# project for a CLI application. I have then inluded Microsoft.ML using NuGet and the csproj is slightly different but I am not sure this is relevant:

<Reference Include="Microsoft.ML, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> <HintPath>..\packages\Microsoft.ML.0.1.0\lib\netstandard2.0\Microsoft.ML.dll</HintPath> </Reference>

More lines are there, to refence other ML modules (Api, Core, CpuMath....)

I can confirm that I am targeting x64 (visual studio fails if try a different architecture).

@guivo, Thanks for checking. Looks like the process fails to find the cpuMathNative.dll. Can you check that the file is in the same location as other managed DLLs and the exe? If it is not in the target directory, then it's likely a problem with our NuGet definition. To unblock yourself, you can copy that file there manually for now.

Regards.

@guivo - I get your issue now. The problem is that you are using packages.config. Can you switch it to use <PackageReference> instead? This blog shows how easy it is to switch:

https://blog.nuget.org/20180409/migrate-packages-config-to-package-reference.html

You can also make PackageReference your default experience in VS following this blog.

Renaming the issue to best reflect the problem.

Guidance from the NuGet team is:

Packages.config doesn鈥檛 support native assets in runtimes\RID,
folks typically write targets to deal with this.
For an example look at https://www.nuget.org/packages/Microsoft.DiaSymReader.Native/1.7.0.

@eerhardt migrating to PackageReference fixed the issue, thanks!

Should I however expect a more flexible approach in the next release of the package?

I haven't tried getting it to work, but it seems simple enough to fix Microsoft.ML to work with packages.config. So I'd hope we can fix it in the next release.

With regard to this thread, I would to mention that in the case a solution with 3 projects, the recipe I have used (Migrating to PackageReference) didn't have positive effect in the last project. Where the migration seemed successful but the runtime error about not finding CpuMathNative appears.

Same code, in a solution with only that project, everything worked.

@guivo - if you could share a .zip (or push to a repo) of a solution that reproduces the issue, I can take a look.

BTW - #165 will fix this issue and allow ML.NET to work with packages.config. So the next release won't require PackageReference.

Sorry, this wasn't actually an issue. It was a visual studio artifact (bug?): I asked to run an x86 conf but it was actually using anycpu, where the math library is not available.

Thanks

Same issue to me
Wpf application
Net 4.8
it's 64 bit
Addded packages ML
opps not working at all

switcting to packagereference solved the question !! ;-)

Reopening. We've regressed the packages.config support with #4096.

If anyone runs into this with version 1.4.0, there are 2 separate workarounds. You can do either of the following, and it will work around the issue:

  1. Use PackageReference instead of packages.config.
  2. Alternatively, in your .csproj, add the following:
    <Content Include="..\packages\Microsoft.ML.CpuMath.1.4.0\runtimes\win-x64\nativeassets\netstandard2.0\*.dll" Condition="'$(PlatformTarget)' == 'x64'">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <Visible>false</Visible>
      <Link>%(Filename)%(Extension)</Link>
    </Content>
    <Content Include="..\packages\Microsoft.ML.CpuMath.1.4.0\runtimes\win-x86\nativeassets\netstandard2.0\*.dll" Condition="'$(PlatformTarget)' == 'x86'">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <Visible>false</Visible>
      <Link>%(Filename)%(Extension)</Link>
    </Content>
  </ItemGroup>

(NOTE: if your packages folder is somewhere other than ..\packages, you will need to adjust the path above.)

The 1st Workaround was not alllowed so tried 2nd adding the code in .csproj but no effect.In Packages folder CpuMathNative.dll is seen but still the error continues.Dont know why it is not able to find.

I am getting the same error but on different scenario. I have 2 input fields one is string and one is int/float. If I am setting only text attribute to my model it is working fine, but when I set int its giving that Microsoft.ML.CpuMathNatiive.dll not loaded error. I am running on x64 mode using ML 1.4.0
Please suggest and provide sample code.

I am trying to consume this model in a service and getting this error.

@samcode22 Is your issue solved?

@coderdipti - can you try with the latest pre-release version of ML.NET? https://www.nuget.org/packages/Microsoft.ML/1.5.0-preview. If that doesn't fix your issue, please open a new issue to track it with full repro steps - https://github.com/dotnet/machinelearning/issues/new

I think the problem will be solved in the next version, temporarily type
--" Install-Package Microsoft.ML -Version 1.5.0-preview "--
and run it in the package manager

Hi everyone
I get this error when publish to iis but it works in debug on vs.
I used CpuMathNative 1.5.2
@eerhardt

@cemilsavtekin - this issue is quite old. Could you open an new issue with as much information as you can? Useful information would be:

  • A link to your project, or your .csproj
  • The steps you took to encounter the error
  • The error message
Was this page helpful?
0 / 5 - 0 ratings

Related issues

sethreidnz picture sethreidnz  路  3Comments

bs6523 picture bs6523  路  4Comments

pgovind picture pgovind  路  3Comments

daholste picture daholste  路  3Comments

daholste picture daholste  路  3Comments