다음을 통해 공유


SYSLIB0004: CER(제약이 있는 실행 영역) 기능이 지원되지 않음

CER(제약이 있는 실행 영역) 기능은 .NET Framework 에서만 지원됩니다. 따라서 다양한 CER 관련 API는 .NET 5부터 사용되지 않는 것으로 표시됩니다. 이러한 API를 사용하면 컴파일 시간에 SYSLIB0004 경고가 생성됩니다.

다음은 사용되지 않는 CER 관련 API입니다.

그러나 다음 CER 관련 API는 사용 중단되지 않습니다.

해결 방법

  • 메서드에 CER 특성을 적용한 경우 특성을 제거합니다. 해당 특성은 .NET 5 이상 버전에 영향을 주지 않습니다.

    // REMOVE the attribute below.
    [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
    public void DoSomething()
    {
    }
    
    // REMOVE the attribute below.
    [PrePrepareMethod]
    public void DoSomething()
    {
    }
    
  • RuntimeHelpers.ProbeForSufficientStack 또는 RuntimeHelpers.PrepareContractedDelegate를 호출하는 경우 호출을 제거합니다. 해당 호출은 .NET 5 이상 버전에 영향을 주지 않습니다.

    public void DoSomething()
    {
        // REMOVE the call below.
        RuntimeHelpers.ProbeForSufficientStack();
    
        // (Remainder of your method logic here.)
    }
    
  • RuntimeHelpers.PrepareConstrainedRegions를 호출하는 경우 호출을 제거합니다. 해당 호출은 .NET 5 이상 버전에 영향을 주지 않습니다.

    public void DoSomething_Old()
    {
        // REMOVE the call below.
        RuntimeHelpers.PrepareConstrainedRegions();
        try
        {
            // try code
        }
        finally
        {
            // cleanup code
        }
    }
    
    public void DoSomething_Corrected()
    {
        // There is no call to PrepareConstrainedRegions. It's a normal try / finally block.
    
        try
        {
            // try code
        }
        finally
        {
            // cleanup code
        }
    }
    
  • RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup을 호출하는 경우 호출을 표준 try/catch/finally 블록으로 바꿉니다.

    // The sample below produces warning SYSLIB0004.
    public void DoSomething_Old()
    {
        RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(MyTryCode, MyCleanupCode, null);
    }
    public void MyTryCode(object state) { /* try code */ }
    public void MyCleanupCode(object state, bool exceptionThrown) { /* cleanup code */ }
    
    // The corrected sample below does not produce warning SYSLIB0004.
    public void DoSomething_Corrected()
    {
        try
        {
            // try code
        }
        catch (Exception ex)
        {
            // exception handling code
        }
        finally
        {
            // cleanup code
        }
    }
    

경고 표시 안 함

사용되지 않는 API를 사용해야 하는 경우, 코드 또는 프로젝트 파일에서 경고를 표시하지 않을 수 있습니다.

단일 위반만 표시하지 않으려면 원본 파일에 전처리기 지시문을 추가하여 경고를 사용하지 않도록 설정한 후 다시 사용하도록 설정합니다.

// Disable the warning.
#pragma warning disable SYSLIB0004

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

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

프로젝트에서 모든 SYSLIB0004 경고를 표시하지 않으려면 프로젝트 파일에 <NoWarn> 속성을 추가합니다.

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

자세한 내용은 경고 표시 안 함을 참조하세요.

참고 항목