-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using .NET Core COM server from new .NET Core Single-File app results in two runtimes in process #40802
Comments
Tagging subscribers to this area: @swaroop-sridhar, @agocke |
This is not new - we've realized this problem pretty early on (unfortunately sort-of forgot since). Writeup of the problem I did some time ago: Native component hosting with single-file bundlesNative component hosting is a set of functionality which allows native code to dynamically load managed code into a process. If the process is .NET Core application, this allows external callers to load managed code into the existing runtime in the process. This is currently done by finding the We will need to find a new solution and also consider providing some way to solve backward compatibility. TODO - determine the size implications - this may need to include code in the bundle which will not be used by normal app startup (APIs to be called from the native hosting scenarios). New solutionFor now I suggest we wait for the diagnostics team to decide on a solution which the debuggers will use to find and contact the runtime in a process. That is essentially the same problem. If the debugger solution is acceptable for native hosting as well, we should use it. It's easier to maintain and support one way of doing it. In any case the single-exe bundle will need to include code to support native hosting, so basically the equivalent functionality to existing The new solution will also mean that all hosts ( Unfortunately, the Backward compatibility considerationNo matter what the new solution looks like, it's not going to be compatible with .NET Core 3.0 native hosting support. This means that for example COM object implemented in .NET Core 3.0 will not be able to load into a .NET 5 single-exe self-contained app (even though it would allow it through roll forward policies). We could either say that such scenario is now not supported for single-exe self-contained apps. With the new hosts as described above, we could support rebuilding the existing 3.0 components with a new SDK which would include the new hosts with the new functionality. There would be no need to change the components themselves, basically just a forced rebuild. There's also a possibility of solving this for at least some cases automatically. On machines which would have globally installed
The new .NET 5 This solution would also us to provide an easy workaround for users - if they run into the problem of .NET 5 single-exe not able to load some 3.0 component, just install .NET 5 runtime on the machine and it should work (since that will put .NET 5 Such solution is obviously not perfect, but it's the best one I can think of without changing already shipped 3.0 code. At the very least we should try to block this actively in 3.1, so that 3.1 COM objects get a consistent failure behavior. See dotnet/core-setup#8299 for more details. |
See also discussion in #3773: The outcome seems to be that it's OK to not actively block this scenario if we document it as unsupported (we don't support two runtimes in one process). |
Client:
.NET 5 console app which uses a COM object
Published as new single-file self-contained
Server:
.NET 5 COM Server implementing the COM object
Using reg-free COM, but this should not really matter.
The code actually works, but it loads two coreclr.dll modules into the process. The first coreclr comes from the client app (it's the coreclr.dll which is next to the bundle). The second coreclr is loaded from the global install.
The underlying issue is that comhost looks for
hostfxr
in the process, but in case of single-file it doesn't find it, so it assumes there's no .NET Core runtime in the process yet, loadshostfxr
from global install and continues on by loading the runtime from there as well.It works correctly when the client is no a single-file app, or if it's an FDD single-file app. So the only broken case is single-file SCD app.
The text was updated successfully, but these errors were encountered: