1

We have a library that is used by multiple companies. They have read-access to built DLL files which are obfusticated.

For each project this library is used, they should pay us. We want to have a telemetry system to make sure that they don't run this library in a non-agreed project.

We thought about somehow calling a telemetry URL each time a process on Windows is started that loads our DLL files. But we need to do it without requiring any coding or configuration from their side.

Is that possible? Can we implement a mechanism in .NET Core inside our library that whenever loaded inside the AppDomain is called once per process lifecycle?

Of course I know we can write code at Program.cs, but in our case, we don't have access to Program.cs and we can't ask them to code, or config anything.

  • .NET Core has no support for creating `AppDomain`s. From your question, as far as I can tell you'd be fine with code that runs once per process, right? No need to drag in `AppDomain`. The easiest way to hook up once-per-process code is running something in a static initializer -- getting these to run at the right time can be tricky, though. Your library would ideally need to have an obvious entry point. – Jeroen Mostert Dec 12 '18 at 12:54
  • No, I'm not trying to create app domains. Static initializers are good but they would be used only on their first access. That means that I have to use static constructors for a lot of my types. I'm looking for a hook opportunity in application/process lifecycle. – mohammad rostami siahgeli Dec 12 '18 at 13:11
  • Actually, you only need one type with a static constructor, as long as that type is accessed consistently. You could tack on a dummy reference in all your types (`static readonly verifier = Verifier.Instance`), or just the major ones that your library won't be used without. An unconditional process start hook would be nice, but I'm not aware of one for .NET Core. From 2.2 onwards there's [host startup hooks](https://github.com/dotnet/core-setup/blob/master/Documentation/design-docs/host-startup-hook.md), but you can't force those from external code (AFAIK). – Jeroen Mostert Dec 12 '18 at 13:16
  • Dear @JeroenMostert, the motivation part of your link is exactly what we need. It exactly mentions telemetry. Thank you so much. So I guess we can have that in .NET Core 3.0 – mohammad rostami siahgeli Dec 12 '18 at 19:27
  • Just as a reference, also there is the module constructor https://stackoverflow.com/questions/1915506/module-initializers-in-c-sharp. – thehennyy Dec 13 '18 at 10:49

0 Answers0