Skip to content

Blazor Server execption on publish after updating to .net 7 #41712

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

Closed
wthks opened this issue May 17, 2022 · 6 comments
Closed

Blazor Server execption on publish after updating to .net 7 #41712

wthks opened this issue May 17, 2022 · 6 comments
Labels
area-dataprotection Includes: DataProtection bug This issue describes a behavior which is not expected - a bug. ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. Status: Resolved

Comments

@wthks
Copy link

wthks commented May 17, 2022

I updated my projects to .net 7 and now I'm getting these errors.

fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]
      An unhandled exception has occurred while executing the request.
      System.Security.Cryptography.CryptographicException: An error occurred while trying to encrypt the provided data. Refer to the inner exception for more information. For more information go to http://aka.ms/dataprotectionwarning
       ---> System.MissingMethodException: Cannot dynamically create an instance of type 'Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel.AuthenticatedEncryptorDescriptorDeserializer'. Reason: No parameterless constructor defined.
         at System.RuntimeType.ActivatorCache..ctor(RuntimeType)
         at System.RuntimeType.CreateInstanceDefaultCtor(Boolean, Boolean)
         at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
         at System.Activator.CreateInstance(Type type, Boolean nonPublic)
         at System.Activator.CreateInstance(Type type)
         at Microsoft.AspNetCore.DataProtection.SimpleActivator.CreateInstance(Type, String)
         at Microsoft.AspNetCore.DataProtection.TypeForwardingActivator.CreateInstance(Type, String, Boolean& )
         at Microsoft.AspNetCore.DataProtection.TypeForwardingActivator.CreateInstance(Type, String)
         at Microsoft.AspNetCore.DataProtection.ActivatorExtensions.CreateInstance[T](IActivator, String)
         at Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager.Microsoft.AspNetCore.DataProtection.KeyManagement.Internal.IInternalXmlKeyManager.DeserializeDescriptorFromKeyElement(XElement)
         at Microsoft.AspNetCore.DataProtection.KeyManagement.DeferredKey.<>c__DisplayClass1_0.<GetLazyDescriptorDelegate>g__GetLazyDescriptorDelegate|0()
         at System.Lazy`1.ViaFactory(LazyThreadSafetyMode)
      --- End of stack trace from previous location ---
         at System.LazyHelper.ThrowException()
         at System.Lazy`1.CreateValue()
         at System.Lazy`1.get_Value()
         at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyBase.get_Descriptor()
         at Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.CngGcmAuthenticatedEncryptorFactory.CreateEncryptorInstance(IKey)
         at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyBase.CreateEncryptor()
         at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRing.KeyHolder.GetEncryptorInstance(Boolean& )
         at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRing.get_DefaultAuthenticatedEncryptor()
         at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Protect(Byte[])
         --- End of inner exception stack trace ---
         at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Protect(Byte[])
         at Microsoft.AspNetCore.DataProtection.TimeLimitedDataProtector.Protect(Byte[], DateTimeOffset)
         at Microsoft.AspNetCore.DataProtection.DataProtectionAdvancedExtensions.Protect(ITimeLimitedDataProtector, Byte[], TimeSpan)
         at Microsoft.AspNetCore.Mvc.ViewFeatures.ServerComponentSerializer.CreateSerializedServerComponent(ServerComponentInvocationSequence invocationId, Type rootComponent, ParameterView parameters)
         at Microsoft.AspNetCore.Mvc.ViewFeatures.ComponentRenderer.PrerenderedServerComponentAsync(HttpContext context, ServerComponentInvocationSequence invocationId, Type type, ParameterView parametersCollection)
         at Microsoft.AspNetCore.Mvc.ViewFeatures.ComponentRenderer.RenderComponentAsync(ViewContext viewContext, Type componentType, RenderMode renderMode, Object parameters)
         at Microsoft.AspNetCore.Mvc.TagHelpers.ComponentTagHelper.ProcessAsync(TagHelperContext context, TagHelperOutput output)
         at Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner.<RunAsync>g__Awaited|0_0(Task task, TagHelperExecutionContext executionContext, Int32 i, Int32 count)

         at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)
         at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, Boolean invokeViewStarts)
         at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
         at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable`1 statusCode)
         at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable`1 statusCode)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|30_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
      --- End of stack trace from previous location ---
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
      --- End of stack trace from previous location ---
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
         at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint, Task, ILogger)
         at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)

running this on local works but after publishing it gives these errors.

@mkArtakMSFT mkArtakMSFT added area-blazor Includes: Blazor, Razor Components feature-blazor-server labels May 17, 2022
@mkArtakMSFT
Copy link
Contributor

Thanks for contacting us. Looks like trimming related issue.
Can you try to disable trimming for your project and see whether that resolves the issue. Here are the docs on the topic: https://docs.microsoft.com/en-us/aspnet/core/blazor/host-and-deploy/configure-trimmer?view=aspnetcore-6.0

@wthks
Copy link
Author

wthks commented May 17, 2022

@mkArtakMSFT thx for the fast reply.

unchecked trim unused code in publish option worked!

@javiercn javiercn added question ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. labels May 17, 2022
@ghost ghost added the Status: Resolved label May 17, 2022
@mkArtakMSFT
Copy link
Contributor

Thanks for confirming, @HeroinGyrl.
Moving over to the data-protection folks to have a look and fix the issue on their end.

@mkArtakMSFT mkArtakMSFT added area-dataprotection Includes: DataProtection bug This issue describes a behavior which is not expected - a bug. and removed question area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. Status: Resolved feature-blazor-server labels May 17, 2022
@adityamandaleeka
Copy link
Member

@JamesNK @HaoK

@JamesNK
Copy link
Member

JamesNK commented May 18, 2022

What version of .NET 7 are you using?

I think the changes recently made to DataProtection should fix this issue - #41650. It forces this type's public constructors to be preserved.

Those changes will be in .NET 7 preview 5.

I suggest you leave trimming disabled for now, and try enabling it again once preview 5 is publically available.

@adityamandaleeka adityamandaleeka added the ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. label May 18, 2022
@ghost ghost added the Status: Resolved label May 18, 2022
@ghost
Copy link

ghost commented May 20, 2022

This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.

See our Issue Management Policies for more information.

@ghost ghost closed this as completed May 20, 2022
Webreaper added a commit to Webreaper/Damselfly that referenced this issue May 30, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jun 19, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-dataprotection Includes: DataProtection bug This issue describes a behavior which is not expected - a bug. ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. Status: Resolved
Projects
None yet
Development

No branches or pull requests

5 participants