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)
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:
PackageReference instead of packages.config.v1.3.1 of ML.NET until a new version comes out with the fix.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
 Eric ErhardtUser contributions licensed under CC BY-SA 3.0