问题标签 [typeinitializeexception]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
517 浏览

wpf - MVVM 模式上的 TypeInitializeException

System.TypeInitializationException was unhandled Message=The type initializer for 'SmartHomeworkOrganizer.ViewModels.MainViewModel' threw an exception. Source=SmartHomeworkOrganizer TypeName=SmartHomeworkOrganizer.ViewModels.MainViewModel StackTrace: at SmartHomeworkOrganizer.ViewModels.MainViewModel..ctor() at SmartHomeworkOrganizer.App.OnStartup(Object sender, StartupEventArgs e) in C:\Users\Mohit\Documents\Visual Studio 2010\Projects\SmartHomeworkOrganizer\SmartHomeworkOrganizer\App.xaml.cs:line 21 at System.Windows.Application.OnStartup(StartupEventArgs e) at System.Windows.Application.<.ctor>b__0(Object unused) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler) at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler) at System.Windows.Threading.DispatcherOperation.InvokeImpl() at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state) at System.Threading.ExecutionContext.runTryCode(Object userData) at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Windows.Threading.DispatcherOperation.Invoke() at System.Windows.Threading.Dispatcher.ProcessQueue() at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler) at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler) at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter) at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame) at System.Windows.Threading.Dispatcher.Run() at System.Windows.Application.RunDispatcher(Object ignore) at System.Windows.Application.RunInternal(Window window) at System.Windows.Application.Run(Window window) at System.Windows.Application.Run() at SmartHomeworkOrganizer.App.Main() in C:\Users\Mohit\Documents\Visual Studio 2010\Projects\SmartHomeworkOrganizer\SmartHomeworkOrganizer\obj\Debug\App.g.cs:line 0 at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: System.ArgumentException Message=Default value type does not match type of property 'Score'. Source=WindowsBase StackTrace: at System.Windows.DependencyProperty.ValidateDefaultValueCommon(Object defaultValue, Type propertyType, String propertyName, ValidateValueCallback validateValueCallback, Boolean checkThreadAffinity) at System.Windows.DependencyProperty.ValidateMetadataDefaultValue(PropertyMetadata defaultMetadata, Type propertyType, String propertyName, ValidateValueCallback validateValueCallback) at System.Windows.DependencyProperty.RegisterCommon(String name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata, ValidateValueCallback validateValueCallback) at System.Windows.DependencyProperty.Register(String name, Type propertyType, Type ownerType, PropertyMetadata typeMetadata, ValidateValueCallback validateValueCallback) at System.Windows.DependencyProperty.Register(String name, Type propertyType, Type ownerType, PropertyMetadata typeMetadata) at SmartHomeworkOrganizer.ViewModels.MainViewModel..cctor() in C:\Users\Mohit\Documents\Visual Studio 2010\Projects\SmartHomeworkOrganizer\SmartHomeworkOrganizer\ViewModels\MainViewModel.cs:line 72 InnerException:
这段代码会在 TypeInitializeException 之前引发 System.ArgumentException。它说:“默认值类型与属性分数的类型不匹配”:

这是 .NET 属性:

0 投票
2 回答
768 浏览

c# - 使用静态字段时的类型初始化异常

当运行这个我得到类型 InTialization Exception 我怎么能避免这个...

0 投票
1 回答
290 浏览

html-agility-pack - 将 Moles 与 HtmlAgilityPack 一起使用时出现 TypeInitializationException

我正在尝试使用 Moles 在单独的程序集中测试非静态方法。在没有 [HostType("Moles")] 标签的情况下运行测试时,测试运行良好。当我更换它时,我收到以下错误:

“'HtmlAgilityPack.HtmlNode' 的类型初始化程序引发了异常。”

我附上了以相同方式执行的代码示例。

任何帮助都会很棒!

单元测试调用的类/方法

单元测试

0 投票
1 回答
748 浏览

.net - 调用类的共享成员时,Gallio 中的 TypeInitializationException 和 NullReferenceException

我正在尝试使用 Gallio 和 MbUnit(版本 3.2.750)。

根据教程(http://gallio.org/wiki/doku.php?id=getting_started:my_first_tests),我创建了一个新的类项目,引用了我想测试的另一个项目(另一个类库),写了一些测试,然后运行它们。

我的每一个测试都非常非常简单。而且我测试的方法也很简单。

这是一个例子。测试功能:

和测试:

和错误:

我意识到共享方法不应该有这样的例外,这就是为什么它让我非常非常困惑。

谢谢

0 投票
3 回答
8967 浏览

c# - 'Quartz.Impl.StdSchedulerFactory' 的类型初始化器抛出异常

我非常密切地按照 Quartz.Net 教程上的说明进行操作,但是在尝试调试我的项目时出现启动错误。

我在网上真的找不到任何帮助。这是配置问题吗?有人知道我在哪里可以得到需要配置的简单列表吗?

(我正在使用 Quartz.Net 2.0)

内部异常:{“无法从配置部分 'common/logging' 获取 Common.Logging 的配置。”}

0 投票
1 回答
1878 浏览

vb.net - vb.net“类型初始化程序引发异常”问题

我在尝试加载某个页面时遇到了这个异常。它没有告诉我哪一行代码有问题,这让我现在有点头晕..

什么是类型初始化器?它是干什么用的?我该如何解决这个问题?有什么建议吗?

0 投票
1 回答
3527 浏览

c# - 部署时如何解决我的应用程序中的 TypeInitialization 异常?

我的应用程序在我的机器上运行良好(当然/著名的遗言)。但是,将其部署到网络上的另一台机器时,它甚至不会启动。我在那台机器上运行了我的 EventLog 实用程序,它告诉我:

所以问题出在我的主窗体的构造函数中,显然……我承认,这有点“忙”:

这看起来有问题吗?(除了 ToolStripControlHost 之外,这些都是非常标准的东西)。

现在关于框架版本:事件日志报告用于创建我的应用程序的框架版本,还是安装在尝试运行应用程序的机器上的框架版本?如果前者,而后者没有安装该框架,那是个问题,对吧?

因此,如果这可能是问题所在,我如何确定该机器上安装了哪个版本的 .NET 运行时?

更新

我不知道为什么会这样,但是只有当我右键单击并选择 Run As(并以我自己的身份运行,因为我没有该机器上的“更多特殊”权限)。当我这样做时,我得到“无法找到运行此应用程序的运行时版本”。

如果我只是 2-click 应用程序,它会在没有呜咽声的情况下死掉(没有错误消息)。

0 投票
1 回答
513 浏览

.net - 类型初始化异常

我尝试在 c# 中压缩文件(ie.images,txt,doc....)并尝试了这个(通过使用给出答案J#

异常消息:

'The type initializer for 'java.io.File' threw an exception.'

我发现问题出在FileOutputStream..但是,找不到解决方法..我想要的只是解决此问题的解决方案以及此异常的原因....

0 投票
1 回答
690 浏览

c# - AutoMapper 枚举字节类型初始化异常

我正在尝试使用 AutoMapper 来映射一个非常简单的枚举。

存在此映射的原因是 PriorityType 位于服务器上运行的 dotnet 4.0 域模型程序集中,但我的 DataContract 程序集中需要 dotnet 3.5 中的 Dto。

如果我取消注释byte父类型(我真的不需要超过 255 个可能的条目!),我会得到一个TypeInitializationException. 也无法使用 ConvertUsing 解决它。

为什么周围打嗝byte

编辑 1

进一步调试 AutoMapper,它实质上检索目标中的所有可写属性并检查具有相同名称的相应属性。

在枚举的情况下,有一个名为的字段value__,它通过 AutoMapper 尝试映射的反射可见。

该错误与 v2.2 不同(在 2.1 上),但它在映射字节枚举时仍然会引发异常,但在映射 int32 枚举时却很好。

错误发生在这里,

lambda.Compile()抛出InvalidProgramException一个.

仍在试图理解为什么。

编辑 2

AutoMapper GitHub 上也报告了问题。

0 投票
2 回答
305 浏览

c# - 如何避免 TypeInitializer 异常?

在应用程序中有 2 个页面,CompletePoll.aspx、Default.aspx。

CompletePoll.aspx --> Page_Load()

完成投票()

问题生成器

但是,如果我先调用 Default.aspx,然后调用 CompletePoll.aspx,则代码工作正常。

Default.aspx --> Page_Load()

所以这里我的问题是,如果我首先访问 CompletePoll.aspx ,我会得到 TypeInitializer 异常。如果我先访问 Default.aspx,然后再访问 CompletePoll.aspx,我不会遇到任何问题。我的代码有什么问题,我错过了什么吗?如何首先访问 CompletePoll.aspx?