为什么会typeof运算(富)曾经返回null? [英] Why would typeof(Foo) ever return null?

查看:80
本文介绍了为什么会typeof运算(富)曾经返回null?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时候,我看到 typeof运算(富)返回null。为什么会出现这种情况?

Occasionally, I see that typeof(Foo) returns null. Why would this happen?

这是在C#,.NET 3.5。

This is in C#, .NET 3.5.

我想这可能是与包含类型没有该组件加载,但一个测试应用程序显示,组件的方法,其中的启动加载的typeof 被使用。

I thought it might have something to do with the assembly containing the type not yet being loaded, but a test app shows that the assembly is loaded at the start of the method where typeof is used.

任何想法?

更新1

  • 在我不能提供一个可重复的样品,因为这发生在一个巨大的应用
  • 当我说'偶尔'我的意思是在我的应用程序相同的方法,但在不同的情况下。此外,在运行时,当失败一次,它会失败的应用程序的该实例每次。

更新2

有问题的应用程序使用的内存huuuuuge量和运行在32位XP。我想也许这是一个TypeLoadException或OutOfMemoryException异常即以某种方式被吞噬(但我看不出,因为我已经试过这与第一次机会异常在调试器中打开)。

The application in question uses a huuuuuge amount of memory and runs on 32bit XP. I'm thinking maybe it's a TypeLoadException or OutOfMemoryException that's somehow being swallowed (but I can't see how, as I've tried this with first-chance exceptions turned on in the debugger).

更新3

遇到同样的问题,刚才。这里的堆栈跟踪: 在code到这一点是真的只是:

Ran into the same issue just now. Here's the stack trace: The code up to this point is literally just:

Type tradeType = typeof(MyTradeType)
TradeFactory.CreateTrade(tradeType)

(之前,它是 .. CreateTrade(typeof运算(MyTradeType))这样的我也没有办法知道,如果 typeof运算返回null

(before, it was ..CreateTrade(typeof(MyTradeType)) so I couldn't actually tell if the typeof returned null)

所以,它看起来像 typeof运算()未返回null ,但它的的时间越来越设置为null,则结束在该 CreateTrade 方法

So, it looks like typeof() isn't returning null but it's getting set to null by the time it ends up in the CreateTrade method.

例外(的NullReferenceException )的 0x80004003 的HResult 属性$ C>(无效的指针)。调用到 System.Runtime.InteropServices.Marshal.GetLastWin32Error()(在立即窗口)返回 127(指定的程序无法找到) 。 我看着在模块窗口,包含此类型和方法的模块被加载并有不看任何加载错误。

The exception (NullReferenceException) has a HResult property of 0x80004003 (Invalid pointer). A call to System.Runtime.InteropServices.Marshal.GetLastWin32Error( ) (in the Immediate Window) returns 127 (The specified procedure could not be found). I've looked in the Modules window and the module that contains this type and method has been loaded and there doesn't look to be any loader errors.

推荐答案

已加载DLL由于某种原因失败?你检查过融合日志的。

Has loading the dll failed for some reason? Have you checked the fusion logs.

我认为这会导致不只是这更多的问题,但如果你正在做这个检查使用任何从组装之前,可能是隐藏任何进一步的问题。

I'd assume this would cause more problems than just this, but if you're doing this check before using anything from the assembly, it may be hiding any further problems.

这篇关于为什么会typeof运算(富)曾经返回null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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