dcsimg
Results 1 to 39 of 39
  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2017
    Posts
    20

    Strange Delete File Error

    Win 10 Pro 64 Bit Machine, VB Net 2012. Here's the code -

    Code:
     RM052_Selected_Sub = 0
            Do Until RM052_Selected_Sub = RM052_Selected_LastSub
                RM052_Selected_Sub = RM052_Selected_Sub + 1
                If UCase(Microsoft.VisualBasic.Right(RM052_Selected_File(RM052_Selected_Sub), 4)) = ".JPG" Then
                    Try
                        RM052_In_File_Name = Trim(RM052_SelectedDirectory_In _
                                                        & "\" _
                                                        & RM052_Selected_File(RM052_Selected_Sub))
                        My.Computer.FileSystem.DeleteFile(RM052_In_File_Name)
                    Catch ex As System.Exception
                        MessageBox.Show("RMMANAGER#FRM052-003-" _
                                       & ex.Message _
                                       & vbCrLf _
                                       & "**Problem While Deleting Original Pictures**" _
                                       & " IN-" _
                                       & RM052_In_File_Name)
                        RM_Error = "Y"
                        Exit Sub
                    End Try
                End If
            Loop
    The subs are defined as -

    Public RM052_Selected_Sub As Integer
    Public RM052_Selected_LastSub As Integer

    When executed, sometimes it works, sometimes it deletes 3 files (if there are more than 3) then deletes the .exe and stops - the TRY/CATCH is never triggered. No apparent viruses (it happens on more than one machine). The code was working fine until the new 1709 version of Win 10 was installed. My hunch that is the problem but maybe another set of eyes might see something else. 'LastSub' is not being exceeded so it is not blowing out the end of the table.
    Last edited by si_the_geek; Dec 7th, 2017 at 09:58 AM. Reason: added Code tags

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    39,936

    Re: Strange Delete File Error

    Welcome to VBForums

    When you post code please put it inside code tags so it is displayed in a more readable way - either using the Code/VBCode buttons in the post editor screen (or at the top of the Quick Reply box), or by putting them in manually, like this: [code] code here [/code] (I have added them to your post)


    It seems to me that the issue is likely to be due to what is in RM052_Selected_File() and/or RM052_Selected_LastSub , but you haven't posted the code that sets them up (or told us exactly what the contents are), so we can't really tell. I suspect there is an issue in the way you fill them.


    Note also that it is rather unusual to have RM052_Selected_Sub and RM052_Selected_LastSub declared as Public, as variables should be declared as locally as possible to avoid accidental modifications of the variables by other routines (which would cause bugs). In this case I would declare RM052_Selected_Sub at the start of the code you posted.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 2017
    Posts
    20

    Re: Strange Delete File Error

    Appreciate the note on posting code and will do that from now on. For sake of example. if the 'subs' were declared before the code as local, is there anything else that could cause the problem?

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Dec 2017
    Posts
    20

    Re: Strange Delete File Error

    BTW, I have verified the value of the 'subs' in the process and they are correct. As I said, it gets to 3 - and it is always 3 - and then crashes.

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    99,156

    Re: Strange Delete File Error

    You say that it crashes and you also say that you never enter your Catch block, which seems to suggest that an exception is being thrown outside the Try block. You should always handle the UnhandledException event of a VB app anyway, and that will allow you to catch unexpected exceptions, log them and close gracefully.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Dec 2017
    Posts
    20

    Re: Strange Delete File Error

    Quote Originally Posted by jmcilhinney View Post
    You say that it crashes and you also say that you never enter your Catch block, which seems to suggest that an exception is being thrown outside the Try block. You should always handle the UnhandledException event of a VB app anyway, and that will allow you to catch unexpected exceptions, log them and close gracefully.
    The 'add' above the TRY is executing correctly (already verified that), the next statement is an IF and then the TRY. That is why I am a bit confused as to how this is happening. The UnhandledException Code is in place and it never 'fires' either (I previously tested it by including a divide by zero to make sure it was working). The program just goes away with no existence as verified by Task Manager.

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    39,936

    Re: Strange Delete File Error

    Have you debugged to find out which line causes the crash? ...and what the filename is at the time?

    If you don't know how to debug, see here: https://msdn.microsoft.com/en-us/library/y740d9d3.aspx


    I have a suspicion that there is a problem with a particular file (possibly due to permissions), and that you may well see a problem if you try to delete it manually in Explorer.

  8. #8
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,580

    Re: Strange Delete File Error

    I want to know what this means:
    then deletes the .exe and stops - the TRY/CATCH is never triggered.
    You didn't show us the code that "deletes the .exe". What .exe? Surely the program isn't trying to delete itself? That's not going to work well.

    Don't ask questions about code you didn't show, we can't answer them.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Dec 2017
    Posts
    20

    Re: Strange Delete File Error

    Quote Originally Posted by Sitten Spynne View Post
    I want to know what this means:

    You didn't show us the code that "deletes the .exe". What .exe? Surely the program isn't trying to delete itself? That's not going to work well.

    Don't ask questions about code you didn't show, we can't answer them.
    The code that ends up deleting the .exe is the code shown - the DELETEFILE. As I said in the original post, it deletes 3 of the intended files and then deletes the .EXE which is not in the 'delete string' of the code. Sorry if I didn't make the explanation clear enough for you to understand that.

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Dec 2017
    Posts
    20

    Re: Strange Delete File Error

    Quote Originally Posted by si_the_geek View Post
    Have you debugged to find out which line causes the crash? ...and what the filename is at the time?

    If you don't know how to debug, see here: https://msdn.microsoft.com/en-us/library/y740d9d3.aspx


    I have a suspicion that there is a problem with a particular file (possibly due to permissions), and that you may well see a problem if you try to delete it manually in Explorer.
    As I said in the original post, it works on some desktops but not others and both desktops have the same permissions and are dealing with the same files. I've repeated this test many times to try to sort it out. It appears to be the 'DELETEFILE' that is aborting but before it does, it deletes the .EXE file of the program executing - which makes no sense at all. And with the TRY/CATCH and EXCEPTION EVENTS in place, you would think the malfunction would trigger one of them. Please note that this code worked perfectly fine for several years before Win 10 1709 update was installed. This is a bit out of the ordinary error as far as I can determine.

  11. #11
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    39,936

    Re: Strange Delete File Error

    While code can seem to work perfectly (even for years), that doesn't mean that it is perfect. I have seen several cases in my career where the code works for the general case and has no problems at all (for 12 years in one case), but a minor change in circumstances (which could be expected if you have enough knowledge in the area) means that the code suddenly no longer behaves as expected.

    It sounds to me as if you aren't debugging enough to find out exactly what your code is doing when the problem occurs. Finding that out is a very important step in determining the cause of the problem, which is required before a proper solution can be found.

    If for some reason you can't debug on the machine where the problem happens, add logging to the code so that you can work out the same as you would with debugging (which means logging after every line of code, including any variables that may have changed).


    Note that there may even be an external issue, such as a virus scanner (or similar) deleting your program... but debugging/logging is still an important step.

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Dec 2017
    Posts
    20

    Re: Strange Delete File Error

    It is the DELETEFILE statement where the program is aborting. And it appears that the .exe that is deleting itself not the Trend Micro anti-virus program. When I trace it, it flows right up to the 4th time through the loop to the DELETEFILE statement - the 'increment the sub' executes, the IF executes, the TRIM executes, then at the DELETEFILE it aborts and deletes the .exe, ignoring the TRY/CATCH and the HANDLEOTHEREXCEPTIONS. I'm sorry if I'm not made myself clear about that. I've been in software development for quite a long time and this one is a strange one.

  13. #13
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,580

    Re: Strange Delete File Error

    I have to be skeptical becasue the code you are showing me very carefully chooses files that end with the string ".JPG" before deleting them. It's cryptic by my standards, but let's look at this bit:
    Code:
    If UCase(Microsoft.VisualBasic.Right(RM052_Selected_File(RM052_Selected_Sub), 4)) = ".JPG" Then
    This does a lot of things on one line. I don't like doing that much on one line, it's easier to suss out what code does one line at a time. Let's use a sample string, "WindowsApplication10.exe", and walk through each step one line at a time.
    Code:
    Dim selectedFile As String = RM052_Selected_File(RM052_Selected_Sub)
    Dim extension As String = Right(selectedFile, 4)
    
    If UCase(extension) = ".JPG" Then
    With our sample string "WindowsApplication10.exe", the variables are:
    Code:
    selectedFile = "WindowsApplication10.exe"
    extension = ".exe"
    UCase(extension" = ".EXE"
    ".EXE" is never going to equal ".JPG". Based on that, my expert opinion is this part of the code can't be what is deleting the .exe file. It's happening, obviously, but I can't imagine it's actually this part of the code. You can double-verify this with a tiny change: add a message box to tell you the name of the file it's deleting each time it deletes a file.

    If I had to make a psychic guess, something along these lines can lead to the symptoms you describe:

    Your program uses some third-party component, maybe some hardware. That component doesn't play nice with this particular Windows update. It causes a crash and, for some reason, that crash results in your file being deleted. "Some reason" might be directly related, or it might be some other cryptic problem. But I bet the two are connected somehow, because you wouldn't be so surprised if "delete the .exe" was a normal part of your program.

    Otherwise, the problem is not in this code UNLESS you have another thread that could update RM052_Selected_File at random times. Then I can build a sequence of events where you inadvertently delete yourself. Do you have multiple threads?
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Dec 2017
    Posts
    20

    Re: Strange Delete File Error

    No multiple threads, no strange hardware or software components and I understand the JPG doesn't equal EXE. ;-) I will defer that maybe the program is not deleting itself (a nice trick if you're writing virus software), but I'm still stuck as to why the program always craters on the 4th iteration on some machines and never craters on other machines of like hardware/software. It's never the 5th, or the 12th, but always the 4th DELETEFILE statement. I've put enough displays in the code to lock it down to the DELETEFILE statement (one after each statement which brought me to my conclusion). And if that statement is the problem, I still don't understand why the TRY/CATCH or the UNHANDLED doesn't give me something back since they both have MESSAGEBOX statements in them. I even swapped out the memory on one machine exhibiting the error just to eliminate that issue but it made no difference. It exhibits the characteristics of memory getting overwritten as in a runaway table or something like that.

  15. #15

    Thread Starter
    Junior Member
    Join Date
    Dec 2017
    Posts
    20

    Re: Strange Delete File Error

    New Code With MSGBOX -

    Code:
      RM052_Selected_Sub = 0
            Do Until RM052_Selected_Sub = RM052_Selected_LastSub
                '@@
                MsgBox("SUB>" & RM052_Selected_Sub _
                       & "<LSUB>" & RM052_Selected_LastSub)
                RM052_Selected_Sub = RM052_Selected_Sub + 1
                MsgBox("AFTER INCR>" & RM052_Selected_Sub)
                If UCase(Microsoft.VisualBasic.Right(RM052_Selected_File(RM052_Selected_Sub), 4)) = ".JPG" Then
                    MsgBox("AFTER IF>" & RM052_Selected_Sub)
                    Try
                        RM052_In_File_Name = Trim(RM052_SelectedDirectory_In _
                                           & "\" _
                                           & RM052_Selected_File(RM052_Selected_Sub))
                        MsgBox("AFTER FNAME>" & RM052_Selected_Sub _
                               & "<FNAME>" & RM052_In_File_Name)
                        My.Computer.FileSystem.DeleteFile(RM052_In_File_Name)
                        MsgBox("AFTER DELETE>" & RM052_Selected_Sub _
                              & "<FNAME>" & RM052_In_File_Name)
                    Catch ex As System.Exception
                        MessageBox.Show("RMMANAGER#FRM052-003-" _
                                       & ex.Message _
                                       & vbCrLf _
                                       & "**Problem While Deleting Original Pictures**" _
                                       & " IN-" _
                                       & RM052_In_File_Name)
                        RM_Error = "Y"
                        Exit Sub
                    End Try
                End If
            Loop
    The last display is 'AFTER FNAME>3<FNAME> file name which ends in PO1010024.JPG' then the program goes away. The AFTER FNAME gives the value of the RM052_SELECTED_SUB and hence the iteration. It does complete the delete of the file name PO10110024.JPG verified by checking the folder but then it craters and the .EXE disappears. I can execute it in debug mode on my machine and it works fine.

  16. #16
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,580

    Re: Strange Delete File Error

    Do those files by any chance represent images that are being displayed in Pictureboxes somewhere?
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  17. #17

    Thread Starter
    Junior Member
    Join Date
    Dec 2017
    Posts
    20

    Re: Strange Delete File Error

    Nope not displayed in Pictureboxes. They reside on a server - are you thinking maybe the server (Server 2012 R2) is got a lock on one of them? BTW, I do really appreciate your responses. Just for grins, I went to the server and closed all 'holds' on the folders and tried it again and got the same results.
    Last edited by PDerryberry; Dec 7th, 2017 at 02:10 PM.

  18. #18
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,249

    Re: Strange Delete File Error

    After reading through this thread there's obviously more going on than PDerryberry's code that's posted is doing, it might be worth it to zip the project (delete the Bin and Obj folders first) and post it here.

  19. #19

    Thread Starter
    Junior Member
    Join Date
    Dec 2017
    Posts
    20

    Re: Strange Delete File Error

    Quote Originally Posted by JuggaloBrotha View Post
    After reading through this thread there's obviously more going on than PDerryberry's code that's posted is doing, it might be worth it to zip the project (delete the Bin and Obj folders first) and post it here.
    It's a pretty big project. This particular module resizes pictures to be smaller so that they can be emailed, then creates a folder where the originals are copied, then this step with the problem deletes the originals. All the steps work except for the deletes which used to work just fine until the WIN 10 1709 update. Since there are lots of forms involved and several BAS modules, it would probably be easier for me to whittle it down to just this form as a project and test it to see if the problem still exists. If it does, then diagnosing would be simple. If it works, then it has to be something 'stepping' on the code. Let me try that first so that I don't waste anyone's time. I'll be back! ;-)

  20. #20

    Thread Starter
    Junior Member
    Join Date
    Dec 2017
    Posts
    20

    Re: Strange Delete File Error

    I have taken the one form with the issue and made it a Project by itself. It exhibits the same problem at the same place. I'll be glad to 'zip it up' if someone can tell me how to post it properly. Thanks for help on this.

  21. #21
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    32,188

    Re: Strange Delete File Error

    I'm inclined to investigate the missing .exe further. It sounds like you've done some pretty detailed tracking of what is going on. Can you describe the steps you've gone through to verify that the .exe itself is being deleted?

    There are two things that this suggests to me, neither of which makes much sense, but might be worth considering.

    1) This kind of behavior does sometimes occur if you are effectively iterating through a collection that you are modifying. Often, that isn't allowed, but it kind of sounds like what is happening is that there is a pointer to a file, which then increments on to the .exe....incorrectly. How that would happen, I can't say, but knowing how you determined the .exe got deleted, and what you did about it, might help.

    2) If it isn't the code that is doing it, then what would it be? Something that is deleting an exe...as that exe is deleting files? That doesn't sound all that random. You mentioned that this seems correlated to a certain Win10 update (roughly). How good is the correlation?
    My usual boring signature: Nothing

  22. #22

    Thread Starter
    Junior Member
    Join Date
    Dec 2017
    Posts
    20

    Re: Strange Delete File Error

    When I look at the file folder on the server where the .exe is located, it is gone immediately after the program aborts. (Tested that a bunch of times). I recently updated all our desktops to the new 1709 release of WIN 10 and after that is when the problem appeared. It had been working fine for years without a hitch. As I said, I first thought it was a virus or a memory error so I tested for both and came up with nothing. I even swapped the memory in one of the desktops with the problem just to eliminate that. This is really making me scratch my head and other parts of my anatomy at this point. ;-)

  23. #23
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    32,188

    Re: Strange Delete File Error

    Is the .exe located in the same folder as the other files that are being deleted?
    My usual boring signature: Nothing

  24. #24

    Thread Starter
    Junior Member
    Join Date
    Dec 2017
    Posts
    20

    Re: Strange Delete File Error

    Quote Originally Posted by Shaggy Hiker View Post
    Is the .exe located in the same folder as the other files that are being deleted?
    No, that is what is so strange. It's in an entirely different folder on the server from the pictures.

  25. #25

    Thread Starter
    Junior Member
    Join Date
    Dec 2017
    Posts
    20

    Re: Strange Delete File Error

    I guess one test I could try is to turn off Windows Defender, Firewall and Trend Micro and see if the .exe still gets deleted. Any other MS programs you can think of to add to the list?

  26. #26
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,580

    Re: Strange Delete File Error

    I am also suspicious because these variable names suggest to me something very complicated is going on. I see a lot of red flags that tell me "this is VB6 code converted to .NET" and not "this is code written by a native .NET developer." Some of them may imply "the original author is long gone".

    * Every variable name starts with "RM052". That's odd. It makes me wonder if we're looking at a few dozen lines from a "God Module" with thousands of lines of code. In that kind of module, there might be a need to keep track of many different variables with the same name. So I am suspicious "RM052" indicates we're looking at a module so large, every variable has a naming convention where it's prefixed with which "feature" the variable belongs to. I'm willing to bet "RM052" means something like '??? Module, feature 052".

    Problem: This makes it very likely some code elsewhere in the module has accidentally misspelled its prefix and can modify some variables in an unexpected manner. It could be reasonably easy to detect with Visual Studio's "find all references", if the things that use variables are usually close to each other. If not, fat chance. In this case, several improvements help: "don't use god modules" and "prefer local varaibles" are chief among them.

    * Many of variables have odd names/inconsistent naming conventions. I have a feeling "RM052_Selected_Sub" and "RM052_Selected_LastSub" are named this way as yet another convention: they are "subvariables" that "belong" to inner scopes and the name is meant "so I don't accidentally use them in the wrong place"? Psychic guess. It's weird and I'm trying to explain it.

    Problem: See above.

    I say this because really, this is how I'd have written a method that does this:

    Code:
    For i = 0 To selectionEnd
        Dim currentFile = selectedFiles(i)
        If IsJpeg(currentFile) Then
            Try
                Dim filePath = Path.Combine(selectedDirectory, currentFile)
                File.Delete(filePath)
            Catch ex As Exception
                MessageBox.Show(...)
                Throw
            End Try
        End If
    Next
    This raises a lot of questions:
    • Where is selectionEnd defined? ("RM052_Selected_LastSub")
    • Where is selectedFiles() populated? ("RM052_Selected_File")
    • Where is selectedDirectory defined? ("RM052_SelectedDirectory")

    I could be wrong about the types or behaviors of any one of these variables, and any one of them could be the source of something goofy happening.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  27. #27

    Thread Starter
    Junior Member
    Join Date
    Dec 2017
    Posts
    20

    Re: Strange Delete File Error

    "Problem: This makes it very likely some code elsewhere in the module has accidentally misspelled its prefix and can modify some variables in an unexpected manner."

    If this was the case, then why would the problem suddenly appear after thousands of prior executions? I can assure you that is not what is happening. I am the 'original developer' and yes this program started out as VB6 and I converted it to VB net. And yes, I purposely use longer names for my variables for easier identification and I identify them by Module name so there is no confusion. I learned a long time ago it is better to 'verbose' so when you are staring at code at 3 AM morning trying to figure it out, it's a little easier. ;-) I have a naming system/convention that I use for that very reason. As I said above, I have pulled the form into a project all by itself and it still does the same thing. I appreciate that I may not program as you do but there is a method to my madness. If someone will explain the proper method for me to post the 'project' I'll be simply delighted to do that.
    Last edited by PDerryberry; Dec 7th, 2017 at 05:02 PM.

  28. #28
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,681

    Re: Strange Delete File Error

    This is probably how I'd have written it:
    Code:
            Dim selectedDirectory As String = "C:\Mine\Folder"
            Dim JpgFiles() As String = System.IO.Directory.GetFiles(selectedDirectory, "*.jpeg")
            For Each jf As String In JpgFiles
                Dim fullPath As String = System.IO.Path.Combine(selectedDirectory, jf)
                Try
                    System.IO.File.Delete(fullPath)
                Catch ex As Exception
                    MessageBox.Show("Unable to delete file " & jf)
                End Try
            Next
    Similar to Sitten's code, main difference is that I added a filter so that the list only contains jpeg files (by extension) in the first place, so there's no need to query if it is one or not.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  29. #29
    Frenzied Member
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    1,131

    Re: Strange Delete File Error

    If I am understanding this correctly, the .exe that processes and deleted the files is stored on a server, in a different folder than the .jpg files, and is run from the server?

    If that is the case, what happens if you place a COPY of the .exe file on a client computer, and run that copy to process and delete the files? Does the .exe on the client computer get deleted?

  30. #30

    Thread Starter
    Junior Member
    Join Date
    Dec 2017
    Posts
    20

    Re: Strange Delete File Error

    Here's my hunch that I will test tonight -
    Trend Micro thinks that the program is a virus because it is deleting so many files so quickly. So Trend Micro kills the process and deletes the .exe. That will be easy enough to test when things settle down. I'll report back the results once I do the test.

  31. #31
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,580

    Re: Strange Delete File Error

    I get the feeling from the code a list of files are being displayed in some control (probably a ListBox) and only a certain number of them are being deleted (as dictated by RM052_Selected_LastSub). That's why I asked about how the particular collections and other variables are being updated.

    @PDerryberry:

    Do you "feel like" nothing has mistakenly changed the variables, or have you "checked every line that sets the variable"? Feelings have no place in debugging.

    why would the problem suddenly appear after thousands of prior executions?
    We don't know that and we're trying to find out. I'm skeptical it's the code, but this wouldn't be the first time I've seen a bug go undetected for a while. If you're off the rails just right you venture into "undefined behavior". The problem with "undefined behavior" is no one guarantees it won't change. Often, you don't even realize you're experiencing it until "undefined" becomes "it crashes".

    There are dozens of other things that could be the issue. Maybe there's a new network issue. Maybe there's a bad sector on a drive. Maybe it's a very specific virus scanner definition update. Maybe there's a Windows bug with a very specific file name. You've got to chase all of these down, but I can only comment on what I see. And you haven't showed me every line of code that can manipulate these variables, so I'm still skeptical.

    If they are public, Module-level variables, every line in your program could access them. That makes it REALLY difficult to be sure nothing accidentally accesses them. The easiest way to find out would be to rename it by hand: update the line where it's declared, then update it in these lines of code. Where else does it fail? If nowhere else, good! Or you could use the IDE's Find features, Find References might even help. It's important to KNOW this isn't the cause.

    I am somewhat suspicious that is not the problem, because it's still hard to explain how the .exe gets deleted. That seems to make me think an overzealous virus scanner application is at play.

    RE: naming conventions and etc., it's off-topic. But look how much I was able to deduce about your project because you felt like you needed this naming convention! It is generally held by developers today that 100 files with 100 lines each are easier to manage than one file with 10,000 lines. It's easier to deduce "DeleteImages() is in ImageOperations.vb" than it is to consult your lookup table to figure out which 5-digit code corresponds to DeleteImages(). You don't need special naming conventions inside types, because each file has its own type, and that scopes its variables for you. And because the variables in Foo are in a different scope than the variables in Bar, it's a compiler error to try and access them in a haphazard manner. When you have a giant "god module", the only thing that stops you is your own discipline. It turns out when you're staring at the IDE at 3AM, that discipline's a lot thinner and it's hard to notice when you sneeze and RM052 when you meant to RM053.

    Let's put that discussion on the table and chase the likely causes. I like the idea of cutting this code out and putting it in a smaller project to see if that project has the same behavior. That is a very valuable step.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  32. #32
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    39,936

    Re: Strange Delete File Error

    Quote Originally Posted by PDerryberry View Post
    If this was the case, then why would the problem suddenly appear after thousands of prior executions?
    I've seen the same kind of thing happen many times over the years, and it is usually because of some kind of assumption that has been true so far.

    One example that comes to mind is a thread where it eventually turned out that an assumption was made about the format of a date when converted to a string (without specifying a format). Even tho it had worked perfectly for years, that was only because they'd been lucky that none of their users had ever had a different date format set in the system properties.


    And yes, I purposely use longer names for my variables for easier identification and I identify them by Module name so there is no confusion.
    You are actually making it more confusing by having them non-local.

    For example, in the posts above with alternate code, there are variables filePath and fullPath instead of your RM052_In_File_Name. While the shorter names are arguably less clear, the fact that they are defined within the code they are used in (and only exist for that specific section of code) means that you know for certain that they cannot be accidentally contaminated by code in other places.

    It seems that none of your variables have the clarity of "this isn't modified elsewhere", so it is something that needs to be carefully checked.


    If someone will explain the proper method for me to post the 'project' I'll be simply delighted to do that.
    Create a .zip file and add the files to it (assuming the files are all within the same folder, simply delete the Bin and Obj folders, then copy the rest to the zip).

    Once you've got the zip file, click "Go Advanced" under the reply box, and on the next page click "Manage Attachments".

  33. #33
    Frenzied Member
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    1,131

    Re: Strange Delete File Error

    If the server antivirus creates any logs of its activity, checking those might be worthwhile.

    Trend Micro's ServerProtect does have the capability to enable debug logging, but that must be manually activated and deactivated after use. I don't know if it keeps activity logs, but Trend Micro support should.

  34. #34

    Thread Starter
    Junior Member
    Join Date
    Dec 2017
    Posts
    20

    Re: Strange Delete File Error

    Well, I turned Trend Micro off and guess what? It was a WAD - working as designed and it worked just fine! So it had nothing to do with my code and the manner in which I coded at all. Evidently when the Windows 1709 update went in, it changed the behavior of Trend Micro. It saw a program deleting several files and decided to take preventative action - kill the program and quarantine/delete it - which makes sense now and explains why always the '3' deletes. I appreciate all the responses along the way, especially the one about Trend Micro. I should have pursued that earlier as I did not think it was my code at all and felt very strongly that it was 'external' to my code. So the moral of the story is if your app is going to delete a lot of files, beware that the anti-virus might shut you down and add it to a 'safe list'.

  35. #35
    Frenzied Member
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    1,131

    Re: Strange Delete File Error

    One clue here was that the program did not change and had been working for years.

    If it suddenly stops working, something changed - something other than the program. This does not mean the program does not have an issue, but it does mean that you should start looking at something that does change, like 1: antivirus signatures and detection algorithms, and 2: Windows.

    Clue 2: The programs deletes lots of files fast from a server. Antivirus software does not like that behavior, for good reason.

  36. #36

    Thread Starter
    Junior Member
    Join Date
    Dec 2017
    Posts
    20

    Re: Strange Delete File Error

    Quote Originally Posted by jdc2000 View Post
    One clue here was that the program did not change and had been working for years.

    If it suddenly stops working, something changed - something other than the program. This does not mean the program does not have an issue, but it does mean that you should start looking at something that does change, like 1: antivirus signatures and detection algorithms, and 2: Windows.

    Clue 2: The programs deletes lots of files fast from a server. Antivirus software does not like that behavior, for good reason.
    Exactly! I'm a little slow somedays but it finally hit me this afternoon to 'check the obvious'. ;-)

  37. #37
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,580

    Re: Strange Delete File Error

    Every time I've paid for antivirus I end up discovering it harms my computer. I've been using Windows Defender since it released and I've had fewer viruses with that than any of the others :/
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  38. #38
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    32,188

    Re: Strange Delete File Error

    Me too, though I haven't had a virus in years.
    My usual boring signature: Nothing

  39. #39

    Thread Starter
    Junior Member
    Join Date
    Dec 2017
    Posts
    20

    Re: Strange Delete File Error

    Just a follow up - I added the .exe to the Trend Micro Whitelist on the server, pushed the update out to the desktops, and now it works as designed - a WAD as we call it around here.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width