RickStrahl / Westwind.Globalization

Database driven resource localization for .NET applications
544 stars 135 forks source link

Not working with azure function version 2.0 #189

Closed sajibcefalo closed 3 years ago

sajibcefalo commented 4 years ago

I tried the following code to integrate westwind globalization in azure function version 2.

My appsettings.json is as following:


 "DbResourceConfiguration": {
    "ResourceAccessMode": "DbResourceManager",
    "ConnectionString": "Data Source=localhost;Initial Catalog=localized-resource;Persist Security Info=True;User ID=sa;Password=sa123;MultipleActiveResultSets=True",
    "DataProvider": "SqlServer",
    "ResourceTableName": "Localizations",
    "StronglyTypedGlobalResource": "~/Properties/Resources.cs",
    "ResourceBaseNamespace": "AppResources",
    "ResxExportProjectType": "Project",
    "ResxBaseFolder": "~/Properties/",
    "AddMissingResources": true,
    "LocalizationFormWebPath": "~/LocalizationAdmin/",
    "BingClientId": "12345-4b99-47ed-be7e-caf733526020",
    "GoogleApiKey": "XXXfaSyDcvmGhGN7FlynP9QUZOLF8_4K8iF9ChWo"
  }

In the start up project I initialized DbResourceConfiguration as follows:

var configurationSection = Configuration.GetSection(nameof(DbResourceConfiguration));
            var dbResourceConfiguration = configurationSection
                .Get<DbResourceConfiguration>();
            if (dbResourceConfiguration == null || dbResourceConfiguration.ConnectionString.StartsWith("***"))
            {
                throw new System.Exception("DbResourceConfiguration could not found");
            }
            WebJobsBuilder.Services.Configure<DbResourceConfiguration>(configurationSection);
            DbResourceConfiguration.Current.Initialize();
            DbResourceConfiguration.Current = dbResourceConfiguration;
            WebJobsBuilder.Services.AddSingleton(dbResourceConfiguration);

It works fine locally. But, when I deployed the app in azure it does not starts and throws the following exception

The function runtime is unable to start. 
Microsoft.Extensions.Configuration.Binder: Failed to create instance of type 'Westwind.Globalization.DbResourceConfiguration'.
System.Private.CoreLib: Exception has been thrown by the target of an invocation. Westwind.Globalization: The type initializer for 'Westwind.Globalization.DbResourceConfiguration' threw an exception. Westwind.Utilities

I downloaded and explored the Westwind.Utilities code could not find out where the problem occurs

Rashik004 commented 3 years ago

Please install this package package and add the code

WebJobsBuilder.Services.AddWestwindGlobalization();

sajibcefalo commented 3 years ago

Please install this package package and add the code

WebJobsBuilder.Services.AddWestwindGlobalization();

Thanks! It works like a charm