Debugging file processing issues in C # /. NET

I have a program that in turn accesses a DLL. It uses files in various ways, creating them, copying them, and setting them as attachments to the emailMessage object. I have a file in use error preventing a file from being overwritten.

Is there any tool or method to facilitate the process - for example, some kind of warning about creating / deleting pens containing a certain string? I looked at the process explorer, the process monitor (successor filemon), etc., but no luck.

I can continue the hunt, but thought there might be a better approach than continuing my informal research with code.

EDIT

Thanks for the comments. Regarding questions, the structure is a bit complicated. I have a client application that references the Engine DLL (also C #). Both of mine. The client creates instances of "attachments", each of which contains a link to a file for different files. The constructor for this capture refers to the file and places the copy in a temporary folder. Later, a set of "actions" creates an email - it adds each attachment as a "real" application to the EmailMessage object. At different times, I delete objects and set their references to zero, but if I do this too soon, I end up with null reference exceptions. If I do it too late, these damned things will be used! I am sure that I will be able to track down this particular error over time, but this prompted me to wonder if there is a useful standard method used by those who know. :)

+4
source share
2 answers

Procmon will tell you who (i.e. which process) is opening the file, and the (unmanaged) stack of the place where it was opened.

A common cause of this problem in C # /. NET is people opening file streams rather than deleting when they are done with them. This means that the file remains open until (at least) the next garbage collection, which may be aged.

+3
source

It sounds like you're looking for a tool to let you know what locks a file during debugging. If so, you can use Unlocker to determine the file lock process.

+2
source

Source: https://habr.com/ru/post/1391940/


All Articles