I am creating a completely new solution, with just a few lines of code that result in the stacktrace:
PS E:\MyProjects\C#\CNTK-GettingStarted> dotnet restore
Restoring packages for E:\MyProjects\C#\CNTK-GettingStarted\CNTK-GettingStarted.csproj...
Generating MSBuild file E:\MyProjects\C#\CNTK-GettingStarted\obj\CNTK-GettingStarted.csproj.nuget.g.props.
Generating MSBuild file E:\MyProjects\C#\CNTK-GettingStarted\obj\CNTK-GettingStarted.csproj.nuget.g.targets.
Restore completed in 141.36 ms for E:\MyProjects\C#\CNTK-GettingStarted\CNTK-GettingStarted.csproj.
PS E:\MyProjects\C#\CNTK-GettingStarted> dotnet build
Microsoft (R) Build Engine version 15.8.160-preview+gaf9d27ba72 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 28.66 ms for E:\MyProjects\C#\CNTK-GettingStarted\CNTK-GettingStarted.csproj.
C:\Program Files\dotnet\sdk\2.1.400-preview-009171\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(143,5): message NETSDK1057: You are working with a preview version of the .NET Core SDK. You can define the SDK version via a global.json file in the current project. More at https://go.microsoft.com/fwlink/?linkid=869452 [E:\MyProjects\C#\CNTK-GettingStarted\CNTK-GettingStarted.csproj]
CNTK-GettingStarted -> E:\MyProjects\C#\CNTK-GettingStarted\bin\Debug\netcoreapp2.1\CNTK-GettingStarted.dll
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.83
PS E:\MyProjects\C#\CNTK-GettingStarted> dotnet run
Unhandled Exception: System.TypeInitializationException: The type initializer for 'CNTK.CNTKLibPINVOKE' threw an exception. ---> System.TypeInitializationException: The type initializer for 'SWIGExceptionHelper' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'Cntk.Core.CSBinding-2.6-rc0.dev20180821.dll' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at CNTK.CNTKLibPINVOKE.SWIGExceptionHelper.SWIGRegisterExceptionCallbacks_CNTKLib(ExceptionDelegate applicationDelegate, ExceptionDelegate arithmeticDelegate, ExceptionDelegate divideByZeroDelegate, ExceptionDelegate indexOutOfRangeDelegate, ExceptionDelegate invalidCastDelegate, ExceptionDelegate invalidOperationDelegate, ExceptionDelegate ioDelegate, ExceptionDelegate nullReferenceDelegate, ExceptionDelegate outOfMemoryDelegate, ExceptionDelegate overflowDelegate, ExceptionDelegate systemExceptionDelegate)
at CNTK.CNTKLibPINVOKE.SWIGExceptionHelper..cctor()
--- End of inner exception stack trace ---
at CNTK.CNTKLibPINVOKE.SWIGExceptionHelper..ctor()
at CNTK.CNTKLibPINVOKE..cctor()
--- End of inner exception stack trace ---
at CNTK.CNTKLibPINVOKE.DeviceDescriptor_UseDefaultDevice()
at CNTK.DeviceDescriptor.UseDefaultDevice()
at CNTK_GettingStarted.Program.Run() in E:\MyProjects\C#\CNTK-GettingStarted\Program.cs:line 15
at CNTK_GettingStarted.Program.Main(String[] args) in E:\MyProjects\C#\CNTK-GettingStarted\Program.cs:line 10
PS E:\MyProjects\C#\CNTK-GettingStarted>
My .csproj file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RootNamespace>CNTK_GettingStarted</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CNTK.GPU" Version="2.6.0-rc0.dev20180821" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
</ItemGroup>
</Project>
My Program.cs file;
```C#
using CNTK;
using System;
namespace CNTK_GettingStarted
{
class Program
{
static void Main(string[] args)
{
new Program().Run();
}
void Run()
{
var cpu = DeviceDescriptor.UseDefaultDevice();
Console.WriteLine($"You are using CNTK for: {cpu.Type}");
}
}
}
```
Try to add
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<Platforms>AnyCPU;x64</Platforms>
to the propertygroup.
It only works in x64 configuration.
I however ran into other issues with 2.6 that works fine on 2.5.
https://stackoverflow.com/questions/51974745/how-to-load-a-onnx-model-with-cntk-on-dotnet-core
I have the same error, does anyone has a solution? I'm using the version 2.5.1, my project already is in x64, but I get the same.

Update: I've manage to solve the problem. Take a look.

I have the same issue using 2.6.0-rc0.dev20180823.
@limapedro Can you give more information about how you managed to solve the problem?
Also could you post the .csproj that worked for you?
I have the same problem with my x64 project running on .netcore 2.0, not working neither in IIS express (64bit) nor console. #2352
I have the same issue with my x64 wpf project using ver. 2.6. I solved the issue as limapedro suggested. To add 'x64' platform, be sure to check off 'create new solution platform' in the 'new' dialog.

It looks as if you need to set the x64 on the solution via the Configuration manager, not the project.
Most helpful comment
I have the same issue using 2.6.0-rc0.dev20180823.
@limapedro Can you give more information about how you managed to solve the problem?
Also could you post the .csproj that worked for you?