-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AnyCpu - Add ModuleInitializer to resolve AnyCpu dlls at runtime
- Checks if the Assembly.GetEntryAssembly() is MSIL - Change CefSharp.Core.csproj to use LangVersion 9 so we can get the compiler to output the ModuleInitializer - Remove CefSharpPlatformCheck and other CefSharpAnyCpuSupport checks - CefSharp.Common.targets still has CefSharpAnyCpuSupport references for backwards compatibility with those with it set and Prefer32bit The default behaviour for this case is to simply copy the 32bit libs - Calling CefRuntime.SubscribeAnyCpuAssemblyResolver multiple times now will simply Unsubscribe the previous resolver This change should remove the need for users to perform any action when supporting AnyCpu.
- Loading branch information
Showing
5 changed files
with
81 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright © 2022 The CefSharp Authors. All rights reserved. | ||
// | ||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. | ||
|
||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace CefSharp | ||
{ | ||
/// <summary> | ||
/// When targeting NETFRAMEWORK this Module Initializer | ||
/// will call <see cref="CefRuntime.SubscribeAnyCpuAssemblyResolver(string)"/> | ||
/// when the <see cref="Assembly.GetEntryAssembly"/> has a <see cref="ProcessorArchitecture.MSIL"/>. | ||
/// </summary> | ||
public static class CefRuntimeAnyCpuInitializer | ||
{ | ||
/// <summary> | ||
/// True if the AnyCpu resolver was attached via this Module Initializer | ||
/// </summary> | ||
public static bool AssemblyResolverAttached { get; private set; } | ||
|
||
[ModuleInitializer] | ||
internal static void ModuleInitializer() | ||
{ | ||
var executingAssembly = Assembly.GetEntryAssembly(); | ||
//The GetEntryAssembly method can return null when a managed assembly has been loaded from an unmanaged application. | ||
//https://docs.microsoft.com/en-us/dotnet/api/system.reflection.assembly.getentryassembly | ||
if (executingAssembly != null && CefRuntime.SubscribeToAnyCpuResolverInModuleInitializer) | ||
{ | ||
var name = executingAssembly.GetName(); | ||
if (name.ProcessorArchitecture == ProcessorArchitecture.MSIL) | ||
{ | ||
if (!CefRuntime.IsAnyCpuAssemblyResolverAttached) | ||
{ | ||
AssemblyResolverAttached = true; | ||
|
||
CefRuntime.SubscribeAnyCpuAssemblyResolver(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters