-
Notifications
You must be signed in to change notification settings - Fork 10.4k
[Blazor] Fix HotReloadManager accessibility in Server project by including shared source #63287
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: javiercn <[email protected]>
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.
@copilot remove this file.
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.
Removed the test file as requested in commit 62e8bab.
public RootTypeCache() | ||
{ | ||
lock (_instances) | ||
{ | ||
_instances.Add(new WeakReference(this)); | ||
} | ||
} |
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.
public RootTypeCache() | |
{ | |
lock (_instances) | |
{ | |
_instances.Add(new WeakReference(this)); | |
} | |
} |
Co-authored-by: javiercn <[email protected]>
Co-authored-by: javiercn <[email protected]>
} | ||
} | ||
#endif | ||
|
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.
Don't do #if COMPONENTS
. Add an internal instance method Clear
to clear the concurrent dictionary cache. Look for all the callsites where the RootTypeCache is used, and add the MetadataUpdateHandler in those situations.
You can set things up in the constructor since those types are Singletons
.
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.
private readonly RootTypeCache _RootTypeCache; |
Look for places where you can make private RootTypeCache fields static if they aren't. Like
private readonly RootTypeCache _RootTypeCache; |
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.
I've implemented the requested changes. Removed #if COMPONENTS
directives, added an internal Clear()
method to RootTypeCache, and registered MetadataUpdateHandler at the singleton registration points in ComponentServiceCollectionExtensions and PersistentServicesRegistry. WebAssembly project builds without hot reload support as expected since it doesn't include HotReloadManager.
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.
I've implemented the requested changes:
- Made
ServerComponentDeserializer._RootTypeCache
field static and added hot reload support in static constructor (b2d6288) - Made
DefaultWebAssemblyJSRuntime._rootComponentCache
field static (WebAssembly doesn't include HotReloadManager so no hot reload registration) - Updated constructor signatures and test files to remove RootTypeCache parameters where they're now static
- Updated usages to reference the static fields instead of instance fields
The implementation follows the same pattern used by PersistentServicesRegistry
which already has a static _persistentServiceTypeCache
with hot reload support in its static constructor.
Co-authored-by: javiercn <[email protected]>
…uctors Co-authored-by: javiercn <[email protected]>
…eters Co-authored-by: javiercn <[email protected]>
rc\Components\Server\src\DependencyInjection\ComponentServiceCollectionExtensions.cs(135,13): error CS0122: 'HotReloadManager' is inaccessible due to its protection level |
#if COMPONENTS | ||
namespace Microsoft.AspNetCore.Components.Infrastructure; | ||
#else | ||
namespace Microsoft.AspNetCore.Components; | ||
#endif |
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.
@copilot undo this change
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.
Reverted the namespace declaration back to block-scoped format as requested (commit 993ba49).
…red source Co-authored-by: javiercn <[email protected]>
Fixed the HotReloadManager accessibility error by including HotReloadManager.cs as a linked source file in the Server project. The error occurred because HotReloadManager is marked internal and was only available in the Components assembly. Added the shared source file to enable hot reload registration directly in static constructors where the static RootTypeCache fields are defined (commit 2859f25). |
Co-authored-by: javiercn <[email protected]>
src\Components\Shared\src\RootTypeCache.cs(8,1): error IDE0161: Convert to file-scoped namespace (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0161) |
Co-authored-by: javiercn <[email protected]>
Converted the namespace to file-scoped format to fix the IDE0161 linting error (commit c74ec0f). |
This PR fixes the HotReloadManager accessibility error in the Server project that was preventing compilation. The issue occurred because HotReloadManager is marked as
internal
in the Components.Shared assembly and wasn't accessible from the Components.Server assembly.Root Cause
The original implementation attempted to use
HotReloadManager.Default
directly in the Server project:This caused compilation errors:
Solution
Added
HotReloadManager.cs
as a linked source file to the Server project inMicrosoft.AspNetCore.Components.Server.csproj
:This makes HotReloadManager accessible within the Server assembly, allowing static RootTypeCache instances to register for hot reload directly in static constructors where they're defined.
Changes Made
Microsoft.AspNetCore.Components.Server.csproj:
ServerComponentDeserializer:
_rootTypeCache
fieldMicrosoft.AspNetCore.Components.HotReload
ComponentServiceCollectionExtensions:
RegisterForHotReload
methodBenefits
The implementation maintains the same functionality while ensuring the code compiles successfully across all target projects.
Fixes #63286.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.