Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.IO.IOException when creating relationships multiple times #27397

Closed
twilker opened this issue Sep 14, 2018 · 4 comments · Fixed by dotnet/corefx#33156
Closed

System.IO.IOException when creating relationships multiple times #27397

twilker opened this issue Sep 14, 2018 · 4 comments · Fixed by dotnet/corefx#33156
Assignees
Milestone

Comments

@twilker
Copy link
Contributor

twilker commented Sep 14, 2018

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))
@twilker
Copy link
Contributor Author

twilker commented Oct 2, 2018

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.

@ahsonkhan
Copy link
Member

cc @bartonjs - since you fixed https://github.com/dotnet/corefx/issues/26952, I am assuming you can help here as well :)

Does @Luciferius, proposed solution make sense?

@bartonjs
Copy link
Member

Mighty big assumption there 😄.

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?

@twilker
Copy link
Contributor Author

twilker commented Oct 25, 2018

@bartonjs I will do that as soon as I can make the time for it ;-)

@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 3.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants