C# 保存KML文件时,我发现系统内存不足异常

C# 保存KML文件时,我发现系统内存不足异常,c#,C#,我正在尝试导出kml文件。由于某些原因,我不断地使系统内存不足异常。请在下面找到我的代码 SharpKml.Dom.Kml root = new SharpKml.Dom.Kml(); root.Feature = doc; SharpKml.Engine.KmlFile kmlFile = SharpKml.Engine.KmlFile.Create(root, true); try {

我正在尝试导出kml文件。由于某些原因,我不断地使系统内存不足异常。请在下面找到我的代码

        SharpKml.Dom.Kml root = new SharpKml.Dom.Kml();
        root.Feature = doc;

        SharpKml.Engine.KmlFile kmlFile = SharpKml.Engine.KmlFile.Create(root, true);
        try
        {
            using (var stream = File.OpenWrite(kmlFileName))
                kmlFile.Save(stream);
        }
        catch 
        { 
          throw;
        }

它在KmlFile.Save(流)上爆炸。请帮助

下一个代码对我来说很好

try
{
        LineString lineString = new LineString()
        {
            AltitudeMode = AltitudeMode.Absolute,
            Tessellate = true,
            Coordinates = new CoordinateCollection()
        };


        Vector prevCoordinates = new Vector(45.883144378662109, 13.902674674987793, -71.5);
        lineString.Coordinates.Add(prevCoordinates);

        Placemark placemark = new Placemark()
        {
            Name = "Coordinate log",
            Geometry = lineString
        };
        placemark.AddStyle(new Style()
        {
            Line = new LineStyle()
            {
                ColorMode = ColorMode.Normal,
                Width = 3,
                Color = new Color32(255, 255, 0, 0),
                OuterWidth = 1,
                OuterColor = new Color32(150, 255, 255, 255),
            },
        });

        KmlFile kml = KmlFile.Create(placemark, false);
        using (var stream = System.IO.File.OpenWrite(telemFileName + ".kml"))
        {
            kml.Save(stream);
        }
}
catch (IOException)
{
    //file in use
}
catch (Exception ex)
{
    logger.Error("Exception: " + ex);
}