General questions

Deleting a package

In my application I am trying to delete the package from an EditorUserControl, and get an error "package is already opened".

This occurs after removing the EditorUserControl from the app and removing all parts from the package, confirming this using the Package.PartCount.

I cannot find any other references to the package or any other methods to remove internal references from the EditorUserControl.


Thanks

Michael


Dear Michael,


How do you try to delete a package ?

You can use:


Engine.DeletePackage()


This should work.


Regards,


Maël

Hi Maël,

I used both of these seperately and both gave me an error saying the package is still open. 

editor.Editor.Part.Package.RemovePart(_part);
editor.Editor.Engine.DeletePackage(_packageName);
editor.Engine.DeletePackage(_packageName);

 Thanks

Michael 

 

Dear Michael,


It seems to be related to garbage collection on ContentPart/ContentPackage objects.

If you force the garbage collection before calling "engine.DeletePackage" it should work:


// Force garbage collection
GC.Collect();
GC.WaitForPendingFinalizers();

// Delete the package on disk
engine.DeletePackage("...");


Regards,


Maël

Hi Maël,

Even adding this I still get the error "package is already open" when trying to delete the package. This is the full code which I use to try to delete the package:

  

var file = await ApplicationData.Current.LocalFolder.GetFileAsync(fileName);
await file.DeleteAsync();
var parent = this.Parent as StackPanel;
parent.Children.Remove(this);
editor.Editor.Part.Package.RemovePart(_part);
var box = new MessageDialog(editor.Editor.Part.Package.PartCount.ToString());
await box.ShowAsync();
GC.Collect();
GC.WaitForPendingFinalizers();
editor.Editor.Engine.DeletePackage(_packageName);
editor.Engine.DeletePackage(_packageName);

 On checking the number of parts the package has, the message box shows 0 and so doesn't seem to be the issue.

Thanks

Michael

Dear Michael,


It seems you still has references on the package and parts.

You still has at least one reference to a part through the "_part" member and also through his "editor.Editor.Part".

Can you please try to set all the references to package/parts to "null" before the calls to the garbage collector ?


Regards,


Maël

 Hi Maël,

I have added the relevant null references and have added all the other references I can see, and using the log file, but I still get the same error.

This is the full code I use and below that is the log file. At the end it appears to set a null part "nullptr", I am unsure if this could be the issue and if so how to solve it.


var file = await ApplicationData.Current.LocalFolder.GetFileAsync(fileName);
await file.DeleteAsync();
var parent = this.Parent as StackPanel;
parent.Children.Remove(this);
editor.Editor.Part.Package.RemovePart(_part);
_part = null;
editor.Editor.Part = null;
_package = null;
GC.Collect();
GC.WaitForPendingFinalizers();
editor.Editor.Engine.DeletePackage(_packageName);
editor.Engine.DeletePackage(_packageName);

 



----------------------------



Engine::createRenderer (132, 132.8, renderer provider)

Renderer::addListener start

Renderer::addListener end

Engine::createEditor (renderer provider)

Editor::Editor

Editor::setViewSize start (0, 0)

Editor::setViewSize end

Editor::setFontMetricsProvider start

Editor::setFontMetricsProvider end

Editor::addListener

Engine::openPackage start ("C:\Users\mgsto\AppData\Local\Packages\b1892125-1a3a-4548-877b-e63080afe1ae_77706dn16q6d8\LocalState\File1.iink") (2)

Engine::openPackage end

ContentPackage::createPart start ("Math")

Engine::getSupportedPartTypes

ContentPart::ContentPart ("Math")

ContentPackage::createPart end

Editor::setPart start ("bjqjqfvm")

Editor::configure start

Renderer::addListener start

Renderer::addListener end

Editor::configure end

IEditorListener::partChanged start

IEditorListener::partChanged end

Editor::setPart end

ContentPackage::save start

ContentPackage::save end

Editor::setViewSize start (795, 255)

Editor::setViewSize end

Renderer::drawCaptureStrokes start (0, 0, 796, 256)

Renderer::drawCaptureStrokes end

Renderer::drawTemporaryItems start (0, 0, 796, 256)

Renderer::drawTemporaryItems end

Renderer::drawModel start (0, 0, 796, 256)

Renderer::drawModel end

Renderer::drawBackground start (0, 0, 796, 256)

Renderer::drawBackground end

ContentPackage::removePart start ("bjqjqfvm")

ContentPackage::removePart end

Editor::setPart start ("nullptr")

Renderer::removeListener start

Renderer::removeListener end

IEditorListener::partChanged start

IEditorListener::partChanged end

Editor::setPart end

Engine::deletePackage start ("C:\Users\mgsto\AppData\Local\Packages\b1892125-1a3a-4548-877b-e63080afe1ae_77706dn16q6d8\LocalState\File1.iink")

EXCEPTION class std::invalid_argument "package is opened"



Thanks

Michael

Commenting to bump the post in case it was missed

Dear Michael,


I am not able to reproduce on my side. Would it be possible to have your project, so that we can investigate further?


Best regards,


Olivier

Hi Oliver,

You can have my project, how would you like me to send it to you?

Thanks

Michael

Dear Michael,


Just provide a link to your project on Dropbox or any other repository.


Once downloaded, I will remove the link.


Best regards,


Olivier

Hi Oliver,

Here is a link to google drive where the project is. The project is 7zip-ed. There is a READ ME file which explains the steps taken to create the iink part in the app and reproduce the issue:


Thanks

Michael

Login or Signup to post a comment