我启动了Visual Studio 2017,并打开了C#Interactive。 当我尝试使用以下代码时,我收到了一条相当特殊的错误消息:
> System.Runtime.Serialization.FormatterServices.GetUninitializedObject(((object)typeof(object)).GetType())
Hosting process exited with exit code -1073741819.
Loading context from 'CSharpInteractive.rsp'.
>
所以我尝试用try / catch包围它,它似乎工作(不退出过程):
> try { System.Runtime.Serialization.FormatterServices.GetUninitializedObject(((object)typeof(object)).GetType()); } catch (Exception ex) { }
>
然后我试着获得Exception的类型:
> try { System.Runtime.Serialization.FormatterServices.GetUninitializedObject(((object)typeof(object)).GetType()); } catch (Exception ex) { WriteLine(ex.GetType()); }
>
没有输出?很奇怪......我尝试输出"未初始化的对象",它又开始退出该过程...
> try { WriteLine(System.Runtime.Serialization.FormatterServices.GetUninitializedObject(((object)typeof(object)).GetType())); } catch (Exception ex) { WriteLine(ex.GetType()); }
Hosting process exited with exit code -1073741819.
Loading context from 'CSharpInteractive.rsp'.
>
捕捉一切都不起作用:
> try { WriteLine(System.Runtime.Serialization.FormatterServices.GetUninitializedObject(((object)typeof(object)).GetType())); } catch { }
Hosting process exited with exit code -1073741819.
Loading context from 'CSharpInteractive.rsp'.
>
有人可以解释一下这里发生了什么吗?