none
Why the dll can not be deleted

    Question

  • Please view the code below, why i can not delete the dll "SQLite.Interop.dll"?

    /////////////////////////////////////////////////////////////////////////////////////////////////

    Imports System.ComponentModel
    Imports System.Data.SQLite
    Imports System.IO

    Public Class Form1

        Private ObjSqliteConnection As New SQLiteConnection
        Private ObjSqliteCommand As New SQLiteCommand

        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load


            Try
                Dim _IS64 As Boolean = System.Environment.Is64BitOperatingSystem

                If File.Exists("SQLite.Interop.dll") Then
                    File.Delete("SQLite.Interop.dll")
                End If

                If _IS64 = True Then
                    File.WriteAllBytes("SQLite.Interop.dll", My.Resources.SQLite_Interop_x64)
                Else
                    File.WriteAllBytes("SQLite.Interop.dll", My.Resources.SQLite_Interop_x86)
                End If
            Catch
            End Try
        End Sub


        Private Sub Form1_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing
            ObjSqliteCommand.Cancel()
            ObjSqliteConnection.Close()

            ObjSqliteCommand.Dispose()
            ObjSqliteConnection.Dispose()

            GC.Collect()
            GC.WaitForPendingFinalizers()

            File.Delete("SQLite.Interop.dll")
        End Sub

        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim chromeHistoryFile As String = "History"
            Dim SqlCommandText As String = "select * from urls"

            ObjSqliteConnection = New SQLiteConnection("Data Source=" & chromeHistoryFile & ";Version=3;")
            ObjSqliteConnection.Open()
            ObjSqliteCommand = New SQLiteCommand(SqlCommandText, ObjSqliteConnection)
            Dim reader As SQLiteDataReader = ObjSqliteCommand.ExecuteReader()
            While reader.Read()
                Dim arrItem(0) As String
                arrItem(0) = reader("id").ToString
                Dim ObjLVI As New ListViewItem(arrItem)
                ListView1.Items.Add(ObjLVI)
            End While
        End Sub

    End Class

    Friday, March 24, 2017 12:27 PM

Answers

  • I have modified my code and delete the dll successfully using FreeLibray. But one problem, after program closed and the dll deleted 10 seconds approximately, system will show an exceptional icon in notification, said program has been stopped to work and sending error to Microsoft..., please view my project. Thank you.

    http://www16.zippyshare.com/v/GcowLUob/file.html

    I recompiled with a few updates and it works on my configuration :TestDeleteDll
    • Marked as answer by gaxjyxq Saturday, March 25, 2017 10:21 PM
    Saturday, March 25, 2017 2:45 PM

All replies

  • Probably because the interop assembly (DLL) is being used by your app. Why do you want to delete it?

    Paul ~~~~ Microsoft MVP (Visual Basic)

    Friday, March 24, 2017 12:36 PM
  • The DLL is needed for the work you are doing and was added in via references tab under project properties. If you delete it then the code presented can not work as it needs to be in the project references and available at runtime.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Friday, March 24, 2017 12:51 PM
    Moderator
  • The SQLite.Interop.dll has not been referenced, only embed into the resource. If you do not click the button, it can be deleted. How to upload my project? thank you.
    Friday, March 24, 2017 2:14 PM
  • The SQLite.Interop.dll has not been referenced, only embed into the resource. If you do not click the button, it can be deleted. How to upload my project? thank you.

    The interop assembly is a dependency for System.Data.SQLite.dll. You can find more detail at:

    http://system.data.sqlite.org/index.html/info/54e52d4c6f


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Friday, March 24, 2017 6:46 PM
  • Please download my project, the C# can delete it, why VB.Net can not delete it? thank you.

    http://www56.zippyshare.com/v/swcclxaD/file.html

    Friday, March 24, 2017 11:39 PM
  • The code is not correct (instances of SQLiteConnection & SQLiteCommand created even if "SQLite.Interop.dll" doesn't exist)

    but you cannot delete the DLL because it is still mapped in the process.

    This can be fixed by unloading the DLL with FreeLibrary() just before deleting it.

    (tested on Windows 10, VS 2015)

    Saturday, March 25, 2017 10:44 AM
  • I have modified my code and delete the dll successfully using FreeLibray. But one problem, after program closed and the dll deleted 10 seconds approximately, system will show an exceptional icon in notification, said program has been stopped to work and sending error to Microsoft..., please view my project. Thank you.

    http://www16.zippyshare.com/v/GcowLUob/file.html

    Saturday, March 25, 2017 2:01 PM
  • I have modified my code and delete the dll successfully using FreeLibray. But one problem, after program closed and the dll deleted 10 seconds approximately, system will show an exceptional icon in notification, said program has been stopped to work and sending error to Microsoft..., please view my project. Thank you.

    http://www16.zippyshare.com/v/GcowLUob/file.html

    I recompiled with a few updates and it works on my configuration :TestDeleteDll
    • Marked as answer by gaxjyxq Saturday, March 25, 2017 10:21 PM
    Saturday, March 25, 2017 2:45 PM
  • Yes, it works well, thank you.
    Saturday, March 25, 2017 10:21 PM