หมายเหตุ
การเข้าถึงหน้านี้ต้องได้รับการอนุญาต คุณสามารถลอง ลงชื่อเข้าใช้หรือเปลี่ยนไดเรกทอรีได้
การเข้าถึงหน้านี้ต้องได้รับการอนุญาต คุณสามารถลองเปลี่ยนไดเรกทอรีได้
The following methods are marked as obsolete, starting in .NET 6. Calling them in code generates warning SYSLIB0018 at compile time. These methods throw a PlatformNotSupportedException at runtime.
- Assembly.ReflectionOnlyLoad
- Assembly.ReflectionOnlyLoadFrom(String)
- Type.ReflectionOnlyGetType(String, Boolean, Boolean)
Workarounds
Reflection-only loading is replaced by the metadata load-context in .NET Core and .NET 5+. For more information, see How to: Inspect assembly contents using MetadataLoadContext.
Suppress a warning
If you must use the obsolete APIs, you can suppress the warning in code or in your project file.
To suppress only a single violation, add preprocessor directives to your source file to disable and then re-enable the warning.
// Disable the warning.
#pragma warning disable SYSLIB0018
// Code that uses obsolete API.
// ...
// Re-enable the warning.
#pragma warning restore SYSLIB0018
To suppress all the SYSLIB0018 warnings in your project, add a <NoWarn> property to your project file.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
...
<NoWarn>$(NoWarn);SYSLIB0018</NoWarn>
</PropertyGroup>
</Project>
For more information, see Suppress warnings.