问题描述
我使用 Assembly.GetEntryAssembly()
...在我的C#code获取应用程序的版本。它运行正常,但当我尝试在NUnit的返回 NULL
。在MSDN它说,它可以返回 NULL
从非托管code时调用。
I am using Assembly.GetEntryAssembly()
... in my C# code to get the version of the application. It runs fine but when I try it in NUnit it returns NULL
. In the MSDN it states that it can return NULL
when called from unmanaged code.
什么是托管或非托管code?我不明白这一点。
What is managed or unmanaged code? I do not get it.
推荐答案
下面是从MSDN一些文字了解。
Here is some text from MSDN about unmanaged code.
某些库code需要调用非托管code(例如,本地code的API,如Win32)。因为这意味着安全边界之外去为管理code,由于谨慎是必需的。
下面是关于管理code其他一些免费的解释:
Here is some other complimentary explication about Managed code:
- code。
- code为目标的公共语言运行库,.NET框架的基础,被称为管理code。
- 管理code提供必要的CLR提供的服务,如内存管理,跨语言集成,code访问安全性,和对象的自动寿命控制的元数据。基于IL所有code作为执行管理code。
- code。该CLI执行环境下执行。
这是由CLR执行
有关你的问题:
我想这是因为NUnit的执行你的code的单元测试,并可能有它的某些部分是不受管理。但我不知道这件事,所以不要把这个黄金。我相信会有人能够给你关于它的更多信息。希望它能帮助!
I think it's because NUnit execute your code for UnitTesting and might have some part of it that is unmanaged. But I am not sure about it, so do not take this for gold. I am sure someone will be able to give you more information about it. Hope it helps!
这篇关于什么是管理在C#/非托管code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!