I'm working on an app that injects a native dll into another process.
This native dll, in turn, loads the managed dll (which, in turn, loads the Ijwhost.dll).
My managed dll is compiled using .NET 8. (8.0.3).
Everything is injected and works fine if the process where the dll is injected is either an unmanaged process or managed using a .NET Framework.
But one case causes a problem for me. I made a test program using WPF/C#, the simplest one, showing just text on a window.
It is compiled for .NET 8 (8.0.3), just like the managed dll that I inject into the process is compiled.
In this case, the process is closed after injection, and this message is written in the output window:
Hosting components are already initialized. Re-initialization to execute an app is not allowed.
At the same time, I cannot catch any specific exception in the debugger.
The process simply stops and the debugger turns off with this message in the output window.
Also, an error with this text is added to the Windows event log, in the section for notifications about errors in applications.
That is, as I understand it, the problem is because the process itself is compiled with .NET 8 (8.0.3), and my managed dll injects an Ijwhost.dll belonging to the same framework. And when injecting the Ijwhost.dll, somewhere it is determined that the host has already been loaded (considering that this is a managed process.).
And the process crashes with an error.
By the way, if I run this test WPF app without injecting any dlls, then I don’t see that it loads any Ijwhost.dll itself that could conflict with mine.
In my opinion, this should not happen.
After all, if the process uses another framework or even a native one, everything loads correctly.
Why can't it just ignore the second attempt to load the CLR host without throwing an error?
Unfortunately, I wouldn't like to post the complete code of the app, since it is large.
Could we just discuss this theoretically, please?
Could you please fix this behavior?
I'm working on an app that injects a native dll into another process.
This native dll, in turn, loads the managed dll (which, in turn, loads the
Ijwhost.dll).My managed dll is compiled using .NET 8. (8.0.3).
Everything is injected and works fine if the process where the dll is injected is either an unmanaged process or managed using a .NET Framework.
But one case causes a problem for me. I made a test program using WPF/C#, the simplest one, showing just text on a window.
It is compiled for .NET 8 (8.0.3), just like the managed dll that I inject into the process is compiled.
In this case, the process is closed after injection, and this message is written in the output window:
Hosting components are already initialized. Re-initialization to execute an app is not allowed.At the same time, I cannot catch any specific exception in the debugger.
The process simply stops and the debugger turns off with this message in the output window.
Also, an error with this text is added to the Windows event log, in the section for notifications about errors in applications.
That is, as I understand it, the problem is because the process itself is compiled with .NET 8 (8.0.3), and my managed dll injects an
Ijwhost.dllbelonging to the same framework. And when injecting theIjwhost.dll, somewhere it is determined that the host has already been loaded (considering that this is a managed process.).And the process crashes with an error.
By the way, if I run this test WPF app without injecting any dlls, then I don’t see that it loads any
Ijwhost.dllitself that could conflict with mine.In my opinion, this should not happen.
After all, if the process uses another framework or even a native one, everything loads correctly.
Why can't it just ignore the second attempt to load the CLR host without throwing an error?
Unfortunately, I wouldn't like to post the complete code of the app, since it is large.
Could we just discuss this theoretically, please?
Could you please fix this behavior?