【问题标题】:A suitable constructor for type 'Microsoft.Extensions.Localization.StringLocalizer could not be located找不到适合类型“Microsoft.Extensions.Localization.StringLocalizer”的构造函数
【发布时间】:2020-10-01 11:27:57
【问题描述】:

我的 Blazor WebAssembly 发布到 Azure 静态文件出现以下错误:

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: A suitable constructor for type 'Microsoft.Extensions.Localization.StringLocalizer`1[CommandesAEmporter.Pages.Index]' could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor.
System.InvalidOperationException: A suitable constructor for type 'Microsoft.Extensions.Localization.StringLocalizer`1[CommandesAEmporter.Pages.Index]' could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor.

在我的电脑上运行时,它运行良好。我在我的项目中使用以下内容:

-Project Sdk="Microsoft.NET.Sdk.Web"--

  --PropertyGroup--
    --TargetFramework--netstandard2.1--/TargetFramework--
    --RazorLangVersion--3.0--/RazorLangVersion--
    --ServiceWorkerAssetsManifest--service-worker-assets.js--/ServiceWorkerAssetsManifest--
  --/PropertyGroup--

  --ItemGroup--
    --PackageReference Include="Azure.Storage.Blobs" Version="12.4.2" /--
    --PackageReference Include="Blazored.LocalStorage" Version="2.1.6" /--
    --PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.0" /--
    --PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.0" PrivateAssets="all" /--
    --PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.0" PrivateAssets="all" /--
    --PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.1.4" /--
    --PackageReference Include="Microsoft.Extensions.Localization" Version="3.1.5" /--
    --PackageReference Include="System.Net.Http.Json" Version="3.2.0" /--
  --/ItemGroup--

  --ItemGroup--
    --ServiceWorker Include="wwwroot\service-worker.js" PublishedContent="wwwroot\service-worker.published.js" /--
  --/ItemGroup--

任何帮助将不胜感激。

【问题讨论】:

    标签: azure blazor webassembly


    【解决方案1】:

    I hope this helps you

    当您使用发布模式构建解决方案时,当资源文件名为 Resource.resx 但如果您的文件名为 Resource.en.resx 然后生成 DLL 文件,我也分享你必须重命名文件的屏幕截图。

    also, change in a startup.cs

    services.Configure<RequestLocalizationOptions>(options =>
            {
                // Define the list of cultures your app will support
                var supportedCultures = new List<CultureInfo>()
                {
                    new CultureInfo("en-US"),
                    new CultureInfo("de")
                };
                // Set the default culture
                options.DefaultRequestCulture = new RequestCulture("en-US");
                options.SupportedCultures = supportedCultures;
                options.SupportedUICultures = supportedCultures;
            });
    

    Resource.resx

    Resource.en.resx

    【讨论】:

      猜你喜欢
      • 2019-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多