Building TrakHound’s MTConnect.NET library for .NET Core 2.0

Building TrakHound’s MTConnect.NET library for .NET Core 2.0

Recently I tried to run the TrakHound MTConnect components on Linux, without success. It seems, though, that TrakHound’s MTConnect.NET library can be made to work within a .NET Core 2.0 application relatively easily.

My first attempt was to add the NuGet package using dotnet add package MTConnect.NET. This appeared to work, but I get warnings that the .NET Framework 4.6 version was loaded. When I try to run a test application, I then get a NullReferenceException when using the library.

After some experimentation, what ended up working was to clone the repository, then create a basic .csproj file targeting .NET Core 2.0. From there, I could add a reference from my test project with dotnet add reference /path/to/MTConnect.NET.csproj. The test project then built, ran, and pulled probe data from

My modified .csproj file is as follows.

<Project Sdk="Microsoft.NET.Sdk">

The various GenerateAssembly*Attribute tags are to circumvent a known issue with the build. This is my first foray into .NET Core, so I’m not sure what needs to be done to roll this into the existing .csproj project file, or to get the NuGet package to support .NET Core 2.0. Just a quick experiment to confirm that the library itself can work on a Linux box.

6 thoughts on “Building TrakHound’s MTConnect.NET library for .NET Core 2.0

  1. Would you be willing to walk me through this a little more in detail. I’m not getting the results. I have created a new project (I’m using visual studio 2017) and added a reference to the MTConnect.NET project. The new project is built using .NET Core 2.0, yet I cannot seem to use a lot of library calls and RestSharp is giving me an error.

  2. Not sure if my previous comment was actually posted, so I apologize if this is a repeat. I tried this method and still have errors about the 4.6 framework. Maybe I’m just doing it wrong: I have a Consol Application (using VS 2017) built on .NET core 2.0, and using MTConnect. In this project I created a clone of the MTConnect.NET and created a reference to it. The clone and the project are in the same solution. Could that be an issue. I could really pick your brain a little on the details of how you got this working. Thanks.

    1. Unfortunately I haven’t tried this in VS 2017. Tomorrow I’ll see if I can get a basic console application working in that version of VS.

      Could you post the error messages that you’re getting?

      1. “Package ‘MTConnect.NET’ was restored using ‘.NETFramework, Version=v4.6.1’ instead of the target project framework ‘.NETCoreApp, Version=v2.1’. This package may not be fully compatible with your project.”

    1. Sorry for the slow response. It sounds like project’s packages.config file is referencing the .NET 4.6 version of RestSharp.

      I’ve been working on a fork of this library at It’s not well-tested in VS2017, but you might use the src/NetStandard2.0/packages.config file for reference. I’m able to build a .NET Core 2.0 console application and perform a basic probe request with that project.

Leave a Reply

Your email address will not be published.

%d bloggers like this: