Domanda

ho ottenuto questo blocco di codice da NHibernate 3 Cookbook (un ottimo libro, btw), e anche se non sono riuscito a trovare anyting nella errata su di esso. Sto ottenendo l'errore "Impossibile accedere un flusso chiuso":

 var settings = new XmlWriterSettings { Indent = true };
 var serializer = new XmlSerializer(typeof(HbmMapping)); // todo: probably should abstract this out, at least optionally
 using (var memStream = new MemoryStream(2048))
 using (var xmlWriter = XmlWriter.Create(memStream, settings))
 {
     serializer.Serialize(xmlWriter, hbmMapping);
     memStream.Flush();
     memStream.Position = 0;

     using (var sr = new StreamReader(memStream))
     {
         return sr.ReadToEnd();
     }
 }

L'errore viene generato sulla linea sr.ReadToEnd ().

È stato utile?

Soluzione

Trovato un problema simile, dopo tutto, Perché lo smaltimento StreamReader rende un flusso illeggibile? . Fondamentalmente, ho rimosso il usando che è stato di circa il lettore e tutto va bene.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top