Skip to content

Commit e0daf3a

Browse files
add CS8500 compiler warning (#49433)
1 parent 668cc30 commit e0daf3a

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

docs/csharp/misc/cs8500.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
description: "Learn more about: Compiler Warning (level 4) CS8500"
3+
title: "Compiler Warning (level 4) CS8500"
4+
ms.date: 10/23/2025
5+
f1_keywords:
6+
- "CS8500"
7+
helpviewer_keywords:
8+
- "CS8500"
9+
---
10+
11+
# Compiler Warning (level 4) CS8500
12+
13+
This takes the address of, gets the size of, or declares a pointer to a managed type ('type')
14+
15+
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:
16+
17+
- Any reference type
18+
- Any struct that contains a reference type as a field or property
19+
20+
For more information, see [Unmanaged types](../language-reference/builtin-types/unmanaged-types.md).
21+
22+
The following sample generates CS8500:
23+
24+
```csharp
25+
// CS8500.cs
26+
// Compile with: /unsafe
27+
28+
class MyClass
29+
{
30+
int a = 98;
31+
}
32+
33+
struct MyProblemStruct
34+
{
35+
string s;
36+
float f;
37+
}
38+
39+
struct MyGoodStruct
40+
{
41+
int i;
42+
float f;
43+
}
44+
45+
public class Program
46+
{
47+
unsafe public static void Main()
48+
{
49+
// MyClass is a class, a managed type.
50+
MyClass s = new MyClass();
51+
MyClass* s2 = &s; // CS8500
52+
53+
// The struct contains a string, a managed type.
54+
int i = sizeof(MyProblemStruct); // CS8500
55+
56+
// The struct contains only value types.
57+
i = sizeof(MyGoodStruct); // OK
58+
}
59+
}
60+
```

0 commit comments

Comments
 (0)