alphaleonis/AlphaVSS

AlphaVSS and Dispose()?

VladimirK69 opened this issue · 4 comments

My goal is to read SQL Server's files (mdf/ldf) with AlphaVSS and to remove snapshot after that (if I understand it correctly). So my code (based on example) in object's constructor

    private readonly VssBackup Vss;
    private readonly Stream VssStream;
...
          Vss = new VssBackup();
          Vss.Setup(Path.GetPathRoot(fileName));
          VssStream = Vss.GetStream(fileName);
          Length = VssStream.Length;

and in destructor

          VssStream.Close();
          Vss.Dispose();

Without Dispose it works without exceptions, but Delete for snapshot never called. With Dispose() I have "System.NullReferenceException: 'Object reference not set to an instance of an object.'" in Snapshot.cs

      public void Delete()
      {
         _backup.DeleteSnapshotSet(_set_id, false);
      }

Am I need to use Dispose and is everything OK with code?

I think you need to provide more of your code, since I can't see what's going wrong from the bits you posted unfortunately.

I tried to create new demo project based on Example2 from AlphaVSS-Samples-develop
VssDispose.zip
but this time I have error "System.ArgumentException: 'Paths that begin with \?\GlobalRoot are internal to the kernel and should not be opened by managed applications.'" on VssStream = Vss.GetStream(openFileDialog1.FileName);
But somehow that part works in my original project that had previous AplhaVSS and AlphaFS (even without it and AlphaVSS.Native.NetFx.2.0.0, in installed NuGet packages only AplhaVSS) updated to recent version. I can only guess it takes something from cache maybe.

In original project exceptions on Dispose it seems fixed after I deleted ".vs" folder and rebuild project.

stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.