-
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
Support for Mono's DllImport(@"__Internal") ? #7267
Comments
cc @yizhang82 |
@yizhang82 Please fix the milestone as applicable. |
@jkotas @AaronRobinsonMSFT I'm looking into working on this next. It fits in well with our goal of improving our hosting story for .NET Core 3.0 as well as improving compatibility with Mono. What do you think? |
The managed NativeLibrary APIs that we are adding for 3.0 allow people to resolve A great hosting story is not a theme for 3.0. I would wait for doing anything more here until a great end-to-end hosting story is a theme. |
@jkotas I would argue the managed COM hosting theme I am working on is probably just that scenario. Being able to load a managed COM server and then have that COM server communicate with the native host seems very natural to me and something I have done. I think this is actually a valuable task for the following reasons:
I don't see a real strong reason not to start on this, unless there is something more pressing at the moment. |
I do not think In any case, this would need more detailed design proposal first. |
Do we have any docs or guidance written down anywhere on writing up design proposals? I know we have some docs for the corefx API review process. Is it a similar process or something different? I just want to make sure that when I eventually write up a design doc for something that I am doing it correctly. |
There is no prescribed format. Smaller proposals just get written as a few paragraphs in the tracking issue. Larger proposals get written as standalone docs, e.g. look under https://github.com/dotnet/coreclr/tree/master/Documentation/design-docs I think this one would be likely on the smaller proposal side. |
@jkotas Sure it is. I have a native application that is using a managed COM server. My managed COM server relies on some native function in my native application. The managed COM server is merely a subset of the native hosting scenario. Am I missing something? |
Then you are mixing COM hosting with a custom hosting. It is not a pure COM hosting anymore. |
@jkotas I don't understand that statement. If I have a native EXE that does a |
The host and component should communicate via COM interfaces only in the pure COM hosting. Once there are side channels, it is not a pure COM hosting anymore.
The server and host can exchange COM interface to call back and forth. It was the way to do this for last 20 years, no |
Is there any chance of revisiting this in light of .NET 5? Embedding is a much more common scenario for Mono, and from our perspective this is important functionality for mobile. |
@CoffeeFlux Are you talking about embedding in general; or specifically about |
|
If it helps, I think it is fine for Much more fundamental difference between CoreCLR and Mono native library loading is that Mono loads everything as |
I don't really get what's the issue with supporting The problem I'm facing right now is that I'm trying to make Python.NET work reasonably with .NET Core. However, in the usual "Python embeds .NET" use-case, the missing In Mono, this is not an issue as I can just use |
Yes, it is how DllImportResolver is meant to be used to customize DllImport lookups. I believe that a small amount of extra code should be acceptable to make more advanced interop scenarios like this one work. |
@jkotas, for this it would essentially be doing the following, is that correct? static void Main(string[] args)
{
NativeLibrary.SetDllImportResolver(Assembly.GetEntryAssembly(), OnResolveDllImport);
int result = AddIntegers(3, 5);
Console.WriteLine(result);
}
public static IntPtr OnResolveDllImport(string libraryName, Assembly assembly, DllImportSearchPath? searchPath)
{
if (libraryName == "__Internal")
{
var module = typeof(ClassLibrary1.Class1).Module;
return Marshal.GetHINSTANCE(module);
}
// Insert additional resolution logic as needed
return IntPtr.Zero;
}
[DllImport("__Internal")]
public static extern int AddIntegers(int lhs, int rhs); Testing with C++/CLI it appears to all work and I wouldn't expect any difference if the entry points were bound another way (such as python or embedding the CLR in a native host). |
Yes, it is the pattern to use for this. For the @filmor 's python case, it would need to PInvoke |
Sure, I can (and will) do this, it just seems complicated for something that has a well-defined and -established meaning on all platforms, as far as I know. Now I have to write two loader variants, that also can't be pure .NET Standard (without a lot of reflection) and select them at runtime. What is particularly annoying is that I can't even piggy-back on the accompanied |
What is it specifically? (just want to make sure that I understand your point) |
Just a small note, the I accept that this confusion is mostly our fault with naming. For clarity can we assume your scenario for a "standard" approach means sharing between .NET Core and Mono? |
Yeah, sorry, I'm currently working on this so I'm jumping a bit around between approaches. For me it would be perfect if .NET Core handled The rest of my comment was more about that the alternative (i.e. custom code for .NET Core) for this is still a bit more work than it should be since I can't do it in a platform-independent manner from within C# as the |
@jkoritzinsky @elinor-fung Lets think about what this means for the .NET 6 time frame. I think we are getting close to the critical mass of requests. |
We have an API proposal to make it much easier to enable this experience in #56331, which will be added in 7.0. |
Can we add support for loading symbols within the hosting application as documented here?
This will make it easier for existing applications to expose method symbols to managed code without having to 1) separating desired methods to a separate dynamic library or 2) passing tables of function pointers to managed code on initialization.
The text was updated successfully, but these errors were encountered: