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

Exception starting 1.10.4 due to dotnet trimming #61

Closed
chrissimon-au opened this issue Nov 19, 2023 · 8 comments
Closed

Exception starting 1.10.4 due to dotnet trimming #61

chrissimon-au opened this issue Nov 19, 2023 · 8 comments
Labels

Comments

@chrissimon-au
Copy link
Contributor

Describe the bug

Unhandled exception. System.AggregateException: One or more errors occurred. (The type initializer for 'DryIoc.Registrator' threw an exception.)
 ---> System.TypeInitializationException: The type initializer for 'DryIoc.Registrator' threw an exception.
 ---> DryIoc.ContainerException: code: Error.UndefinedMethodWhenGettingTheSingleMethod;
message: Undefined Method '"Initializer"' in Type DryIoc.Registrator (including non-public=True)
   at DryIoc.Throw.ThrowIfNull[T](T, Int32 , Object , Object , Object , Object )
   at DryIoc.ReflectionTools.SingleMethod(Type, String, Boolean )
   at DryIoc.Registrator..cctor()
   --- End of inner exception stack trace ---
   at OmniSharp.Extensions.JsonRpc.JsonRpcServerServiceCollectionExtensions.AddJsonRpcMediatR(IContainer)
   at OmniSharp.Extensions.JsonRpc.JsonRpcServerServiceCollectionExtensions.AddJsonRpcServerCore[T](IContainer, JsonRpcServerOptionsBase`1)
   at OmniSharp.Extensions.LanguageServer.Shared.LanguageProtocolServiceCollectionExtensions.AddLanguageProtocolInternals[T](IContainer, LanguageProtocolRpcOptionsBase`1)
   at OmniSharp.Extensions.LanguageServer.Server.LanguageServerServiceCollectionExtensions.AddLanguageServerInternals(IContainer, LanguageServerOptions, IServiceProvider )
   at OmniSharp.Extensions.LanguageServer.Server.LanguageServer.From(LanguageServerOptions, IServiceProvider , CancellationToken)
   --- End of inner exception stack trace ---
   at Microsoft.FSharp.Control.AsyncResult`1.Commit() in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 454
   at Microsoft.FSharp.Control.AsyncPrimitives.QueueAsyncAndWaitForResultSynchronously[a](CancellationToken, FSharpAsync`1, FSharpOption`1) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 1140
   at Microsoft.FSharp.Control.FSharpAsync.RunSynchronously[T](FSharpAsync`1, FSharpOption`1 , FSharpOption`1 ) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 1511
   at Contextive.LanguageServer.Program.main(String[]) in /home/runner/work/contextive/contextive/src/language-server/Contextive.LanguageServer/Program.fs:line 36

To Reproduce
Start contextive v1.10.4

Expected behavior
It should start normally.

Desktop (please complete the following information):
All

Additional context
From local testing, is caused by the use of https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trim-self-contained

@chrissimon-au
Copy link
Contributor Author

A fix will be deployed with trimming turned off, but as it increases the binary size from 49MB to 106MB and the zip'd artifacts from 20MB to 42MB, this issue is used to track resolving properly and restoring trimming.

chrissimon-au added a commit that referenced this issue Nov 19, 2023
chrissimon-au pushed a commit that referenced this issue Nov 19, 2023
## [1.10.5](v1.10.4...v1.10.5) (2023-11-19)

### Bug Fixes

* exception on startup [#61](#61) ([2a69c0a](2a69c0a))
@chrissimon-au
Copy link
Contributor Author

Almost certainly caused by the recent update to .net 7.0 and this breaking change.

Trimming now trims all assemblies in console apps, by default. This change only affects apps that are published with PublishTrimmed=true, and it only breaks apps that had existing trim warnings.

While we did have PublishTrimmed=true we didn't have trim warnings, so this doesn't seem accurate.

Experimenting with the official revert approach (<TrimMode>partial</TrimMode>) does allow to trim the output (smaller file size) without the exception. This is likely the way forward.

However, what's curious is that the exception is specifically Undefined Method '"Initializer"' in Type DryIoc.Registrator. In theory, we should be able to mark the DryIoc dependency (DryIoc.Internal?) as a TrimmerRoot to prevent trimming of anything within that assembly. However, when attempting to do that, it fails saying the assembly cannot be found. Of note, the dependency is marked as PrivateAssets="All".

@chrissimon-au
Copy link
Contributor Author

The initial exception can be resolved by marking OmniSharp.Extensions.JsonRpc as a TrimmerRoot, however new exceptions arise. From running the test suite against the build trimmed binary, determined the following assemblies must be marked as TrimmerRoots, mostly due to the extensive use of reflection by OmniSharp :

    <TrimmerRootAssembly Include="OmniSharp.Extensions.JsonRpc" />
    <TrimmerRootAssembly Include="OmniSharp.Extensions.LanguageServer" />
    <TrimmerRootAssembly Include="OmniSharp.Extensions.LanguageProtocol" />
    <TrimmerRootAssembly Include="OmniSharp.Extensions.LanguageServer.Shared" />
    <TrimmerRootAssembly Include="Newtonsoft.Json" />
    <TrimmerRootAssembly Include="MediatR" />
    <TrimmerRootAssembly Include="Contextive.Core" />

The impact on file sizes is:

v1.10.3        (net6.0): trimMode partial (default)      : 56.0 MB
v1.10.4        (net7.0): trimMode full (default), broken : 49.0 MB
v1.10.5        (net7.0): no trimming, short term fix     : 78.6 MB
v1.10.5.bugfix (net7.0): trimMode partial                : 65.4 MB
v1.10.5.bugfix (net7.0): trimMode full with roots        : 55.5 MB

It seems the safest option would be to deploy with TrimMode partial - resulting in a filesize increase from 56MB to 65.4MB as a result of moving from .NET 6 to .NET 7.

However, with trimMode full but explicitly nominating the required trimmerRoots, we actually have a smaller file size (55.5MB), but the increased risk of a new assembly causing an issue. To mitigate this risk, propose updating the vscode e2e tests in the CI workflow to use the published/trimmed binary instead of dotnet run debug mode.

A preliminary step will attempt to run the language server immediately (with a 2s timeout, as it doesn't end on it's own). This will make any trimmer-caused exceptions that prevent startup extremely obvious. Other issues will get caught by the vscode e2e tests.

chrissimon-au pushed a commit that referenced this issue Nov 24, 2023
## [1.10.6](v1.10.5...v1.10.6) (2023-11-24)

### Performance Improvements

* **language-server:** reduce binary size and improve CI gate (fixes [#61](#61)) ([d34d8a4](d34d8a4))
chrissimon-au added a commit that referenced this issue Nov 24, 2023
Also improves the CI gate - now uses the published binary in the vscode extension e2e tests ensuring that issues with the published, trimmed, ready-to-run, self-contained binary, are caught earlier.
chrissimon-au pushed a commit that referenced this issue Mar 11, 2024
# [1.11.0](v1.10.5...v1.11.0) (2024-03-11)

### Features

* **intellij:** Add IntelliJ plugin (closes [#32](#32)) ([fad50b8](fad50b8))
* **intellij:** automatically download the language server if it's not found ([38db4b7](38db4b7))

### Performance Improvements

* **language-server:** reduce binary size (fixes [#61](#61)) ([5658484](5658484))
@chrissimon-au
Copy link
Contributor Author

🎉 This issue has been resolved in version 1.11.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

chrissimon-au pushed a commit that referenced this issue Mar 11, 2024
# [1.11.0](v1.10.5...v1.11.0) (2024-03-11)

### Features

* **intellij:** Add IntelliJ plugin (closes [#32](#32)) ([fad50b8](fad50b8))
* **intellij:** automatically download the language server if it's not found ([38db4b7](38db4b7))

### Performance Improvements

* **language-server:** reduce binary size (fixes [#61](#61)) ([5658484](5658484))
@chrissimon-au
Copy link
Contributor Author

🎉 This issue has been resolved in version 1.11.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

chrissimon-au pushed a commit that referenced this issue Mar 11, 2024
# [1.11.0](v1.10.5...v1.11.0) (2024-03-11)

### Features

* **intellij:** Add IntelliJ plugin (closes [#32](#32)) ([fad50b8](fad50b8))
* **intellij:** automatically download the language server if it's not found ([38db4b7](38db4b7))

### Performance Improvements

* **language-server:** reduce binary size (fixes [#61](#61)) ([5658484](5658484))
@chrissimon-au
Copy link
Contributor Author

🎉 This issue has been resolved in version 1.11.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

chrissimon-au pushed a commit that referenced this issue Mar 11, 2024
# [1.11.0](v1.10.5...v1.11.0) (2024-03-11)

### Features

* **intellij:** Add IntelliJ plugin (closes [#32](#32)) ([fad50b8](fad50b8))
* **intellij:** automatically download the language server if it's not found ([38db4b7](38db4b7))

### Performance Improvements

* **language-server:** reduce binary size (fixes [#61](#61)) ([5658484](5658484))
@chrissimon-au
Copy link
Contributor Author

🎉 This issue has been resolved in version 1.11.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

chrissimon-au pushed a commit that referenced this issue Mar 11, 2024
# [1.11.0](v1.10.5...v1.11.0) (2024-03-11)

### Features

* **intellij:** Add IntelliJ plugin (closes [#32](#32)) ([fad50b8](fad50b8))
* **intellij:** automatically download the language server if it's not found ([38db4b7](38db4b7))

### Performance Improvements

* **language-server:** reduce binary size (fixes [#61](#61)) ([5658484](5658484))
@chrissimon-au
Copy link
Contributor Author

🎉 This issue has been resolved in version 1.11.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

1 participant