Skip to content
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

C# application referencing /clr:netcore creating its own static instances #64905

Closed
fiercekittenz opened this issue Feb 7, 2022 · 9 comments
Closed

Comments

@fiercekittenz
Copy link

I have a WPF net5.0-windows C# application that references a /clr:netcore targeted Managed C++ library. The C# application instantiates a static instance of a core system. When the Managed C++ accesses that instance, instead of seeing it already exists, it creates its own. Any usage of it goes through "native" handles and crashes when it accesses code that isn't available to /clr:netcore (example: Microsoft.Data.SqlClient).

What can be done to stop this behavior, or is this new and intended as of /clr:netcore?

@dotnet-issue-labeler dotnet-issue-labeler bot added area-Meta untriaged New issue has not been triaged by the area owner labels Feb 7, 2022
@ghost
Copy link

ghost commented Feb 7, 2022

Tagging subscribers to this area: @dotnet/area-meta
See info in area-owners.md if you want to be subscribed.

Issue Details

I have a WPF net5.0-windows C# application that references a /clr:netcore targeted Managed C++ library. The C# application instantiates a static instance of a core system. When the Managed C++ accesses that instance, instead of seeing it already exists, it creates its own. Any usage of it goes through "native" handles and crashes when it accesses code that isn't available to /clr:netcore (example: Microsoft.Data.SqlClient).

What can be done to stop this behavior, or is this new and intended as of /clr:netcore?

Author: fiercekittenz
Assignees: -
Labels:

area-Meta, untriaged

Milestone: -

@AaronRobinsonMSFT
Copy link
Member

@fiercekittenz This is known issue with C++/CLI and how it works in .NET Core 3.1/.NET 5+. WPF is particularly sensitive to this issue and is described at dotnet/wpf#1700.

@vitek-karas and @elinor-fung This seems like another manifestation of the single ALC issue we've been tracking. Is there a specific issue we are using in the runtime?

@AaronRobinsonMSFT AaronRobinsonMSFT added area-HostModel Microsoft.NET.HostModel issues and removed area-Host labels Feb 8, 2022
@AaronRobinsonMSFT
Copy link
Member

/cc @agocke

@ghost
Copy link

ghost commented Feb 8, 2022

Tagging subscribers to this area: @vitek-karas, @agocke, @VSadov
See info in area-owners.md if you want to be subscribed.

Issue Details

I have a WPF net5.0-windows C# application that references a /clr:netcore targeted Managed C++ library. The C# application instantiates a static instance of a core system. When the Managed C++ accesses that instance, instead of seeing it already exists, it creates its own. Any usage of it goes through "native" handles and crashes when it accesses code that isn't available to /clr:netcore (example: Microsoft.Data.SqlClient).

What can be done to stop this behavior, or is this new and intended as of /clr:netcore?

Author: fiercekittenz
Assignees: -
Labels:

area-Host, untriaged

Milestone: -

@AaronRobinsonMSFT
Copy link
Member

AaronRobinsonMSFT commented Feb 8, 2022

I believe #61105 is tracking this general problem.

@elinor-fung
Copy link
Member

Also related: #62754

@elinor-fung elinor-fung added area-AssemblyLoader-coreclr and removed area-HostModel Microsoft.NET.HostModel issues labels Feb 8, 2022
@ghost
Copy link

ghost commented Feb 8, 2022

Tagging subscribers to this area: @vitek-karas, @agocke, @VSadov
See info in area-owners.md if you want to be subscribed.

Issue Details

I have a WPF net5.0-windows C# application that references a /clr:netcore targeted Managed C++ library. The C# application instantiates a static instance of a core system. When the Managed C++ accesses that instance, instead of seeing it already exists, it creates its own. Any usage of it goes through "native" handles and crashes when it accesses code that isn't available to /clr:netcore (example: Microsoft.Data.SqlClient).

What can be done to stop this behavior, or is this new and intended as of /clr:netcore?

Author: fiercekittenz
Assignees: -
Labels:

area-AssemblyLoader-coreclr, untriaged

Milestone: -

@fiercekittenz
Copy link
Author

Thanks. I did stumble upon that yesterday through some clever web searches. It should be documented somewhere though. I blew 2 days of engineering time trying to figure out what was going on until I fumbled into the other issue thread.

@elinor-fung
Copy link
Member

Closing based on #66486 - C++/CLI DLLs targeting .NET 7 will be loaded into the default AssemblyLoadContext.

Documentation was added in dotnet/docs#28850

@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Jun 10, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jul 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Development

No branches or pull requests

3 participants