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

[Feature Request] Support Module Initialization in C# #36411

Closed
rladuca opened this issue Jun 13, 2019 · 4 comments
Closed

[Feature Request] Support Module Initialization in C# #36411

rladuca opened this issue Jun 13, 2019 · 4 comments

Comments

@rladuca
Copy link
Member

rladuca commented Jun 13, 2019

WPF used to build one of its assemblies, PresentationCore, as a hybrid between C++/CLI and C#. In an effort to reduce our dependencies on NetModule and make our build cleaner, we split the C++/CLI portion into a new DLL.

We relied on the use of Module Initialization in PresentationCore in order to properly configure defaults for WPF applications. Due to the split, this was no longer possible to do purely in code as we had used the C++/CLI portion to add this before.

This is now accomplished via IL injection via IL(D)Asm in order to add this back to a pure C# assembly. This isn't a very sustainable way of doing this and we're worried about this breaking in the future.

WPF would like a supported way to add a module initializer to a C# assembly. Perhaps a compiler flag/msbuild property that allows a developer to specify a type/function to call on initialization of the module.

You can see how WPF is doing this (a fairly common idiom):

Something like this would provide an easy way to access this functionality with, it seems to me, minimal risk to breaking existing builds.

@rladuca
Copy link
Member Author

rladuca commented Jun 13, 2019

CC. @vatsan-madhavan

@0xd4d
Copy link

0xd4d commented Jun 14, 2019

There are at least two nuget packages that can do this today:

https://www.nuget.org/packages/InjectModuleInitializer/
https://www.nuget.org/packages/ModuleInit.Fody/

@rladuca
Copy link
Member Author

rladuca commented Jun 18, 2019

dotnet/csharplang#2608

@gafter
Copy link
Member

gafter commented Jul 9, 2019

Indeed, this is a dup of dotnet/csharplang#2608

@gafter gafter closed this as completed Jul 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants