IBM MQ For .NET Core Primer

I’m starting to see questions (even being asked) about IBM MQ for .NET Core and the challenges that people are having. I’m not a .NET developer, more of a “I’ll do it to get it done” .NET developer. Hence, I’ll explain it from an IBM MQ perspective.

The first thing you should know is that there are 2 different .NET environments: .NET Framework and .NET Core.

  • .NET Framework V1.0 was released in 2001 and the current release of .NET Framework is V4.8 and was released in 2019.
  • .NET Core V1.0 was released in 2016. Microsoft re-branded .NET Core to be called just .NET in 2020. The current release of .NET is V6 and was released in last month.

So far, so good!?!

Now to IBM MQ. IBM has 2 releases of IBM MQ called: IBM MQ classes for .NET Framework and IBM MQ classes for .NET Standard (aka Base .NET Classes).

  • IBM MQ classes for .NET Framework is for .NET Framework
  • IBM MQ classes for .NET Standard is for .NET Core (aka .NET)
    When you are developing MQ applications for .NET Framework or Core, you need to select the correct MQ DLL:

  • IBM MQ classes for .NET Framework uses amqmdnet.dll
  • IBM MQ classes for .NET Standard uses amqmdnetstd.dll

So, still with me!?!

I have posted a lot of IBM MQ C# sample applications that were built for .NET Framework and can also be built for .NET Core.

So, lets say you now want to build your MQ .NET applications for .NET Core. Well, the first thing you will need to do is check if you have .NET Core v3.1 or higher. To check, simply issue the dotnet –version command. Note: You can also use the dotnet –info command.
i.e.

C:\>dotnet –version
2.1.509

So, I don’t have the correct .NET Core version. To get .NET Core v3.1, simply go to Microsoft’s Download .NET Core 3.1 web page, download and then install it. As you see on the download page, you can get .NET Core V3.1 for Linux, macOS and Windows.

After you install .NET Core v3.1, you can issue the dotnet –version command again.
i.e.

C:\>dotnet –version
3.1.415

Now I have the correct .NET Core release to use the IBM MQ classes for .NET Standard.

I just copied my MQTest62L.cs (get messages in a loop) to a new directory. You can download the source code from here.

Next, we need to create a C# project file for it. The C# project file is used by the .NET Core compiler to build the executable. There are 2 important items in it: .NET Core version and where to find the amqmdnetstd.dll file. Simply name the C# project file with the same prefix as the source file. i.e. MQTest62L.csproj
i.e.

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

<PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
	<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
	<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
	<OutputPath>.</OutputPath>
    </PropertyGroup>
  <ItemGroup>
    <Reference Include="amqmdnetstd">
      <HintPath>C:\Program Files\IBM\MQ\tools\dotnet\samples\cs\core\base\bin\amqmdnetstd.dll</HintPath>
    </Reference>
  </ItemGroup>
</Project>

So, now we can compile the C# file as follows:

F:\dev\some\path\to\it\MQTest62L> dotnet build MQTest62L.csproj
Microsoft (R) Build Engine version 16.7.2+b60ddb6f4 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  All projects are up-to-date for restore.
  MQTest62L -> F:\dev\some\path\to\it\MQTest62L\MQTest62L.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.66

The .NET Core compiler will generate a bunch of files in the working directory. Don’t worry about them, as long as it generated the MQTest62L.exe file.

So, now it is time to test the newly build application. I’ll put 10 test messages on the queue using MQ Visual Edit then run MQTest62L.exe to retrieve the messages.

F:\dev\some\path\to\it\MQTest62L>  MQTest62L.exe -h 127.0.0.1 -p 1414 -c TEST.CHL -m MQA1 -q TEST.Q1 -u tester -x mypwd
2021-12-03 16:49:26.799 MQTest62L: MQ:
2021-12-03 16:49:26.805 MQTest62L:   QMgrName ='MQA1'
2021-12-03 16:49:26.806 MQTest62L:   Output QName ='TEST.Q1'
2021-12-03 16:49:26.806 MQTest62L: Connection values:
2021-12-03 16:49:26.807 MQTest62L:   hostname = '127.0.0.1'
2021-12-03 16:49:26.807 MQTest62L:   userID = 'tester'
2021-12-03 16:49:26.807 MQTest62L:   port = '1414'
2021-12-03 16:49:26.808 MQTest62L:   transport = 'MQSeries Managed Client'
2021-12-03 16:49:26.808 MQTest62L:   channel = 'TEST.CHL'
2021-12-03 16:49:27.015 MQTest62L: MQTest62L successfully connected to MQA1
2021-12-03 16:49:27.020 MQTest62L: MQTest62L successfully opened TEST.Q1
2021-12-03 16:49:27.041 MQTest62L: Message Data: This is a test message #1
2021-12-03 16:49:27.042 MQTest62L: Message Data: This is a test message #2
2021-12-03 16:49:27.043 MQTest62L: Message Data: This is a test message #3
2021-12-03 16:49:27.043 MQTest62L: Message Data: This is a test message #4
2021-12-03 16:49:27.044 MQTest62L: Message Data: This is a test message #5
2021-12-03 16:49:27.044 MQTest62L: Message Data: This is a test message #6
2021-12-03 16:49:27.045 MQTest62L: Message Data: This is a test message #7
2021-12-03 16:49:27.045 MQTest62L: Message Data: This is a test message #8
2021-12-03 16:49:27.046 MQTest62L: Message Data: This is a test message #9
2021-12-03 16:49:27.048 MQTest62L: Message Data: This is a test message #10
2021-12-03 16:49:32.065 MQTest62L: No more messages.
2021-12-03 16:49:32.068 MQTest62L: closed: TEST.Q1
2021-12-03 16:49:32.080 MQTest62L: disconnected from MQA1

Hopefully the above information will help people get up and running using .NET Core and IBM MQ classes for .NET Standard.

If you are really adventurous, you can now build IBM MQ and .NET Core applications on Linux, macOS and Windows. Have fun!

Regards,
Roger Lacroix
Capitalware Inc.

This entry was posted in .NET, C#, IBM MQ, IBM MQ Appliance, Linux, macOS (Mac OS X), Windows.

Comments are closed.