You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I get an IOException 'Entries cannot be opened multiple times in Update mode.' when I create a package part relationship, flush the package and again create a relationship. A similar issue was adressed in #24962, but not solved for this issue.
To reproduce it simply add the following unit test to the System.IO.Packaging.Tests project:
[Fact]
public void WriteRelationsTwice()
{
FileInfo tempGuidFile = GetTempFileInfoWithExtension(".zip");
using (Package package = Package.Open(tempGuidFile.FullName, FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
//first part
PackagePart packagePart = package.CreatePart(PackUriHelper.CreatePartUri(new Uri("MyFile1.xml", UriKind.Relative)),
System.Net.Mime.MediaTypeNames.Application.Octet);
using (packagePart.GetStream(FileMode.Create))
{
//do stuff with stream - not necessary to reproduce bug
}
package.CreateRelationship(PackUriHelper.CreatePartUri(new Uri("MyFile1.xml", UriKind.Relative)),
TargetMode.Internal, "http://my-fancy-relationship.com");
package.Flush();
//create second part after flush
packagePart = package.CreatePart(PackUriHelper.CreatePartUri(new Uri("MyFile2.xml", UriKind.Relative)),
System.Net.Mime.MediaTypeNames.Application.Octet);
using (packagePart.GetStream(FileMode.Create))
{
//do stuff with stream - not necessary to reproduce bug
}
package.CreateRelationship(PackUriHelper.CreatePartUri(new Uri("MyFile2.xml", UriKind.Relative)),
TargetMode.Internal, "http://my-fancy-relationship.com");
}
}
A simple solution would be the to change the line using (IgnoreFlushAndCloseStream s = new IgnoreFlushAndCloseStream(part.GetStream()))
in the method private void WriteRelationshipPart(PackagePart part)
in the class System.IO.Packaging.InternalRelationshipCollection
to the following lines:
using (Stream partStream = part.GetStream())
using (IgnoreFlushAndCloseStream s = new IgnoreFlushAndCloseStream(partStream))
The text was updated successfully, but these errors were encountered:
Maybe this should be moved to the area-System.IO.Compression, as this is almost the same issue as the referenced issue in the description. I do not know how important that is.
It seems reasonable, and seems to solve the problem. I'm sort of wondering if the right answer is actually "get rid of IgnoreFlushAndCloseStream". It might have been a thing introduced to manage the zip library it was using in .NET Framework that doesn't make sense given that it now uses System.IO.Compression. (Looks like that was my thought when I got the previous bug load balanced to me, too 😄)
Though if we add this using we've effectively done that, so maybe adding a second using here is easier than figuring out if it's important to not flush?
@Luciferius Since you've already done all the leg work, do you want to just open a PR?
I get an IOException 'Entries cannot be opened multiple times in Update mode.' when I create a package part relationship, flush the package and again create a relationship. A similar issue was adressed in #24962, but not solved for this issue.
To reproduce it simply add the following unit test to the System.IO.Packaging.Tests project:
A simple solution would be the to change the line
using (IgnoreFlushAndCloseStream s = new IgnoreFlushAndCloseStream(part.GetStream()))
in the method
private void WriteRelationshipPart(PackagePart part)
in the class
System.IO.Packaging.InternalRelationshipCollection
to the following lines:
The text was updated successfully, but these errors were encountered: