2

I have the code for CSEvalClientTest.csproj from Microsoft's CNTK on GitHub. I've created a new Visual Studio 2015 c# console app, pasted in the code from CSEvalClientTest.csproj, fixed the references and got it to run. It doesn't get very far though. On this line of source code: using (var model = new IEvaluateModelManagedF()) It throws this exception:

System.Runtime.InteropServices.SEHException was unhandled
  • ErrorCode=-2147467259 HResult=-2147467259 Message=External component has thrown an exception. Source=hhCSEvalClientTest
    StackTrace: at Microsoft.MSR.CNTK.Extensibility.Managed.CSEvalClient.Program.OnGeneralException(Exception ex) in E:\Users\Hal\Source\Workspaces\hhCSEvalClientTest\hhCSEvalClientTest\hhCSEvalClientTest\Program.cs:line 123 at Microsoft.MSR.CNTK.Extensibility.Managed.CSEvalClient.Program.EvaluateModelSingleLayer() in E:\Users\Hal\Source\Workspaces\hhCSEvalClientTest\hhCSEvalClientTest\hhCSEvalClientTest\Program.cs:line 171 at Microsoft.MSR.CNTK.Extensibility.Managed.CSEvalClient.Program.Main(String[] args) in E:\Users\Hal\Source\Workspaces\hhCSEvalClientTest\hhCSEvalClientTest\hhCSEvalClientTest\Program.cs:line 69 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException:

Any help resolving this issue will be very much appreciated!

Hal Heinrich
  • 544
  • 1
  • 4
  • 21

2 Answers2

1

Would you be able to use CNTK Nuget Package for your C# application? This would remove most headaches regarding dll references. You can look at the example in https://github.com/Microsoft/CNTK/tree/master/Examples/Evaluation/CSEvalClient for more information.

Zhou
  • 546
  • 3
  • 3
  • Good point, yes - if using the standard build without modifications, the Nuget package should be easier than custom referencing. – Anton Schwaighofer Nov 19 '16 at 17:20
  • Thanks for the suggestion - I may come back to it later. For now, I'm hoping I can fix up the references. I have trouble using Git and have never used Nuget. I want to learn about CNTK while minimizing the other tools I need to learn to get it up and running. – Hal Heinrich Nov 20 '16 at 04:22
  • After so much struggling, I think Zhou's suggestion is the way to go. Using nuget is very simple really. In VS, use Tools/NugetPackageManger/ManagePackagesForSolution. Pick nuget.org, search for "CNTK" in the "search online" box. Then you can pick which projects should get the reference. – Anton Schwaighofer Nov 21 '16 at 13:30
0

Most likely, you are missing some of the referenced native DLLs. Have a look at this related SO question for a list of DLLs. Those need to reside in the same directory as your main executable.

Note that you will have to add the correct set of references for all DLLs or EXEs that use EvalWrapper, which is a cumbersome. I've found it helpful to work with a props file, that you reference in your project files. Here's how my cntk_evalwrapper.props looks like (you need to adjust the location of your CNTK build)

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <None Include="c:/git/cntk/x64/Release_CpuOnly/EvalDll.dll">
      <Link>evaldll.dll</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Include="c:/git/cntk/x64/Release_CpuOnly/EvalDll.lib">
      <Link>EvalDll.lib</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Include="c:/git/cntk/x64/Release_CpuOnly/Math.dll">
      <Link>Math.dll</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Include="c:/git/cntk/x64/Release_CpuOnly/libiomp5md.dll">
      <Link>libiomp5md.dll</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Include="c:/git/cntk/x64/Release_CpuOnly/mkl_cntk_p.dll">
      <Link>mkl_cntk_p.dll</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <Reference Include="EvalWrapper">
      <HintPath>c:/git/cntk/x64/Release_CpuOnly/EvalWrapper.dll</HintPath>
    </Reference>
  </ItemGroup>
</Project>

In your project file yourproject.csproj, include this props file, so that the top of your project file looks like:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\cntk_evalwrapper.props" />

Again, adjust the relative path such that it correctly points from your project file to the props file. If that worked correctly, you should see a reference to EvalWrapper in your project's references once you re-load the project.

Community
  • 1
  • 1
Anton Schwaighofer
  • 3,119
  • 11
  • 24
  • Thanks for the quick response. I'm struggling with adding the other DLLs. I can add and remove EvalWrapper.dll without trouble. But the rest of them from your link fail with the error: **A reference to the "....dll" could not be added.Please make sure that the file is accessible and that it is a valid assembly or COM component.**. I've added the DLLs to the directory you suggested: **..\obj\x64\Debug**, but I'm still getting the same error. I've googled adding references, and find a lot of different approaches - none of which feel 'right'. Would you point me in the right direction? – Hal Heinrich Nov 18 '16 at 20:20
  • `EvalWrapper.dll` is the only reference that you need to add. For all the other DLLs, do not try to add them as references - they only must sit in the same directory as `EvalWrapper.dll`. I would really suggest you go the way of the props file. May seem daunting at first to mess with the .csproj file, but makes live a lot easier. Right-click on the project, "Unload project", then "Edit project file", do your edits, then "Re-load project". Make sure you save backup of your project file first. – Anton Schwaighofer Nov 18 '16 at 21:31
  • Thanks again! I wrestled with this for a while and some progress. The changes to the .csproj file seem good. The code follows in the next comment. sorry, but I can't get the formatting to work. – Hal Heinrich Nov 20 '16 at 05:12
  • My project builds fine. The reference to EvalWrapper appears, and if I delete it, it reappears when I reopen the project. When I run the project form Visual Studio, it crashes with a **vshost.exe has stopped working** *A problem caused the program to stop working correctly. Windows will close the program and notify you if a solution is available.* That occurs at the same point in the code where the exception was being thrown previously. – Hal Heinrich Nov 20 '16 at 05:33
  • The slash,backslash pair in your props file example seems odd. I changed it to just a slash, but that made no difference, so I've changed it back. My .props file follows in the next comment. I'm using the CPU plus GPU version of the code. I got the first Python/Jupyter tutorial to work, so I assume that's not an issue. My .props file is in the next comment. – Hal Heinrich Nov 20 '16 at 05:38
  • evaldll.dll Always ... E:\Users\Hal\Source\Workspaces\CSEvalClientTest\CSEvalClientTest\CSEvalClientTest\obj\x64\Debug\/EvalWrapper.dll – Hal Heinrich Nov 20 '16 at 05:42
  • Any thoughts as to what I might try next? – Hal Heinrich Nov 20 '16 at 05:43
  • Did you verify that the DLLs in question actually exist in the directory you are using? If you are using the default CNTK build setup and output folders, I don't think you would ever see DLLs in `CSEvalClientTest\CS‌​EvalClientTest\CSEva‌​lClientTest\obj\x64\‌​Debug\` – Anton Schwaighofer Nov 21 '16 at 13:26