Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions docs/csharp/misc/cs8500.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
description: "Learn more about: Compiler Warning (level 4) CS8500"
title: "Compiler Warning (level 4) CS8500"
ms.date: 10/23/2025
f1_keywords:
- "CS8500"
helpviewer_keywords:
- "CS8500"
---

# Compiler Warning (level 4) CS8500

This takes the address of, gets the size of, or declares a pointer to a managed type ('type')

Even when used with the [unsafe](../language-reference/keywords/unsafe.md) keyword, taking the address of a managed object, getting the size of a managed object, or declaring a pointer to a managed type is not allowed. A managed type is:

- Any reference type
- Any struct that contains a reference type as a field or property

For more information, see [Unmanaged types](../language-reference/builtin-types/unmanaged-types.md).

The following sample generates CS8500:

```csharp
// CS8500.cs
// Compile with: /unsafe

class MyClass
{
int a = 98;
}

struct MyProblemStruct
{
string s;
float f;
}

struct MyGoodStruct
{
int i;
float f;
}

public class Program
{
unsafe public static void Main()
{
// MyClass is a class, a managed type.
MyClass s = new MyClass();
MyClass* s2 = &s; // CS8500

// The struct contains a string, a managed type.
int i = sizeof(MyProblemStruct); // CS8500

// The struct contains only value types.
i = sizeof(MyGoodStruct); // OK
}
}
```
Loading