0

我的 Windows 窗体应用程序在 Windows 10(最新版本)上安装和运行没有问题。但是,当安装在 Windows 2012R2 x64 终端服务器上时,程序在启动时会崩溃。

事件日志(请参见下文)似乎指向在 MainForm 的构造函数中调用System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));的方法中的行。InitializeComponent()在那里,它抛出一个CultureNotFoundException.

服务器完全是最新的,并且安装了正确版本的 .NET (v4.7.2)。(一个重要的说明是我自己没有任何访问服务器的权限,所以我无法直接在服务器上调试软件。)

我尝试安装不同版本的应用程序,该应用程序尝试CultureInfo.CurrentCulture.NumberFormat在调用InitializeComponent(). 该版本的程序能够毫无问题地从中获取,但随后程序仍然NumberFormat在. 从这里我了解到问题似乎不是由本地文化设置引起的。CurrentCultureInitializeComponent()

深入研究 Microsoft 的参考代码后,我进入了包含一个 try 语句GetNeutralResourcesLanguage()的类,该语句在 try时特别捕获。我可能是错的,但我相信这是引发异常的地方。在 catch 声明中指出:ManifestBasedResourceGrovelerArgumentExceptionCultureInfo c = CultureInfo.GetCultureInfo(cultureName);

// we should catch ArgumentException only.
// Note we could go into infinite loops if mscorlib's 
// NeutralResourcesLanguageAttribute is mangled.  If this assert
// fires, please fix the build process for the BCL directory.

关于如何解决这个问题的任何想法?提前谢谢了。

事件簿:

- <System>
  <Provider Name=".NET Runtime" /> 
  <EventID Qualifiers="0">1026</EventID> 
  <Level>2</Level> 
  <Task>0</Task> 
  <Keywords>0x80000000000000</Keywords> 
  <TimeCreated SystemTime="2020-07-10T08:45:15.000000000Z" /> 
  <EventRecordID>1402928</EventRecordID> 
  <Channel>Application</Channel> 
  <Computer>XXXXXXXXX</Computer> 
  <Security /> 
  </System>
- <EventData>
  <Data>Application: MyApplication.exe Framework Version: v4.0.30319 
Description: The process was terminated due to an unhandled exception.
Exception Info:
  System.Globalization.CultureNotFoundException
  at System.Globalization.CultureInfo.GetCultureInfo(System.String)
  at System.Resources.ManifestBasedResourceGroveler.GetNeutralResourcesLanguage(System.Reflection.Assembly, System.Resources.UltimateResourceFallbackLocation ByRef)
Exception Info:
  System.ArgumentException
  at System.Resources.ManifestBasedResourceGroveler.GetNeutralResourcesLanguage(System.Reflection.Assembly, System.Resources.UltimateResourceFallbackLocation ByRef)
  at System.Resources.ResourceManager.CommonAssemblyInit() at System.Resources.ResourceManager..ctor(System.Type)
  at System.ComponentModel.ComponentResourceManager..ctor(System.Type)
  at MyNameSpace.MainForm.InitializeComponent() at MyNameSpace.MainForm..ctor(System.String[]) 
  at MyNameSpace.Program.Main(System.String[])</Data> 
  </EventData>
  </Event>```
4

1 回答 1

0

我找到了问题的根源,并找到了解决方案。在 MainForm 的构造函数中调用System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));的方法中的行抛出以下内容:InitializeComponent()ArgumentException

The NeutralResourcesLanguageAttribute on the assembly "MyApplication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" specifies an invalid culture name: "en-BW".
Inner exception: System.Globalization.CultureNotFoundException: Culture is not supported.
Parameter name: name
en-BW is an invalid culture identifier.
   at System.Globalization.CultureInfo.GetCultureInfo(String name)
   at System.Resources.ManifestBasedResourceGroveler.GetNeutralResourcesLanguage(Assembly a, UltimateResourceFallbackLocation& fallbackLocation)

事实证明,NeutralResourceLanguageAttribute由于未知原因,它被设置为"en-BW". 此区域性仅在 Windows 10 和 Windows Server 2016(及更高版本)中可用,请参阅MSDN。打开应用程序的项目属性后,单击“程序集信息”按钮可以更改此语言。将“中性语言”字段更改为“无”为我解决了这个问题。

于 2020-07-19T11:06:06.553 回答