首页 > 解决方案 > System.IO.FileLoadException 如果在设置文件中使用俄语字母

问题描述

我创建了一个使用配置文件中的一些设置的 net framework 4.8 控制台应用程序。我在发布配置中构建这个应用程序并在我的服务器上运行它。

问题是当我在设置文件的值中使用一些俄语字母时 - 应用程序无法以System.IO.FileLoadException. Could not load file or assembly 'System.Threading.Tasks.Extensions, Version=4.2.0.0异常启动。当我从设置文件中删除所有俄语字母时,它工作得很好。

当我从 Visual Studio 运行此应用程序时,无论设置文件中使用什么字母,它都能正常工作。

设置文件的主要部分如下所示

<configSections>
        <sectionGroup name="Settings">
            <section name="TestSettings" type="Foo.Bar.TestSettingsSection, Foo" />
        </<sectionGroup>
</configSections>
<Settings>
       <TestSettings>VALUE</TestSettings>
</Settings>

所以, <TestSettings>значение</TestSettings>失败和<TestSettings>value</TestSettings>工作。

从配置读取的东西看起来像这样(它只是一个代码示例,不适用于我的 TestSettings 示例)

public class TestSettingsSection : ConfigurationSection
    {
        [ConfigurationProperty("Sources")]
        public AppSettingSectionElement Sources
        {
            get => this["Sources"] as AppSettingSectionElement;
            set => this["Sources"] = value;
        }

        public IOptions<TestSettings> CreateOptionsFromConfig()
        {
            var settings = Sources.InnerText.Split(',')
                                 .Select(x => x.Trim())
                                 .ToArray();

            return Options.Create(new TestSettings
                                      {
                                          Sources = settings
                                      });
        }
    }
public class AppSettingSectionElement : ConfigurationElement
    {
        public string InnerText { get; private set; }

        protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey)
        {
            InnerText = reader.ReadElementContentAsString();
        }
    }

这对我来说真的很奇怪,我什至无法理解我可以提供哪些额外的信息。因此,我们将不胜感激为什么会发生这种情况的任何想法。

标签: c#.net-framework-4.8

解决方案


推荐阅读