Home Can't find the reference to a library
Reply: 2

Can't find the reference to a library

programer Anel
programer Anel Published in 2017-12-07 20:25:01Z

Trying to shadow copy file from path A to Path B but it keep throwing me error message

{"Could not load file or assembly 'AlphaVSS.x64, Version=, Culture=neutral, PublicKeyToken=959d3993561034e3' or one of its dependencies. An attempt was made to load a program with an incorrect format."}

Code i try with it

  Public Sub copyFile(baza As String, destination As String)

        If IO.File.Exists(baza) Then

            Dim myFileInfo As FileInfo
            myFileInfo = New FileInfo(baza)

            Dim _volume As String = myFileInfo.Directory.Root.Name

            Dim _vssImplementation As IVssImplementation = VssUtils.LoadImplementation()
            Dim _backup As IVssBackupComponents = _vssImplementation.CreateVssBackupComponents()



            _backup.SetContext(VssVolumeSnapshotAttributes.Persistent Or VssVolumeSnapshotAttributes.NoAutoRelease)
            _backup.SetBackupState(False, True, Alphaleonis.Win32.Vss.VssBackupType.Full, False)

            Dim MyGuid01 As Guid = _backup.StartSnapshotSet()
            Dim MyGuid02 As Guid = _backup.AddToSnapshotSet(_volume, Guid.Empty)


            _backup.ExposeSnapshot(MyGuid02, Nothing, VssVolumeSnapshotAttributes.ExposedLocally, "L:")

            Dim sVSSFile2 As String = baza.Replace(_volume, "L:\")

            If (File.Exists(sVSSFile2)) Then
                System.IO.File.Copy(sVSSFile2, destination + "\" + System.IO.Path.GetFileName(baza), True)

                For Each prop As VssSnapshotProperties In _backup.QuerySnapshots
                    If (prop.ExposedName = "L:\") Then
                        Console.WriteLine("File found !")
                        _backup.DeleteSnapshot(prop.SnapshotId, True)
                    End If

                _backup = Nothing

                Console.WriteLine("File copied")


                Console.WriteLine("File not exist: " + baza)

            End If
        End If
    End Sub

I have the VSS nuget package and references

It throws error on line

Dim _vssImplementation As IVssImplementation = VssUtils.LoadImplementation()
djv Reply to 2017-12-07 21:08:43Z

Read the documentation. There are requirements when using the package

  1. Visual C++ 2017 Redistributables must be installed on the machine running any application using AlphaVSS

  2. Note that your application must be built using "Prefer 32-bit" unchecked if the Platform Target is set to Any CPU. Also note that your application must be built for 64-bit to work on a 64-bit system (or Any CPU with Prefer 32-bit off), and in 32-bit to work on a 32-bit system.

I initially had the same error as you, until I unchecked "Prefer 32-bit", then that line of code worked.

Visual Vincent
Visual Vincent Reply to 2017-12-07 21:16:59Z

An attempt was made to load a program with an incorrect format

This message means you're trying to load an executable (.dll, .exe, etc.) which cannot be run by the process (or by Windows itself depending on the situation).

The most common cause for this error is trying to load 32-bit code into a 64-bit process (or vice versa). 64-bit processes can only run 64-bit code, and 32-bit processes can only run 32-bit code.

Since it is the AlphaVSS.x64 assembly that's faulting, your project is most likely compiled into a 32-bit executable. You should either remove this reference or change your project to target x64 only (note that if you do the latter you won't be able to run your application on 32-bit machines).

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.376824 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO