Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is the correct way to write a .conf file?

I’m trying to compile a ready-made project, in which a .conf file is missing, I tried to write this file but I always get errors like "System.FormatException: Input string was not in a correct format." What is the correct way to write the .conf file for this code? From what I’ve seen, you have to declare a value for Host: 127.0.0.1;
Port: 29300;
PwVersion : 156;


namespace CoreAutoMessage.Models;

public record GProvider : IPwDaemonConfig
{
    public string Host { get; private init; }
    public int Port { get; private init; }
    public int PwVersion { get; private init; }

    public GProvider()
    {
        var gproviderConfs = File.ReadAllLines("./Configurations/GProvider.conf");

        this.Host = gproviderConfs[1];
        this.Port = int.Parse(gproviderConfs[3]);
        this.PwVersion = int.Parse(gproviderConfs[5]);
    }
}

Sorry I’m new to C#

GProvider.conf =

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Host:127.0.0.1
Port:29300
PwVersion:156

>Solution :

Here is the format:

Host: or literally anything here.
127.0.0.1
Port:
29300
PwVersion:
156

The ReadAllLines method returns an array of strings, literally lines, separated by endline character. And in your code you are just looking for specified line numbers, 1 3 5, numeration from 0.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading