HMR does not work when setup a ContractResolver in JsonConvert.DefaultSettings #353

Closed
opened 2025-08-09 17:15:58 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @firewave-remo on 10/19/2017

When i setup a Contract Resolver in the ConfigureServices Method like this:

public void ConfigureServices(IServiceCollection services)
        {
            JsonConvert.DefaultSettings = () => new JsonSerializerSettings() {
                PreserveReferencesHandling = PreserveReferencesHandling.Objects,
                ContractResolver = new CamelCasePropertyNamesContractResolver(),
                NullValueHandling = NullValueHandling.Ignore
            };
            
            ...
        }

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions() {
                    HotModuleReplacement = true
                });                
            }
            ...
        }

The webpack compilation will not be triggered after the server starded his work.

Multitool> dotnet run
Using launch settings from C:\Users\RemoFischer\Documents\Visual Studio 2017\Projects\Multitool\Multitool\Properties\launchSettings.json...
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
      User profile is available. Using 'C:\Users\RemoFischer\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
Hosting environment: Development
Content root path: C:\Users\RemoFischer\Documents\Visual Studio 2017\Projects\Multitool\Multitool
Now listening on: http://localhost:22222
Application started. Press Ctrl+C to shut down.

When removing ContractResolver

Multitool> dotnet run
Using launch settings from C:\Users\RemoFischer\Documents\Visual Studio 2017\Projects\Multitool\Multitool\Properties\launchSettings.json...
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
      User profile is available. Using 'C:\Users\RemoFischer\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
Hosting environment: Development
Content root path: C:\Users\RemoFischer\Documents\Visual Studio 2017\Projects\Multitool\Multitool
Now listening on: http://localhost:22222
Application started. Press Ctrl+C to shut down.
info: Microsoft.AspNetCore.NodeServices[0]
      webpack built 04e15700b1b5542a65d1 in 4867ms

Of course i can workaround this issue, but it would be nice if the library could fix this by using their own JsonSerializerSettings.

*Originally created by @firewave-remo on 10/19/2017* When i setup a Contract Resolver in the ConfigureServices Method like this: ```csharp public void ConfigureServices(IServiceCollection services) { JsonConvert.DefaultSettings = () => new JsonSerializerSettings() { PreserveReferencesHandling = PreserveReferencesHandling.Objects, ContractResolver = new CamelCasePropertyNamesContractResolver(), NullValueHandling = NullValueHandling.Ignore }; ... } public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions() { HotModuleReplacement = true }); } ... } ``` The webpack compilation will not be triggered after the server starded his work. ``` Multitool> dotnet run Using launch settings from C:\Users\RemoFischer\Documents\Visual Studio 2017\Projects\Multitool\Multitool\Properties\launchSettings.json... info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0] User profile is available. Using 'C:\Users\RemoFischer\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest. Hosting environment: Development Content root path: C:\Users\RemoFischer\Documents\Visual Studio 2017\Projects\Multitool\Multitool Now listening on: http://localhost:22222 Application started. Press Ctrl+C to shut down. ``` When removing `ContractResolver` ``` Multitool> dotnet run Using launch settings from C:\Users\RemoFischer\Documents\Visual Studio 2017\Projects\Multitool\Multitool\Properties\launchSettings.json... info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0] User profile is available. Using 'C:\Users\RemoFischer\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest. Hosting environment: Development Content root path: C:\Users\RemoFischer\Documents\Visual Studio 2017\Projects\Multitool\Multitool Now listening on: http://localhost:22222 Application started. Press Ctrl+C to shut down. info: Microsoft.AspNetCore.NodeServices[0] webpack built 04e15700b1b5542a65d1 in 4867ms ``` Of course i can workaround this issue, but it would be nice if the library could fix this by using their own JsonSerializerSettings.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#353
No description provided.