Share via


SYSLIB1039:JsonSourceGenerator 遇到啟用了 JsonSourceGenerationMode.SerializationJsonDerivedTypeAttribute 註釋

資源產生支援 JsonDerivedTypeAttribute 註釋,但不支援使用 JsonSourceGenerationMode.Serialization 註釋的內容。 也就是說,屬性可與中繼資料來源產生器搭配使用,但不適用於快速路徑方法。

因應措施

移除屬性,或從序列化內容中移除 JsonSourceGenerationMode.Serialization 註釋。

隱藏警告

建議您盡可能使用其中一種因應措施。 不過,若您無法變更程式碼,可以透過 #pragma 指示詞或 <NoWarn> 專案設定來隱藏警告。 若 SYSLIB1XXX 來源產生器診斷未顯示錯誤,可以隱藏程式碼或專案檔中的警告。

若要隱藏程式碼中的警告:

// Disable the warning.
#pragma warning disable SYSLIB1006

// Code that generates compiler diagnostic.
// ...

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

若要隱藏專案檔中的警告:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
   <TargetFramework>net6.0</TargetFramework>
   <!-- NoWarn below suppresses SYSLIB1002 project-wide -->
   <NoWarn>$(NoWarn);SYSLIB1002</NoWarn>
   <!-- To suppress multiple warnings, you can use multiple NoWarn elements -->
   <NoWarn>$(NoWarn);SYSLIB1002</NoWarn>
   <NoWarn>$(NoWarn);SYSLIB1006</NoWarn>
   <!-- Alternatively, you can suppress multiple warnings by using a semicolon-delimited list -->
   <NoWarn>$(NoWarn);SYSLIB1002;SYSLIB1006;SYSLIB1007</NoWarn>
  </PropertyGroup>
</Project>