在 Windows CE 中调试时到处抛出 NotSupportedExceptions
我正在 Windows CE 6.0 应用程序上做一些工作。应用程序使用动态加载许多外部程序集。
Assembly assembly = Assembly.Load(path);
这些 .dll 文件位于解决方案之外,但每个文件中都有实现公共接口的类。
加载程序集后,应用程序将循环遍历每个类并实例化一个实例,然后对每个类调用 .Load() 方法。
//in class definition
private log4net.ILog _log = log4net.LogManager.GetLogger(this.GetType());
//in looping method
foreach (IPlugin plugin in _plugins)
{
try
{
plugin.Load();
}
catch (Exception e)
{
string message = string.Format("Plugin load error: {0}", plugin.Name); //breakpoint gets set here.
if (_log.IsErrorEnabled) _log.Error(message, e);
}
}
当我将应用程序部署到设备并运行它时,效果很好。然而,当我在调试器(附加到设备,而不是模拟器)中运行它时,其中一个插件的 Load() 方法抛出“System.NotSupportedException”,该异常被捕获并尝试记录它。但是,Log4Net 日志的 _log.IsErrorEnabled 属性也会引发 NotSupportedException。
当我在构建消息的行上设置断点时,我得到了一些非常奇怪的行为。如果我检查监视窗口中的 _log 对象,我会发现 IsErrorEnabled 和 IsFatalEnabled 属性都抛出 NotSupportedExceptions,但其他 IsXXXEnabled 属性按其应有的方式返回 True 或 False。
此外,如果我检查异常“e”(这是一个 NotSupportedException),我会在它的 StackTrace 属性中看到以下内容:
“((System.Exception)($exception)).StackTrace”引发了“System.Exception”类型的异常。 NotSupportedException'
我的问题是什么可能导致调试环境中出现这种明显的故障?我觉得 Log4Net 的 IsXXXEnabled 方法中的某些方法有效而其他方法无效这一事实可能是一个线索。
I am doing some work on a windows CE 6.0 application. The application loads a number of external assemblies dynamically using.
Assembly assembly = Assembly.Load(path);
These .dll files are outside of the solution, but there are classes in each of them that implement a common interface.
Once the assemblies are loaded the application loops through each of the classes and instansiates an instance, then calls the .Load() method on each of them.
//in class definition
private log4net.ILog _log = log4net.LogManager.GetLogger(this.GetType());
//in looping method
foreach (IPlugin plugin in _plugins)
{
try
{
plugin.Load();
}
catch (Exception e)
{
string message = string.Format("Plugin load error: {0}", plugin.Name); //breakpoint gets set here.
if (_log.IsErrorEnabled) _log.Error(message, e);
}
}
This works fine when I deploy the application to the device and run it. However, when I run this in the debugger (attached to the device, not an emulator) the Load() method of one of the plugins is throwing a 'System.NotSupportedException', which is caught and we attempt to log it. However, the _log.IsErrorEnabled property of the Log4Net log is also throwing a NotSupportedException also.
I get some very odd behavior when I set a breakpoint on the line where I build the message. If I inspect the _log object in the watch window I see that the IsErrorEnabled and IsFatalEnabled properties are both throwing NotSupportedExceptions, but the other IsXXXEnabled Properties return True or False as they should.
Additionally, if I inspect the Exception 'e' (which is a NotSupportedException), I am seeing the following in it's StackTrace Property:
'((System.Exception)($exception)).StackTrace' threw an exception of type 'System.NotSupportedException'
My question is what could be causing this apparent breakdown in the debugging environment? I feel like the fact that some of Log4Net's IsXXXEnabled methods are working and others are not could be a clue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来非常可疑,就像您内存不足,并且运行时在加载目标的调试信息时遇到问题。设备上的内存划分是什么样的?
Is sounds very suspiciously like you're low on memory and the runtime is having problems loading the debug info for your targets. What does the memory division look like on the device?
卸载 Compact Framework 2.0 解决了该问题。希望这对其他人有帮助。
Uninstalling the Compact Framework 2.0 fixed the issue. Hopefully this helps someone else.