Search code examples
c#.netunmanageddefinitionmanaged

What is managed or unmanaged code in programming?


I am using a specific command in in my C# code, which works well. However, it is said to misbehave in "unmanaged" code.

What is managed or unmanaged code?


Solution

  • Here is some text from MSDN about unmanaged code.

    Some library code needs to call into unmanaged code (for example, native code APIs, such as Win32). Because this means going outside the security perimeter for managed code, due caution is required.

    Here is some other complimentary explication about Managed code:

    • Code that is executed by the CLR.
    • Code that targets the common language runtime, the foundation of the .NET Framework, is known as managed code.
    • Managed code supplies the metadata necessary for the CLR to provide services such as memory management, cross-language integration, code access security, and automatic lifetime control of objects. All code based on IL executes as managed code.
    • Code that executes under the CLI execution environment.

    For your problem:

    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!