Home > OS >  yamldotnet added 0x0d in desktop application but not in xamarin android
yamldotnet added 0x0d in desktop application but not in xamarin android

Time:09-16

I need help for my code, i will try to generate license file in cross-platform with yamldotnet but output different then desktop, it's removed 0x0D in xamarin android, i need to keep it 0x0D.

Code for generating license:

public void GenerateLicense()
{
    var YamlStream = new YamlStream(
          new YamlDocument(
              new YamlMappingNode(
                  new YamlScalarNode("XXXXXXXXXXXXXLic"), new YamlMappingNode(
                      new YamlScalarNode("CustomerName"), new YamlScalarNode("Yo"),
                      new YamlScalarNode("CustomerEmail"), new YamlScalarNode("[email protected]"),
                      new YamlScalarNode("HardwareID"), new YamlScalarNode("yo"),
                      new YamlScalarNode("Signature"), new YamlScalarNode()
                      )
                  )
              )
      );

    string yaml;
    var buffer = new StringBuilder();
    using (var writer = new StringWriter(buffer))
    {
        YamlStream.Save(writer, false);
        yaml = writer.ToString();
    }

    var checksum = StringToHex(MD5CheckSumStr(yaml));

    var input = new StringReader(yaml);
    YamlStream = new YamlStream();
    YamlStream.Load(input);

    var mapping = (YamlMappingNode)YamlStream.Documents[0].RootNode;
    ((YamlScalarNode)mapping.Children["XXXXXXXXXXXXXLic"]["Signature"]).Value = checksum;

    using (TextWriter writer = File.CreateText("../yo.yaml"))
    {
        YamlStream.Save(writer, false);
    }
}

Click Here it's output preview image left desktop and right xamarin android

CodePudding user response:

I assume it's using the platform-default line ending.

I suspect if you change your last block to:

using (TextWriter writer = File.CreateText("../yo.yaml"))
{
    writer.NewLine = "\r\n";
    YamlStream.Save(writer, false);
}

... that will fix it. You quite possibly want to do the same thing earlier on when you're writing to the StringWriter.

  • Related