2
votes

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!

2

2 Answers

1
votes

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.

0
votes

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.