'< Module>'的类型初始值设定项引发了异常。服务器核心上的PowerShell WPF,带.net 4.7 [英] The type initializer for '<Module>' threw an exception. PowerShell WPF on Server Core with .net 4.7

查看:243
本文介绍了'< Module>'的类型初始值设定项引发了异常。服务器核心上的PowerShell WPF,带.net 4.7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我想知道是否有其他人遇到过这个问题。我们有一个WPF GUI,我们使用PowerShell来显示一些报告,它在Windows Server 2016上运行良好,包括Full和Core。但是,最近,当我在Server
Core机器上安装.net framework 4.7时,WPF GUI停止加载。每当我尝试加载它时(使用PowerShell脚本),它都会抛出此错误消息:


'< Module>'的类型初始值设定项引发异常。

在线:1个字符:1个
+。\ wcrui.ps1

+ ~~~~~~~~~~~¥b $ b    + CategoryInfo          :OperationStopped:(:) [],TypeInitializationException

    + FullyQualifiedErrorId:System.TypeInitializationException


没有其他错误。


这是我到目前为止观察和验证的内容:



  • 此错误仅在安装.net framework 4.7后出现
  • 仅在Server Core上遇到此问题。在完全安装WIndows Server 2016时,没有遇到这个问题(据我所知,.Net框架在Full / Core上是相同的,但我的理解可能已经过时)

我希望有人可能会知道.net 4.7 wrt WPF / XAML中有什么变化。我确实尝试通过.net框架阅读,但在这个问题上找不到任何线索。


这是我的powershell代码加载XAML文件:

 Add-Type -AssemblyName presentationframework 
[xml] $ xaml = get-content" $ PSScriptRoot \hwsummary.xaml"
$ reader =(New-Object System.Xml.XmlNodeReader $ xaml)
#below line抛出错误信息!
$ Form = [Windows.Markup.XamlReader] :: Load($ reader)





cheers..uc

如果您发现我的帖子已经回答了您的问题,请把它标记为答案。如果您发现我的帖子无论如何都有帮助,请点击投票为有帮助。

解决方案

您好,


抛出异常是因为某些文件未正确加载,i n .NET Framework 4.7,一些重要文件可能包含更改了它们的位置,例如,最初在GAC
中的文件被移动到其他位置。
升级.NET Framework后,这会导致程序从GAC文件加载无法加载。


这需要你找到未加载的文件,然后将其放入s uitable位置,以便  您的
程序已正确加载。


如果您认为  ;这是一个错误,我建议您可以向Microsoft Connect反馈门户报告您的问题: 
https://connect.microsoft.com/


我找到了这个问题的一些解释,希望对你有帮助。


TypeInitializationException:'< Module>'的类型初始化程序引发了例外


< module>的类型初始值设定项提出异常


最好的问候,


Bob


Hello,

I am wondering if anyone else has experienced this issue. We have a WPF GUI which we use with PowerShell to show some report and it works nice on Windows Server 2016 both Full and Core. However, recently, when I installed .net framework 4.7 on the Server Core machine, the WPF GUI stopped loading. Whenever I try to load it (using PowerShell script), it throws this error message:

The type initializer for '<Module>' threw an exception.
At line:1 char:1
+ .\wcrui.ps1
+ ~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], TypeInitializationException
    + FullyQualifiedErrorId : System.TypeInitializationException

There are no other errors.

Here is what I have observed and verified so far:

  • This error is appearing only after installation of .net framework 4.7
  • The issue is only experienced on Server Core. On Full installation of WIndows Server 2016, this issue is not experienced (It is my understanding that .Net framework is same on Full/Core but my understanding may be outdated)

I am hoping someone might have some info about what has changed in .net 4.7 wrt WPF/XAML. I did try to read thru .net framework but couldn't find any leads into this issue.

Here is my powershell code which loads the XAML file:

Add-Type -AssemblyName presentationframework 
[xml] $xaml = get-content "$PSScriptRoot\hwsummary.xaml"
$reader = (New-Object System.Xml.XmlNodeReader $xaml) 
# below line throws the error message!
$Form = [Windows.Markup.XamlReader]::Load($reader) 


cheers..uc
If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.

解决方案

Hi,

The exception threw is because some files are not loaded correctly, in .NET Framework 4.7, some important files may have changed their location, for example, files that were originally in the GAC were moved to other places. After upgrading the .NET Framework, this causes your program to be loaded from the GAC file that could not be loaded.

This requires you to find what file is not loaded, and then put it in the suitable location,so that your program loaded correctly.

If you think it is a bug, I suggest you can report your question to Microsoft Connect feedback portal:  https://connect.microsoft.com/

I find some explanation for this question, hope to help you.

TypeInitializationException: The type initializer for '<Module>' threw an exception

the type initializer for <module> threw an exception

Best Regards,

Bob


这篇关于'&lt; Module&gt;'的类型初始值设定项引发了异常。服务器核心上的PowerShell WPF,带.net 4.7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆