Z
Z
Zakharov Alexander2018-10-12 13:51:25
.NET
Zakharov Alexander, 2018-10-12 13:51:25

How to catch the place in the program that leads to the loading of the dll?

Hello.
C# program using a shared library. According to the business logic, this library should not be loaded before it is passed by the control to the Main function, because the program must pass the initial initialization of the parameters. But apparently some class performs its loading in the top. As a result, the main program crashes (a dialog is displayed, with a small text, but there is nothing except the name of the program and the time of the "incident").
Is there any way to figure out where in the program or at what point dotnet is loading this library?
dotnet 4.6.2, VS 2017. windows 8.1 / Server 2016.
As far as I know, dll loading occurs according to certain rules, and not all at once. (Strong/non-strong names in this task do not exactly affect. I tried to rebuild this library in different ways).
Update 1:
Why is it about Main:
5bc0821f5fd43525354501.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
Zakharov Alexander, 2018-10-12
@AlexZaharow

The problem is solved in a purely philosophical way. Got a finger in the sky. Reading the article https://weblog.west-wind.com/posts/2012/Nov/03/Bac... (from 2012!!!) drew attention to the paragraph: And then I took a closer look at the Main function code: And then I got this puzzle! There was an assumption that dot.net before executing a function looks at the body of the function and checks if this code will require library loading? Stupid assumption, but... why not check it out. Moved the function body into a separate function: And now the library LongFile.AppendAllText method is not visible in the Main function! And a MIRACLE happened! The program started normally! It turns out from the rearrangement of the terms, the result changes))) Decided.

V
VoidVolker, 2018-10-12
@VoidVolker

How is this library connected? In links or manually? If manually, then from there you can immediately go to all the places where it is used. If in the links, then look where it is used and add monitoring there. The easiest way is to start by monitoring file system access.
https://docs.microsoft.com/en-us/sysinternals/down... - add filters for: process - your application, event type - file system, contains - dll file name.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question