4.7.2 Framework generated executable works, but .NET Core does not

Vladimir 20 Reputation points
2023-06-15T14:03:37.1466667+00:00

Hiya, how are you all doing? I ask you to observe your explanations as I'm a hobby programmer and knowledge-wise surely cannot be compared with pro developers.

Situation:

I make a console program in .net Core (6 and 7), implementing a small part of the chess UCI protocol. Then compile and via a chess GUI (either Cutechess or Fritz 18 GUI) attach the executable. Sometimes magically it works. Mostly not. However, when I recreate the same project in ramework .net 4.7.2 then it works.

It must be something related to .net.. But I don't have the knowledge to analyze how the GUI interacts with the executable to figure out where it goes wrong. Notice that there's nothing to debug, as it would imply the GUI communicates with the console. It doesn't do that as it never gets that far.

I don't mind help on this at all. It would be horrible if I had to continue my chess programming journey with an older Framework instead of a .net core project. I run Windows 10 and use VS 2022 (Version 17.6.3).

The code below is only to prove that it's not the code causing the problem.

Steps to reproduce:

Install Cutechess gui.

Compile this code in .net core 6 or 7.

In Cutechess, go to tools->settings->engines

Add engine

Try to run a game with "game -> new and select the engine to play with either color"

Error occurs or nothing happens. Or you don't have the choice to select your "engine at all.

Now try the same with .net framework 4.7.2. Works fine. Every time.


using System;

namespace Uci2
{
    public class Program
    {
        private static void Main(string[] args)
        {
            while (true)
            {
                string input = ReadInput();

                if (input == null)
                    break;

                string[] tokens = input.Trim().Split();

                if (tokens.Length == 0)
                    continue;

                switch (tokens[0])
                {
                    case "uci":
                        Console.WriteLine($"id name ValChess");
                        Console.WriteLine($"id author Uci2");
                        Console.WriteLine("uciok");
                        break;
                    case "isready":
                        Console.WriteLine("readyok");
                        break;
                    case "position":
                        break;
                    case "go":
                        Console.WriteLine("bestmove e2e4");
                        break;
                    case "ucinewgame":
                        break;
                    case "stop":
                        break;
                    case "quit":
                        break;
                    case "setoption":
                        break;
                    default:
                        break;
                }
            }
        }

        private static string ReadInput()
        {
            return Console.ReadLine();
        }
    }
}
Developer technologies .NET .NET Runtime
Developer technologies .NET Other
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2023-06-15T15:18:11.2066667+00:00

    most likely the working folder is not properly set when running your .net console app.

    net 4.* installed a lot of it's support dll in the gac, so none were need to a simple console app. .net core does not use the gac, and requires several dlls at runtime.

    for .net core there is a single file option. this would probably fix your issue:

    https://learn.microsoft.com/en-us/dotnet/core/deploying/single-file/overview?tabs=cli

    as to why the core app is larger. .net works like java, there is an il code, and an engine to run it. for the old framework support of loading the engine was added to the o/s an a special exe format defined. with core, no o/s changes were made. so you run a core app with dotnet prog.dll. originally a script was generated, but not the compiler builds a small exe that hosts the core program automatically rather than using dotnet.exe. the single file, is just an extension that stores the dll's internally rather than as separate file.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.