我的 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
在. 从这里我了解到问题似乎不是由本地文化设置引起的。CurrentCulture
InitializeComponent()
深入研究 Microsoft 的参考代码后,我进入了包含一个 try 语句GetNeutralResourcesLanguage()
的类,该语句在 try时特别捕获。我可能是错的,但我相信这是引发异常的地方。在 catch 声明中指出:ManifestBasedResourceGroveler
ArgumentException
CultureInfo 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>```