0
<?xml version='1.0' encoding='ISO-8859-1' standalone='yes'?>
<Collection>
<Book Id='1' ISBN='1-100000ABC-200'>
<Title>Principle of Relativity</Title> 
</Book>
</Collection>

Whenever I want to save my updated XML file in the app directory which is /data/data/App17.App17/files an exception occurs which is

System.ArgumentException: Conversion buffer overflow.

Why does this exception is occur and how can I solve it?

using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using System.IO;
using System.Reflection;
using Android.Content.Res;
using System.Xml;
using System.Xml.Linq;
using System.Xml.XPath;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace App17
{
[Activity(Label = "App17", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
    int count = 1;

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);


        SetContentView(Resource.Layout.Main);
        var xml = XDocument.Load(Assets.Open("Q317664.xml"));
        var node = xml.Descendants("Book").FirstOrDefault(cd => cd.Attribute("Id").Value == "1");
        node.SetAttributeValue("ISBN", "new");

        string dir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
        string path = Path.Combine(dir, "Q317664.xml");

       xml.Save(path);
Sven-Michael Stübe
  • 14,560
  • 4
  • 52
  • 103
Asad Ahmad
  • 29
  • 1
  • 9

1 Answers1

0

The problem is, that the File is not encoded in UTF-8. I assume, you have created it with Visual Studio > New File. This creates a file with a Windows Code page or some other encoding.

Open the File in VS and save it via File > Advanced Save Options and then select Unicode - Codepage 1200.

enter image description here

After you have done this, your code should run fine.

Sven-Michael Stübe
  • 14,560
  • 4
  • 52
  • 103