[Mono-dev] System.IO.Packaging throws NullReferenceExeption

CikaPero1 cika.pero1 at gmail.com
Thu Feb 9 13:03:38 UTC 2012


Hi,

Does anyone know why the code below throws an exception?

The code below works with MS Visual Studio but simply won't work with Mono
2.8.

using System;
using System.IO;
using System.IO.Packaging;
using System.Text;
using System.Xml;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            using (Package Package = Package.Open("out.zip",
FileMode.Create))
            {
                Uri partUri = new Uri("/_rels/.rels", UriKind.Relative);
                PackagePart packagePart = Package.CreatePart(partUri,
"application/vnd.openxmlformats-package.relationships+xml");

                using (Stream str = packagePart.GetStream())
                {
                    using (var writer = new XmlTextWriter(str, new
UTF8Encoding(false)))
                    {
                        writer.WriteStartDocument(true);
                        writer.WriteStartElement("Relationships");
                        writer.WriteAttributeString("xmlns",
"http://schemas.openxmlformats.org/package/2006/relationships");
                        writer.WriteStartElement("Relationship");
                        writer.WriteAttributeString("Type",
"http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties");
                        writer.WriteEndElement();
                        writer.WriteEndElement();
                    }
                }
            }
        }
    }
}

Strangely, it works when I change some strings:
a) "/_rels/.rels" -> "/rels/.rels"
b) or "xmlns" -> "x"
c) or "http://schemas.openxmlformats.org/package/2006/relationships" ->
"http://schemas.openxmlformats.org/package/2007/relationships"
d) or "http://schemas.openxmlformats.org/package/2006/relationships" ->
"http://schemas.openxmlformats.org/package/2007/relationships" and
"http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties"
->
"http://schemas.openxmlformats.org/package/2007/relationships/metadata/core-properties"

This will bring me to insanity!

Thanks for any help,
Cika Pero

--
View this message in context: http://mono.1490590.n4.nabble.com/System-IO-Packaging-throws-NullReferenceExeption-tp4372735p4372735.html
Sent from the Mono - Dev mailing list archive at Nabble.com.


More information about the Mono-devel-list mailing list