-
Notifications
You must be signed in to change notification settings - Fork 471
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
When Castle.Core is loaded in a collectible Assembly Load Context, use AssemblyBuilderAccess.RunAndCollect by default #679
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2004-2021 Castle Project - http://www.castleproject.org/ | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
|
||
namespace Castle.DynamicProxy | ||
{ | ||
using System.Reflection.Emit; | ||
|
||
public static class AssemblyBuilderAccessDefaults | ||
{ | ||
#if NET | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note to self: need to research what this conditional compilation symbol is for, and whether it's needed. Does it guard the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is to guard against usage of AssemblyLoadContext (it is not in netatandard / netfx, only in .net core). However, it would be nice if the check could be done at runtime (in case of loading netatandard assemblies in a .net core executable). We have usage of reflection based wrappers at Unity for this kind of thing. I can probably do the same here. |
||
// If Castle.Core is loaded in a collectible AssemblyLoadContext, the generated assembly should be collectible as well by default. | ||
static readonly AssemblyBuilderAccess automatic = System.Runtime.Loader.AssemblyLoadContext.GetLoadContext(typeof(AssemblyBuilderAccessDefaults).Assembly).IsCollectible ? AssemblyBuilderAccess.RunAndCollect : AssemblyBuilderAccess.Run; | ||
#else | ||
static readonly AssemblyBuilderAccess automatic = AssemblyBuilderAccess.Run; | ||
#endif | ||
static AssemblyBuilderAccess? userSpecified; | ||
|
||
/// <summary> | ||
/// Get or set the default <see cref="System.Reflection.Emit.AssemblyBuilderAccess"/> to use when creating dynamic assemblies. | ||
/// On .Net Core, the default is <see cref="System.Reflection.Emit.AssemblyBuilderAccess.RunAndCollect"/> if Castle.Core is loaded in a collectible AssemblyLoadContext. | ||
/// </summary> | ||
public static AssemblyBuilderAccess Default | ||
{ | ||
get => userSpecified ?? automatic; | ||
set => userSpecified = value; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong year, should be
-2024
.