aspnetboilerplate/aspnetboilerplate · error · AbpException

Must set LocalizationSourceName before, in order to get…

Error message

Must set LocalizationSourceName before, in order to get LocalizationSource

What it means

BackgroundJobBase.LocalizationSource lazily resolves an ILocalizationSource from LocalizationSourceName and throws if that name is null. LocalizationSourceName is normally set via the [LocalizationSourceName] attribute or by overriding the property; without it the job cannot localize its display/log strings.

Solutions

  1. Add [LocalizationSourceName("YourSourceName")] to the job class
  2. Or override 'protected override string LocalizationSourceName => AbpConsts.LocalizationSourceName;' (your source)
  3. Or override the LocalizationSource property entirely to return a custom ILocalizationSource

Example fix

// before
public class EmailJob : BackgroundJob<EmailArgs> { /* no source name */ }
// after
[LocalizationSourceName("MyApp")]
public class EmailJob : BackgroundJob<EmailArgs> { }
Defensive patterns

Strategy: validation

Validate before calling

if (job.LocalizationSourceName == null)
    throw new InvalidOperationException("Set [LocalizationSourceName] on the job class first");

Try / catch

try { text = job.L("Done"); }
catch (AbpException ex) when (ex.Message.Contains("Must set LocalizationSourceName"))
{
    text = "Done"; // fallback to raw key
}

Prevention

When it happens

Trigger: Executing a background job class that neither has a LocalizationSourceName attribute nor overrides the LocalizationSourceName property, and whose code path touches LocalizationSource (e.g. via L(...)).

Common situations: Custom background job copied from a sample without the attribute; job class in an assembly ABP's convention-based localization doesn't associate with any source.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


AI-assisted analysis of aspnetboilerplate/aspnetboilerplate@2323c13a15 (2026-09-08). Data as JSON: /api/errors/8c2312aabcd12475. Report an issue: GitHub.

Appendix: source

Thrown at src/Abp/BackgroundJobs/BackgroundJobBase.cs:65

        public ILocalizationManager LocalizationManager { protected get; set; }

        /// <summary>
        /// Gets/sets name of the localization source that is used in this application service.
        /// It must be set in order to use <see cref="L(string)"/> and <see cref="L(string,CultureInfo)"/> methods.
        /// </summary>
        protected string LocalizationSourceName { get; set; }

        /// <summary>
        /// Gets localization source.
        /// It's valid if <see cref="LocalizationSourceName"/> is set.
        /// </summary>
        protected ILocalizationSource LocalizationSource
        {
            get
            {
                if (LocalizationSourceName == null)
                {
                    throw new AbpException(
                        "Must set LocalizationSourceName before, in order to get LocalizationSource");
                }

                if (_localizationSource == null || _localizationSource.Name != LocalizationSourceName)
                {
                    _localizationSource = LocalizationManager.GetSource(LocalizationSourceName);
                }

                return _localizationSource;
            }
        }

        private ILocalizationSource _localizationSource;

        /// <summary>
        /// Reference to the logger to write logs.
        /// </summary>
        public ILogger Logger { protected get; set; }

View on GitHub (pinned to 2323c13a15)