0

我正在尝试通过 dotvvm 在我的网站上使用多语言。第一页加载正确,但是当我想改变文化时抛出异常。我的startup.cs:

public class Startup
{
    private readonly IConfiguration Configuration;

    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddLocalization(o =>
        {
            o.ResourcesPath = "Resources";
        });

        services.AddDbContext<justincaseContext>(opt =>
        {
            opt.UseMySQL(Configuration.GetConnectionString("DefaultConnection"));
        });

        services.AddDistributedMemoryCache(opt =>
        {
        });
        services.AddSession(opt =>
        {
            opt.IdleTimeout = TimeSpan.FromMinutes(20);
            opt.Cookie.HttpOnly = true;
            opt.Cookie.IsEssential = true;
        });
        //services.AddHttpContextAccessor();

        //services.AddLocalization(options => options.ResourcesPath = "");


        services.AddDataProtection();
        services.AddAuthorization();
        services.AddWebEncoders();
        services.AddDotVVM<DotvvmStartup>();
        //.AddLocalization(opt =>
        //{
        //    opt.ResourcesPath = "";
        //});
        services.Configure<RequestLocalizationOptions>(options =>
        {
            var supportedCultures = new[]
            {
                new CultureInfo("tr"),
                new CultureInfo("en")
            };
            options.DefaultRequestCulture = new RequestCulture(culture: "en", uiCulture: "en");
            options.SupportedCultures = supportedCultures;
            options.SupportedUICultures = supportedCultures;
            options.RequestCultureProviders.Clear();
            options.AddInitialRequestCultureProvider(new DotvvmRouteRequestCultureProvider("Lang"));
        });
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        app.UseRequestLocalization();

        //var locOptions = app.ApplicationServices.GetService<IOptions<RequestLocalizationOptions>>();
        //app.UseRequestLocalization(locOptions.Value);

        app.UseSession();

        // use DotVVM
        var dotvvmConfiguration = app.UseDotVVM<DotvvmStartup>(env.ContentRootPath);
        dotvvmConfiguration.AssertConfigurationIsValid();

        // use static files
        app.UseStaticFiles();
    }
}

堆栈跟踪:

{
ClassName:"System.IO.FileLoadException"
Message:"Assembly with same name is already loaded"
Data:null
InnerException:null
HelpURL:null
StackTraceString:" at System.Runtime.Loader.AssemblyLoadContext.InternalLoad(ReadOnlySpan`1 arrAssembly, ReadOnlySpan`1 arrSymbols)\r\n at System.Runtime.Loader.AssemblyLoadContext.LoadFromStream(Stream assembly, Stream assemblySymbols)\r\n at System.Runtime.Loader.AssemblyLoadContext.LoadFromStream(Stream assembly)\r\n at DotVVM.Framework.Utils.AssemblyLoader.LoadRaw(Byte[] data)\r\n at DotVVM.Framework.Compilation.DefaultViewCompiler.BuildAssembly(CSharpCompilation compilation)\r\n at DotVVM.Framework.Compilation.DefaultViewCompiler.<>c__DisplayClass11_0.<CompileView>b__0()\r\n at DotVVM.Framework.Compilation.DefaultControlBuilderFactory.<>c__DisplayClass11_1.<CreateControlBuilder>b__1()\r\n at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)\r\n at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)\r\n at System.Lazy`1.CreateValue()\r\n at DotVVM.Framework.Runtime.DefaultDotvvmViewBuilder.BuildView(IDotvvmRequestContext context)\r\n at DotVVM.Framework.Hosting.DotvvmPresenter.ProcessRequestCore(IDotvvmRequestContext context)\r\n at DotVVM.Framework.Hosting.DotvvmPresenter.ProcessRequest(IDotvvmRequestContext context)\r\n at DotVVM.Framework.Hosting.Middlewares.DotvvmRoutingMiddleware.Handle(IDotvvmRequestContext context)\r\n at DotVVM.Framework.Hosting.Middlewares.DotvvmRoutingMiddleware.Handle(IDotvvmRequestContext context)\r\n at DotVVM.Framework.Hosting.DotvvmMiddleware.Invoke(HttpContext context)\r\n at DotVVM.Framework.Hosting.Middlewares.DotvvmErrorPageMiddleware.Invoke(HttpContext context)"
RemoteStackTraceString:null
RemoteStackIndex:0
ExceptionMethod:null
HResult:-2146232799
Source:"System.Private.CoreLib"
WatsonBuckets:null
FileLoad_FileName:null
FileLoad_FusionLog:null
}
Assembly System.Runtime.Loader.AssemblyLoadContext.InternalLoad(ReadOnlySpan<byte> arrAssembly, ReadOnlySpan<byte> arrSymbols)
Assembly System.Runtime.Loader.AssemblyLoadContext.LoadFromStream(Stream assembly, Stream assemblySymbols)
Assembly System.Runtime.Loader.AssemblyLoadContext.LoadFromStream(Stream assembly)
Assembly DotVVM.Framework.Utils.AssemblyLoader.LoadRaw(byte[] data)
Assembly DotVVM.Framework.Compilation.DefaultViewCompiler.BuildAssembly(CSharpCompilation compilation)
ValueTuple<ControlBuilderDescriptor, Func<CSharpCompilation>> DotVVM.Framework.Compilation.DefaultViewCompiler.CompileView(string sourceCode, string fileName, CSharpCompilation compilation, string namespaceName, string className)+() => { }
ValueTuple<ControlBuilderDescriptor, Lazy<IControlBuilder>> DotVVM.Framework.Compilation.DefaultControlBuilderFactory.CreateControlBuilder(MarkupFile file)+() => { }
void System.Lazy<T>.ViaFactory(LazyThreadSafetyMode mode)
void System.Lazy<T>.ExecutionAndPublication(LazyHelper executionAndPublication, bool useDefaultConstructor)
T System.Lazy<T>.CreateValue()
DotvvmView DotVVM.Framework.Runtime.DefaultDotvvmViewBuilder.BuildView(IDotvvmRequestContext context)
async Task DotVVM.Framework.Hosting.DotvvmPresenter.ProcessRequestCore(IDotvvmRequestContext context)
async Task DotVVM.Framework.Hosting.DotvvmPresenter.ProcessRequest(IDotvvmRequestContext context)
async Task<bool> DotVVM.Framework.Hosting.Middlewares.DotvvmRoutingMiddleware.Handle(IDotvvmRequestContext context)
async Task<bool> DotVVM.Framework.Hosting.Middlewares.DotvvmRoutingMiddleware.Handle(IDotvvmRequestContext context)
async Task DotVVM.Framework.Hosting.DotvvmMiddleware.Invoke(HttpContext context)
async Task DotVVM.Framework.Hosting.Middlewares.DotvvmErrorPageMiddleware.Invoke(HttpContext context)
 

我怎样才能找到问题所在?谢谢

4

1 回答 1

0

已在GitHub问题中解决。

问题是需要有一个默认资源文件Texts.resx以及特定于语言的资源文件,如Texts.en-US.resxTexts.tr-TR.resx等。

于 2021-03-03T09:17:51.413 回答