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

Enhancement Allow unload AssemblyLoadContext which contains Avalonia content #13935 #13974

Merged
merged 25 commits into from
Apr 5, 2024

Conversation

MakesYT
Copy link
Contributor

@MakesYT MakesYT commented Dec 16, 2023

What does the pull request do?

Allows AssemblyLoadContext that contains Avalonia content to be unloaded

What is the current behavior?

Allowed AssemblyLoadContext that contains Avalonia content to be unloaded
Allowed you to uninstall Avalonia property registration on a specific type
Allowed to delete the IAssemblyDescriptorResolver StandardAssetLoader _assemblyNameCache

What is the updated/expected behavior with this PR?

Usage
Add the following methods to the AssemblyLoadContext Unloading event

Unloading += (sender) =>
        {
            AvaloniaPropertyRegistry.Instance.UnregisterByModule(sender.Assemblies.First().DefinedTypes);
            Application.Current.Styles.Remove(MainWindow.Style);//You need to manually remove all style references from AssemblyLoadContext
            MainWindow.Style= null;
            AssetLoader.InvalidateAssemblyCache(sender.Assemblies.First().GetName().Name);
           
        };

How was the solution implemented (if it's not obvious)?

Checklist

Breaking changes

None

Obsoletions / Deprecations

Added the RemoveAssembly method in IAssetLoader

 /// <summary>
        /// Removes the assembly from the cache.
        /// </summary>
        /// <param name="name">The Assemblies.First().GetName().Name</param>
        void InvalidateAssemblyCache(string name);
        /// <summary>
        /// Removes all assemblies from the cache.
        /// </summary>
        void InvalidateAssemblyCache();

@grokys @kekekeks & @danwalmsley

Fixed issues

@MakesYT
Copy link
Contributor Author

MakesYT commented Dec 16, 2023

@dotnet-policy-service agree

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.1.999-cibuild0043008-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@timunie
Copy link
Contributor

timunie commented Dec 18, 2023

@MakesYT you may want to work on top of #13970 as this may change some important steps. Just an idea, haven't checked it on my own deep enough

@MakesYT MakesYT marked this pull request as ready for review December 23, 2023 05:21
@MakesYT MakesYT changed the title Try fix #13935 Enhancement Allow unload AssemblyLoadContext #13935 Dec 23, 2023
@MakesYT
Copy link
Contributor Author

MakesYT commented Dec 23, 2023

Usage
Add the following methods to the AssemblyLoadContext Unloading event

Unloading += (sender) =>
{
     AvaloniaPropertyRegistry.Instance.UnregisterByModule(sender.Assemblies.First().DefinedTypes);
};

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.1.999-cibuild0043140-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.1.999-cibuild0043347-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.1.999-cibuild0044424-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@maxkatz6 maxkatz6 requested a review from kekekeks February 11, 2024 02:33
@maxkatz6
Copy link
Member

cc @kekekeks

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.2.999-cibuild0046354-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MakesYT MakesYT marked this pull request as draft March 19, 2024 06:27
@MakesYT MakesYT marked this pull request as ready for review March 19, 2024 09:53
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.2.999-cibuild0046361-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MakesYT MakesYT changed the title Enhancement Allow unload AssemblyLoadContext #13935 Enhancement Allow unload AssemblyLoadContext which contains Avalonia content #13935 Mar 19, 2024
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.2.999-cibuild0046378-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MakesYT MakesYT marked this pull request as draft March 20, 2024 12:39
@MakesYT MakesYT marked this pull request as ready for review March 31, 2024 15:04
@MakesYT MakesYT requested review from kekekeks and maxkatz6 April 2, 2024 15:01
@maxkatz6
Copy link
Member

maxkatz6 commented Apr 3, 2024

@MakesYT since IAssetsLoader is a public API, and it's not possible to add interface method to a public API without breaking ABI, these changes are considered a breaking change. But it should be a pretty minor one, that we can accept. Can you run nuke ValidateApiDiff command in the repository root? It will update api-diff related files, which you then can commit in this PR. So CI builds can be green again.

@AvaloniaUI AvaloniaUI deleted a comment from Arafath101 Apr 3, 2024
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.2.999-cibuild0046969-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MakesYT
Copy link
Contributor Author

MakesYT commented Apr 5, 2024

@maxkatz6 now it's ok

@maxkatz6 maxkatz6 merged commit 299c16d into AvaloniaUI:master Apr 5, 2024
10 checks passed
@maxkatz6 maxkatz6 added the backport-candidate-11.1.x Consider this PR for backporting to 11.1 branch label Apr 5, 2024
maxkatz6 pushed a commit that referenced this pull request Apr 6, 2024
…content #13935 (#13974)

* Try fix #13935

* Fix

* Fix

* add sample

* Fix

* try load Style by reflection

* try

* Fixed an error when registering properties when uninstalling assemblies

* Allowed to delete the IAssemblyDescriptorResolver StandardAssetLoader _assemblyNameCache

* Resolving merge conflicts

* Fix

* Add exegesis

* optimize

* fix

* Resolving merge conflicts

* nuke
@maxkatz6 maxkatz6 added backported-11.1.x and removed backport-candidate-11.1.x Consider this PR for backporting to 11.1 branch labels Apr 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants