1

I am trying to make project in .NET framework in which the controller code is as below:

[HttpGet]
public ActionResult Analysis()
{
    return View();
}

[HttpPost]
public ActionResult Analysis(ModelInput input)
{
    // Load the model  
    MLContext mlContext = new MLContext();
    ITransformer mlModel = mlContext.Model.Load(@"C:\Users\samya\source\repos\riya123\riya123ML.Model\MLModel.zip", out var modelInputSchema);

    // Create prediction engine related to the loaded train model
    var predEngine = mlContext.Model.CreatePredictionEngine<ModelInput, ModelOutput>(mlModel);

    // Input  
    input.Year = DateTime.Now.Year;

    // Try model on sample data and find the score
    ModelOutput result = predEngine.Predict(input);

    // Store result into ViewBag
    ViewBag.Result = result;

    return View();
}

And when I try to run it shows error as below although the dll is seen in the solution explorer:

Exception thrown: 'System.DllNotFoundException' in Microsoft.ML.CpuMath.dll

An exception of type 'System.DllNotFoundException' occurred in Microsoft.ML.CpuMath.dll but was not handled in user code

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

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Bond007
  • 31
  • 5
  • Please try to reinstall Microsoft.ML.CpuMath package from NuGet. – habib Nov 16 '19 at 15:58
  • Uninstalled both ML.NET and ML.CpuMath package and reinstalled but error remains same..Here is a link which has similar problem but couldn't understand:https://github.com/dotnet/machinelearning/issues/3764 – Bond007 Nov 16 '19 at 16:32

1 Answers1

2

There is a bug with the v1.4.0 version of ML.NET that breaks projects using packages.config. See:

To workaround this, try one of the following possible workarounds:

  1. Use PackageReference instead of packages.config.
  2. Fallback to v1.3.1 of ML.NET until a new version comes out with the fix.
  3. Alternatively, you can copy the CpuMathNative.dll from the nuget package into your output folder. You can do this manually, or with a change to your .csproj like 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.)

Also note one more thing: You can't use AnyCPU with ML.NET on .NET Framework. Since ML.NET uses native assemblies, you need to pick either x86 or x64 explicitly.

Eric Erhardt
  • 2,286
  • 15
  • 19