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

Use of Type.GetType in OverrideRuntimeNodeWriterTemplateTypeNamePhase causes crash when using ILMerge #546

Closed
General-Fault opened this issue Nov 7, 2024 · 2 comments
Labels

Comments

@General-Fault
Copy link

General-Fault commented Nov 7, 2024

Describe the bug
RazorLight cannot be used in an application that has been merged into a single assembly using ILMerge. ILMerge combines all referenced assemblies into one. This has the side-effect of changing the assembly name for all types that have been merged. So, when the OverrideRuntimeNodeWriterTemplateTypeNamePhase attempts to locate the Microsoft.AspNetCore.Razor.Language.DefaultRazorCSharpLoweringPhase type in the Register method, it fails because the AssemblyQualifiedName for that type no longer contains "Microsoft.AspNet.Core.Razor.Language" as the assembly name. The result is that OverrideRuntimeNodeWriterTemplateTypeNamePhase.Register throws a RazorLightException with the error "SetTemplateTypePhase cannot be registered as DefaultRazorCSharpLoweringPhase could not be located".

See also #322

To Reproduce
Create a console application for .Net Framework 4.8 using RazorLight. I used the RazorLightSandbox and updated the async using statements in Main() to comply with C#7.3.
Install the ILMerge.MSBuild.Task package (see https://github.com/emerbrito/ILMerge-MSBuild-Task/wiki)
Compile the project. There should be an ILMerge directory in the output.

Run the generated executable.

You should see the error

Exception
System.AggregateException: One or more errors occurred. ---> RazorLight.RazorLightException: SetTemplateTypePhase cannot be registered as DefaultRazorCSharpLoweringPhase could not be located
at RazorLight.Instrumentation.OverrideRuntimeNodeWriterTemplateTypeNamePhase.Register(RazorProjectEngineBuilder builder)
at RazorLight.DefaultRazorEngine.<>c__DisplayClass1_0.<get_Instance>b__0(RazorProjectEngineBuilder builder)
at Microsoft.AspNetCore.Razor.Language.RazorProjectEngine.Create(RazorConfiguration configuration, RazorProjectFileSystem fileSystem, Action`1 configure)
at RazorLight.DefaultRazorEngine.get_Instance()
at RazorLight.RazorLightEngineBuilder.Build()

Expected behavior
The library should be usable in an assembly that has been merged with ILMerge.

Information (please complete the following information):

Additional context
The application that this applies to is a portable tool used by our development team to create API documentation. The tool must be a single executable with all dependencies "wrapped in". Unfortunately, other dependencies of this tool are still targeting the .Net Framework v4.8.

@General-Fault
Copy link
Author

Admittedly, my "steps to reproduce" are not ideal. I will see if I can put together a simple project that replicates this behavior.

@toddams
Copy link
Owner

toddams commented Dec 2, 2024

ILMerge utility is not supported and I don't recall any plans to support it. Considering that it has been deprecated, I'm closing this one as "won't do"

@toddams toddams closed this as completed Dec 2, 2024
@toddams toddams added the wontfix label Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants