Edit

Share via


SYSLIB0012: Assembly.CodeBase and Assembly.EscapedCodeBase are obsolete

The following APIs are marked as obsolete, starting in .NET 5. Using them in code generates warning SYSLIB0012 at compile time.

Workarounds

Use Assembly.Location instead.

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.

C#
// Disable the warning.
#pragma warning disable SYSLIB0012

// Code that uses obsolete API.
// ...

// Re-enable the warning.
#pragma warning restore SYSLIB0012

To suppress all the SYSLIB0012 warnings in your project, add a <NoWarn> property to your project file.

XML
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
   ...
   <NoWarn>$(NoWarn);SYSLIB0012</NoWarn>
  </PropertyGroup>
</Project>

For more information, see Suppress warnings.

See also