將移轉變更從 .NET Framework 4.5.1 重定為 4.7Retargeting Changes for Migration from .NET Framework 4.5.1 to 4.7

如果您想從 .NET Framework 4.5.1 移轉至 4.7,請檢閱下列主題中可能會影響應用程式的應用程式相容性問題:If you are migrating from the .NET Framework 4.5.1 to 4.7, review the following topics for application compatibility issues that may affect your app:

ASP.NETASP.NET

HtmlTextWriter 無法正確轉譯 <br/> 項目HtmlTextWriter does not render <br/> element correctly

詳細資料Details

從 .NET Framework 4.6 開始,使用 <BR /> 項目呼叫 RenderBeginTag(String)RenderEndTag() 將會正確地只插入一個 <BR /> (而不是兩個)Beginning in the .NET Framework 4.6, calling RenderBeginTag(String) and RenderEndTag() with a <BR /> element will correctly insert only one <BR /> (instead of two)

建議Suggestion

如果應用程式需要額外的 <BR /> 標籤,則應該再次呼叫 RenderBeginTag(String)If an app depended on the extra <BR /> tag, RenderBeginTag(String) should be called a second time. 請注意,這項行為變更只會影響以 .NET Framework 4.6 或更新版本為目標的應用程式,因此另一個做法是以舊版 .NET Framework 為目標,以取得舊版行為。Note that this behavior change only affects apps that target the .NET Framework 4.6 or later, so another option is to target a previous version of the .NET Framework in order to get the old behavior.

名稱Name Value
影響範圍Scope EdgeEdge
版本Version 4.64.6
類型Type 正在重定目標Retargeting

受影響的 APIAffected APIs

每一個工作階段的節流閥並行要求數目Throttle concurrent requests per session

詳細資料Details

在 .NET Framework 4.6.2 和更早版本中,ASP.NET 會使用相同的 Sessionid 循序執行要求,且 ASP.NET 預設一律會透過 Cookie 發出 Sessionid。In the .NET Framework 4.6.2 and earlier, ASP.NET executes requests with the same Sessionid sequentially, and ASP.NET always issues the Sessionid through cookies by default. 如果頁面需要很長的時間來回應,則只要在瀏覽器上按F5 ,就會大幅降低伺服器效能。If a page takes a long time to respond, it will significantly degrade server performance just by pressing F5 on the browser. 在修正程式中,我們新增了一個計數器來追蹤佇列要求,並在超過指定限制時終止要求。In the fix, we added a counter to track the queued requests and terminate the requests when they exceed a specified limit. 預設值是 50。The default value is 50. 如果達到限制,會在事件記錄檔記錄警告並在 IIS 記錄檔中記錄 HTTP 500 回應。If the limit is reached, a warning will be logged in the event log, and an HTTP 500 response may be recorded in the IIS log.

建議Suggestion

若要還原舊行為,您可以將下列設定加入您的 web.config 檔案以選擇退出新行為。To restore the old behavior, you can add the following setting to your web.config file to opt out of the new behavior.

<appSettings>
    <add key="aspnet:RequestQueueLimitPerSession" value="2147483647"/>
</appSettings>
名稱Name Value
影響範圍Scope EdgeEdge
版本Version 4.74.7
類型Type 正在重定目標Retargeting

ClickOnceClickOnce

透過 ClickOnce 發行的應用程式,這些應用程式使用可能會在 Windows 2003 上失敗的 SHA-256 程式碼簽署憑證Apps published with ClickOnce that use a SHA-256 code-signing certificate may fail on Windows 2003

詳細資料Details

這個可執行檔使用 SHA256 簽署。The executable is signed with SHA256. 之前,不論程式碼簽署憑證為 SHA-1 或 SHA-256,都會使用 SHA1 簽署。Previously, it was signed with SHA1 regardless of whether the code-signing certificate was SHA-1 or SHA-256. 這適用於:This applies to:

  • 使用 Visual Studio 2012 (含) 以後版本建置的所有應用程式。All applications built with Visual Studio 2012 or later.
  • 使用 Visual Studio 2010 (含) 以前版本,在具有 .NET Framework 4.5 的系統上建置應用程式。Applications built with Visual Studio 2010 or earlier on systems with the .NET Framework 4.5 present. 此外,如果有 .NET Framework 4.5 (含) 以後版本,也會針對 SHA-256 憑證使用 SHA-256 來簽署 ClickOnce 資訊清單,而不論編譯的 .NET Framework 版本為何。In addition, if the .NET Framework 4.5 or later is present, the ClickOnce manifest is also signed with SHA-256 for SHA-256 certificates regardless of the .NET Framework version against which it was compiled.

建議Suggestion

對簽署 ClickOnce 可執行檔所做的變更只會影響 Windows Server 2003 系統;這些變更需要安裝 KB 938397。The change in signing the ClickOnce executable affects only Windows Server 2003 systems; they require that KB 938397 be installed. 對使用 SHA-256 簽署資訊清單所做的變更還會引進 .NET Framework 4.5 (含) 以後版本的執行階段相依性,即使應用程式是以 .NET Framework 4.0 (含) 以前版本為目標亦然。The change in signing the manifest with SHA-256 even when an app targets the .NET Framework 4.0 or earlier versions introduces a runtime dependency on the .NET Framework 4.5 or a later version.

名稱Name Value
影響範圍Scope EdgeEdge
版本Version 4.54.5
類型Type 正在重定目標Retargeting

ClickOnce 在 4.0 為目標的應用程式上支援 SHA-256ClickOnce supports SHA-256 on 4.0-targeted apps

詳細資料Details

先前,具有使用 SHA-256 簽署之憑證的 ClickOnce 應用程式,需要有 .NET Framework 4.5 或更新版本存在,即使應用程式是以 4.0 為目標。Previously, a ClickOnce app with a certificate signed with SHA-256 would require .NET Framework 4.5 or later to be present, even if the app targeted 4.0. 現在,即使使用 SHA-256 簽署,以 .NET Framework 4.0 為目標的 ClickOnce 應用程式也可以在 .NET Framework 4.0 上執行。Now, .NET Framework 4.0-targeted ClickOnce apps can run on .NET Framework 4.0, even if signed with SHA-256.

建議Suggestion

這項變更移除了該相依性,並允許使用 SHA-256 憑證來簽署以 .NET Framework 4 和更早版本為目標的 ClickOnce 應用程式。This change removes that dependency and allows SHA-256 certificates to be used to sign ClickOnce apps that target .NET Framework 4 and earlier versions.

名稱Name Value
影響範圍Scope MinorMinor
版本Version 4.64.6
類型Type 正在重定目標Retargeting

核心Core

AesCryptoServiceProvider 解密程式提供可重複使用的轉換AesCryptoServiceProvider decryptor provides a reusable transform

詳細資料Details

從以 .NET Framework 4.6.2 為目標的應用程式開始,AesCryptoServiceProvider 解密程式會提供可重複使用的轉換。Starting with apps that target the .NET Framework 4.6.2, the AesCryptoServiceProvider decryptor provides a reusable transform. 呼叫 System.Security.Cryptography.CryptoAPITransform.TransformFinalBlock(Byte[], Int32, Int32) 之後,轉換就會重新初始化並且可重複使用。After a call to System.Security.Cryptography.CryptoAPITransform.TransformFinalBlock(Byte[], Int32, Int32), the transform is reinitialized and can be reused. 若為以舊版 .NET Framework 為目標的應用程式,嘗試透過在呼叫 System.Security.Cryptography.CryptoAPITransform.TransformFinalBlock(Byte[], Int32, Int32) 之後呼叫 System.Security.Cryptography.CryptoAPITransform.TransformBlock(Byte[], Int32, Int32, Byte[], Int32) 來重複使用解密程式,會擲回 CryptographicException 或產生損毀的資料。For apps that target earlier versions of the .NET Framework, attempting to reuse the decryptor by calling System.Security.Cryptography.CryptoAPITransform.TransformBlock(Byte[], Int32, Int32, Byte[], Int32) after a call to System.Security.Cryptography.CryptoAPITransform.TransformFinalBlock(Byte[], Int32, Int32) throws a CryptographicException or produces corrupted data.

建議Suggestion

此變更的影響應該很小,因為這是預期的行為。倚賴舊行為的應用程式可以藉由將下列組態設定新增到應用程式設定檔的 <runtime> 區段,選擇不使用:The impact of this change should be minimal, since this is the expected behavior.Applications that depend on the previous behavior can opt out of it using it by adding the following configuration setting to the <runtime> section of the application's configuration file:

<runtime>
<AppContextSwitchOverrides value="Switch.System.Security.Cryptography.AesCryptoServiceProvider.DontCorrectlyResetDecryptor=true"/>
</runtime>

此外,以舊版 .NET Framework 為目標,但是在從 .NET Framework 4.6.2 開始的 .NET Framework 版本下執行的應用程式,可以藉由將下列組態設定新增到應用程式設定檔的 <runtime> 區段,來選擇使用:In addition, applications that target a previous version of the .NET Framework but are running under a version of the .NET Framework starting with .NET Framework 4.6.2 can opt in to it by adding the following configuration setting to the <runtime> section of the application's configuration file:

<runtime>
<AppContextSwitchOverrides value="Switch.System.Security.Cryptography.AesCryptoServiceProvider.DontCorrectlyResetDecryptor=false"/>
</runtime>
名稱Name Value
影響範圍Scope MinorMinor
版本Version 4.6.24.6.2
類型Type 正在重定目標Retargeting

受影響的 APIAffected APIs

呼叫 ClaimsIdentity 建構函式Calls to ClaimsIdentity constructors

詳細資料Details

從 .NET Framework 4.6.2 開始,具有 System.Security.Principal.IIdentity 參數的 ClaimsIdentity 建構函式如何設定 System.Security.Claims.ClaimsIdentity.Actor 屬性的方法有變更。Starting with the .NET Framework 4.6.2, there is a change in how ClaimsIdentity constructors with an System.Security.Principal.IIdentity parameter set the System.Security.Claims.ClaimsIdentity.Actor property. 如果 System.Security.Principal.IIdentity 引數是 ClaimsIdentity 物件,而且該 ClaimsIdentity 物件的 System.Security.Claims.ClaimsIdentity.Actor 屬性不是 null,則會使用 Clone() 方法來附加 System.Security.Claims.ClaimsIdentity.Actor 屬性。If the System.Security.Principal.IIdentity argument is a ClaimsIdentity object, and the System.Security.Claims.ClaimsIdentity.Actor property of that ClaimsIdentity object is not null, the System.Security.Claims.ClaimsIdentity.Actor property is attached by using the Clone() method. 在 Framework 4.6.1 和更早版本中,System.Security.Claims.ClaimsIdentity.Actor 屬性會附加作為現有的參考。由於此項變更,從 .NET Framework 4.6.2 開始,新 ClaimsIdentity 物件的 System.Security.Claims.ClaimsIdentity.Actor 屬性便不等於建構函式之 System.Security.Principal.IIdentity 引數的 System.Security.Claims.ClaimsIdentity.Actor 屬性。In the Framework 4.6.1 and earlier versions, the System.Security.Claims.ClaimsIdentity.Actor property is attached as an existing reference.Because of this change, starting with the .NET Framework 4.6.2, the System.Security.Claims.ClaimsIdentity.Actor property of the new ClaimsIdentity object is not equal to the System.Security.Claims.ClaimsIdentity.Actor property of the constructor's System.Security.Principal.IIdentity argument. 在 .NET Framework 4.6.1 和更早版本中,它是相等的。In the .NET Framework 4.6.1 and earlier versions, it is equal.

建議Suggestion

如果不想要這種行為,您可以將應用程式組態檔中的 Switch.System.Security.ClaimsIdentity.SetActorAsReferenceWhenCopyingClaimsIdentity 參數設為 true 來還原舊版行為。If this behavior is undesirable, you can restore the previous behavior by setting the Switch.System.Security.ClaimsIdentity.SetActorAsReferenceWhenCopyingClaimsIdentity switch in your application configuration file to true. 您會需要將下列內容新增至 web.config 檔案的 <runtime> 區段︰This requires that you add the following to the <runtime> section of your web.config file:

<configuration>
  <runtime>
    <AppContextSwitchOverrides value="Switch.System.Security.ClaimsIdentity.SetActorAsReferenceWhenCopyingClaimsIdentity=true" />
  </runtime>
</configuration>
名稱Name Value
影響範圍Scope EdgeEdge
版本Version 4.6.24.6.2
類型Type 正在重定目標Retargeting

受影響的 APIAffected APIs

ZipArchiveEntry 物件的 FullName 屬性中路徑分隔符號字元變更Change in path separator character in FullName property of ZipArchiveEntry objects

詳細資料Details

針對以 .NET Framework 4.6.1 和更新版本為目標的應用程式,在方法的多載所建立之物件的屬性中,路徑分隔符號已從反斜線 ( " \ " ) 變更為正斜線 ( "/" ) FullName ZipArchiveEntry CreateFromDirectoryFor apps that target the .NET Framework 4.6.1 and later versions, the path separator character has changed from a backslash ("\") to a forward slash ("/") in the FullName property of ZipArchiveEntry objects created by overloads of the CreateFromDirectory method. 這項變更使得 .NET 實作遵守 .ZIP File Format Specification (.ZIP 檔案格式規格) 的 4.4.17.1 小節,並允許在非 Windows 系統上解壓縮 ZIP 封存。The change brings the .NET implementation into conformity with section 4.4.17.1 of the .ZIP File Format Specification and allows .ZIP archives to be decompressed on non-Windows systems.
在非 Windows 作業系統 (例如 Macintosh) 上解壓縮以舊版 .NET Framework 為目標的應用程式所建立的 ZIP 檔案,會無法保留目錄結構。Decompressing a zip file created by an app that targets a previous version of the .NET Framework on non-Windows operating systems such as the Macintosh fails to preserve the directory structure. 例如,在 Macintosh 上,它會建立一組檔案,其檔案名稱會串連目錄路徑,以及任何反斜線 (\) 字元和檔案名稱。For example, on the Macintosh, it creates a set of files whose filename concatenates the directory path, along with any backslash ("\") characters, and the filename. 因此,解壓縮檔案的目錄結構會無法保留。As a result, the directory structure of decompressed files is not preserved.

建議Suggestion

這項變更對的影響。在 Windows 作業系統上,由 .NET Framework 命名空間中的 Api 解壓縮的 ZIP 檔案 System.IO 應該是最小的,因為這些 api 可以順暢地處理正斜線 ( "/" ) 或反斜線 ( " \ " ) 做為路徑分隔字元。The impact of this change on .ZIP files that are decompressed on the Windows operating system by APIs in the .NET Framework System.IO namespace should be minimal, since these APIs can seamlessly handle either a forward slash ("/") or a backslash ("\") as the path separator character.
如果不需要這項變更,您可以新增設定至 <runtime> 應用程式佈建檔的區段,以退出宣告。If this change is undesirable, you can opt out of it by adding a configuration setting to the <runtime> section of your application configuration file. 下列範例顯示 <runtime> 區段及 Switch.System.IO.Compression.ZipFile.UseBackslash 選擇退出參數:The following example shows both the <runtime> section and the Switch.System.IO.Compression.ZipFile.UseBackslash opt-out switch:

<runtime>
  <AppContextSwitchOverrides value="Switch.System.IO.Compression.ZipFile.UseBackslash=true" />
</runtime>

此外,以舊版 .NET Framework 為目標但在 .NET Framework 4.6.1 和更新版本上執行的應用程式,可以藉由新增設定至 <runtime> 應用程式佈建檔的區段,來加入宣告此行為。In addition, apps that target previous versions of the .NET Framework but are running on the .NET Framework 4.6.1 and later versions can opt in to this behavior by adding a configuration setting to the <runtime> section of the application configuration file. 下圖顯示 <runtime> 區段及 Switch.System.IO.Compression.ZipFile.UseBackslash 選擇加入參數。The following shows both the <runtime> section and the Switch.System.IO.Compression.ZipFile.UseBackslash opt-in switch.

<runtime>
  <AppContextSwitchOverrides value="Switch.System.IO.Compression.ZipFile.UseBackslash=false" />
</runtime>
名稱Name Value
範圍Scope EdgeEdge
版本Version 4.6.14.6.1
類型Type 正在重定目標Retargeting

受影響的 APIAffected APIs

路徑正規化的變更Changes in path normalization

詳細資料Details

從以 .NET Framework 4.6.2 為目標的應用程式開始,執行階段正規化路徑的方式已變更。正規化路徑涉及修改識別路徑或檔案的字串,使它符合目標作業系統上的有效路徑。Starting with apps that target the .NET Framework 4.6.2, the way in which the runtime normalizes paths has changed.Normalizing a path involves modifying the string that identifies a path or file so that it conforms to a valid path on the target operating system. 正規化通常牽涉到︰Normalization typically involves:

  • 規範化元件和目錄分隔符號。Canonicalizing component and directory separators.
  • 將目前的目錄套用到相對路徑。Applying the current directory to a relative path.
  • 評估路徑中的相對目錄 (.) 或上層目錄 (..)。Evaluating the relative directory (.) or the parent directory (..) in a path.
  • 修剪指定的字元。Trimming specified characters. 從以 .NET Framework 4.6.2 為目標的應用程式開始,預設會啟用路徑正規化的下列變更:Starting with apps that target the .NET Framework 4.6.2, the following changes in path normalization are enabled by default:
    • 執行階段會延後至作業系統的 GetFullPathName 函式再進行路徑正規化。The runtime defers to the operating system's GetFullPathName function to normalize paths.
  • 正規化不再涉及修剪目錄區段的結尾 (例如目錄名稱結尾的空格)。Normalization no longer involves trimming the end of directory segments (such as a space at the end of a directory name).
  • 支援完全信任的裝置路徑語法,包括 \\.\ 以及適用於 mscorlib.dll 中之檔案 I/O API 的 \\?\Support for device path syntax in full trust, including \\.\ and, for file I/O APIs in mscorlib.dll, \\?\.
  • 執行階段不會驗證裝置語法路徑。The runtime does not validate device syntax paths.
  • 支援使用裝置語法存取替代資料流。The use of device syntax to access alternate data streams is supported. 這些變更可改善效能,同時允許方法存取先前無法存取的路徑。These changes improve performance while allowing methods to access previously inaccessible paths. 此變更不會影響以 .NET Framework 4.6.1 和舊版為目標但執行於 .NET Framework 4.6.2 或更新版本下的應用程式。Apps that target the .NET Framework 4.6.1 and earlier versions but are running under the .NET Framework 4.6.2 or later are unaffected by this change.

建議Suggestion

以 .NET Framework 4.6.2 或更新版本為目標的應用程式可透過在應用程式設定檔的 <runtime> 區段中新增下列內容來選擇退出此變更,並使用舊版行為:Apps that target the .NET Framework 4.6.2 or later can opt out of this change and use legacy normalization by adding the following to the <runtime> section of the application configuration file:

<runtime>
  <AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=true" />
</runtime>

以 .NET Framework 4.6.1 或更早版本為目標,但在 .NET Framework 4.6.2 或更新版本上執行的應用程式,可以藉由在應用程式設定檔的 <runtime> 區段新增下行,就能啟用路徑正規化的變更:Apps that target the .NET Framework 4.6.1 or earlier but are running on the .NET Framework 4.6.2 or later can enable the changes to path normalization by adding the following line to the <runtime> section of the application .configuration file:

<runtime>
  <AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=false" />
</runtime>
名稱Name Value
範圍Scope MinorMinor
版本Version 4.6.24.6.2
類型Type 正在重定目標Retargeting

長路徑支援Long path support

詳細資料Details

從以 .NET Framework 4.6.2 為目標的應用程式開始,支援長路徑 (最多 32K 個字元),且已移除對於路徑長度的 260 個字元 (或 MAX_PATH) 限制。若為重新編譯以 .NET Framework 4.6.2 為目標的應用程式,先前因為路徑超過 260 個字元而擲回 System.IO.PathTooLongException 的程式碼路徑,現在將只有在下列情況下擲回 System.IO.PathTooLongExceptionStarting with apps that target the .NET Framework 4.6.2, long paths (of up to 32K characters) are supported, and the 260-character (or MAX_PATH) limitation on path lengths has been removed.For apps that are recompiled to target the .NET Framework 4.6.2, code paths that previously threw a System.IO.PathTooLongException because a path exceeded 260 characters will now throw a System.IO.PathTooLongException only under the following conditions:

  • 路徑的長度大於 MaxValue (32,767) 個字元。The length of the path is greater than MaxValue (32,767) characters.
  • 作業系統傳回 COR_E_PATHTOOLONG 或其對應項。The operating system returns COR_E_PATHTOOLONG or its equivalent. 若為以 .NET Framework 4.6.1 和更早版本為目標的應用程式,每當路徑超過 260 個字元時,執行階段就會自動擲回 System.IO.PathTooLongExceptionFor apps that target the .NET Framework 4.6.1 and earlier versions, the runtime automatically throws a System.IO.PathTooLongException whenever a path exceeds 260 characters.

建議Suggestion

若為以 .NET Framework 4.6.2 為目標的應用程式,如果不需要長路徑支援,您可以透過將下列內容新增至 app.config 檔案的 <runtime> 區段以選擇退出長路徑支援︰For apps that target the .NET Framework 4.6.2, you can opt out of long path support if it is not desirable by adding the following to the <runtime> section of your app.config file:

<runtime>
  <AppContextSwitchOverrides value="Switch.System.IO.BlockLongPaths=true" />
</runtime>

若為以舊版 .NET Framework 為目標但卻在 .NET Framework 4.6.2 或更新版本上執行的應用程式,則可將下列內容新增至 app.config 檔案的 <runtime> 區段,以選擇加入長路徑支援:For apps that target earlier versions of the .NET Framework but run on the .NET Framework 4.6.2 or later, you can opt in to long path support by adding the following to the <runtime> section of your app.config file:

<runtime>
  <AppContextSwitchOverrides value="Switch.System.IO.BlockLongPaths=false" />
</runtime>
名稱Name Value
影響範圍Scope MinorMinor
版本Version 4.6.24.6.2
類型Type 正在重定目標Retargeting

路徑冒號檢查更嚴格Path colon checks are stricter

詳細資料Details

在 .NET Framework 4.6.2 中,為了支援先前所不支援的路徑 (就長度和格式兩方面) 而有數項變更。In .NET Framework 4.6.2, a number of changes were made to support previously unsupported paths (both in length and format). 檢查是否有適當的磁片磁碟機分隔符號 (冒號) 語法是否更正確,它的副作用是在一些先前容許的特定路徑 Api 中封鎖某些 URI 路徑。Checks for proper drive separator (colon) syntax were made more correct, which had the side effect of blocking some URI paths in a few select Path APIs where they were previously tolerated.

建議Suggestion

如果傳遞 URI 給受影響的 API,請先將字串修改為合法的路徑。If passing a URI to affected APIs, modify the string to be a legal path first.

  • 以手動方式從 Url 移除配置 (例如, file:// 從 url 移除) 。Remove the scheme from URLs manually (for example, remove file:// from URLs).

  • 將 URI 傳遞給 Uri 類別,並使用 LocalPathPass the URI to the Uri class and use LocalPath.

或者,您可以藉由將 AppCoNtext 參數設定為,退出宣告新的路徑正規化 Switch.System.IO.UseLegacyPathHandling trueAlternatively, you can opt out of the new path normalization by setting the Switch.System.IO.UseLegacyPathHandling AppContext switch to true.

名稱Name Value
範圍Scope EdgeEdge
版本Version 4.6.24.6.2
類型Type 正在重定目標Retargeting

受影響的 APIAffected APIs

Entity FrameworkEntity Framework

如果使用 EntityDeploySplit 或 EntityClean 工作,以 Visual Studio 2013 建置 Entity Framework edmx 可能會失敗,並出現錯誤 MSB4062Building an Entity Framework edmx with Visual Studio 2013 can fail with error MSB4062 if using the EntityDeploySplit or EntityClean tasks

詳細資料Details

MSBuild 12.0 工具 (隨附於 Visual Studio 2013) 已變更 MSBuild 檔案位置,導致舊版 Entity Framework 的目標檔案無效。MSBuild 12.0 tools (included in Visual Studio 2013) changed MSBuild file locations, causing older Entity Framework targets files to be invalid. 結果是 EntityDeploySplitEntityClean 工作會失敗,因為找不到 Microsoft.Data.Entity.Build.Tasks.dllThe result is that EntityDeploySplit and EntityClean tasks fail because they are unable to find Microsoft.Data.Entity.Build.Tasks.dll. 請注意,造成此中斷的原因是工具組 (MSBuild/VS) 變更,而不是 .NET Framework 變更。Note that this break is because of a toolset (MSBuild/VS) change, not because of a .NET Framework change. 只有在升級開發人員工具時才會發生此情況,若只是升級 .NET Framework 則不會發生。It will only occur when upgrading developer tools, not when merely upgrading the .NET Framework.

建議Suggestion

Entity Framework 的目標檔案已修正,從 .NET Framework 4.6 開始,可搭配新的 MSBuild 配置使用。Entity Framework targets files are fixed to work with the new MSBuild layout beginning in the .NET Framework 4.6. 升級至該版 Framework 將會修正此問題。Upgrading to that version of the Framework will fix this issue. 或者,您也可以使用此因應措施來直接修補目標檔案。Alternatively, this workaround can be used to patch the targets files directly.

名稱Name Value
影響範圍Scope 主要Major
版本Version 4.5.14.5.1
類型Type 正在重定目標Retargeting

JITJIT

try 區域中不允許 IL retIL ret not allowed in a try region

詳細資料Details

不同於 JIT64 Just-In-Time 編譯器,RyuJIT (用於 .NET Framework 4.6) 不允許在 try 區域中使用 IL ret 指令。Unlike the JIT64 just-in-time compiler, RyuJIT (used in .NET Framework 4.6) does not allow an IL ret instruction in a try region. ECMA-335 規格不允許從 try 區域傳回,而且不會有已知的受控編譯器產生這類 IL。Returning from a try region is disallowed by the ECMA-335 specification, and no known managed compiler generates such IL. 不過,如果這類 IL 是由反映發出所產生,則 JIT64 編譯器將會執行這類 IL。However, the JIT64 compiler will execute such IL if it is generated using reflection emit.

建議Suggestion

如果應用程式產生在 try 區域中包含 ret opcode 的 IL,應用程式可以 .NET Framework 4.5 為目標,即可使用舊的 JIT,以避免這項中斷。If an app is generating IL that includes a ret opcode in a try region, the app may target .NET Framework 4.5 to use the old JIT and avoid this break. 或者,可以將產生的 IL 更新為在 try 區域之後傳回。Alternatively, the generated IL may be updated to return after the try region.

名稱Name Value
影響範圍Scope EdgeEdge
版本Version 4.64.6
類型Type 正在重定目標Retargeting

.NET Framework 4.6 中的新 64 位元 JIT 編譯器New 64-bit JIT compiler in the .NET Framework 4.6

詳細資料Details

從 .NET Framework 4.6 開始,使用新的 64 位元 JIT 編譯器來進行 Just-In-Time 編譯。Starting with the .NET Framework 4.6, a new 64-bit JIT compiler is used for just-in-time compilation. 在某些情況下,如果使用 32 位元編譯器或舊版 64 位元 JIT 編譯器來執行應用程式,則會擲回非預期的例外狀況或遵守不同的行為。In some cases, an unexpected exception is thrown or a different behavior is observed than if an app is run using the 32-bit compiler or the older 64-bit JIT compiler. 這種變更不會影響32位 JIT 編譯程式。This change does not affect the 32-bit JIT compiler. 下列是已知的差異︰The known differences include the following:

  • 在某些情況下,已開啟最佳化的發行組建中的 Unboxing 作業可能會擲回 NullReferenceExceptionUnder certain conditions, an unboxing operation may throw a NullReferenceException in Release builds with optimization turned on.
  • 在某些情況下,執行大型方法主體中的實際執行程式碼可能會擲回 StackOverflowExceptionIn some cases, execution of production code in a large method body may throw a StackOverflowException.
  • 某些狀況下,發行組建中傳遞至方法的結構會被視為參考型別而非實值型別。Under certain conditions, structures passed to a method are treated as reference types rather than as value types in Release builds. 這個問題的其中一種表現,就是集合中的個別項目會以非預期的順序出現。One of the manifestations of this issue is that the individual items in a collection appear in an unexpected order.
  • 在某些情況下,如果啟用最佳化,UInt16 的值在設定高位元時的比較會不正確。Under certain conditions, the comparison of UInt16 values with their high bit set is incorrect if optimization is enabled.
  • 在某些情況下,尤其是初始化陣列值時,使用 OpCodes.Initblk IL 指令初始化記憶體,可能會以不正確的值初始化記憶體。Under certain conditions, particularly when initializing array values, memory initialization by the OpCodes.Initblk IL instruction may initialize memory with an incorrect value. 這會造成未處理的例外狀況或不正確的輸出。This can result either in an unhandled exception or incorrect output.
  • 在少數情況下,如果啟用編譯器最佳化,條件式位元測試可能會傳回不正確的 Boolean 值或擲回例外狀況。Under certain rare conditions, a conditional bit test can return the incorrect Boolean value or throw an exception if compiler optimizations are enabled.
  • 某些狀況下,如果使用 if 陳述式在進入 try 區塊之前和自 try 區塊退出時測試某項條件,而且也在 catchfinally 區塊中評估該條件時,新版 64 位元 JIT 編譯器在最佳化程式碼時會將 if 條件自 catchfinally 區塊中移除。Under certain conditions, if an if statement is used to test for a condition before entering a try block and in the exit from the try block, and the same condition is evaluated in the catch or finally block, the new 64-bit JIT compiler removes the if condition from the catch or finally block when it optimizes code. 因此,catchfinally 區塊的 if 陳述式中的程式碼會無條件執行。As a result, code inside the if statement in the catch or finally block is executed unconditionally.

建議Suggestion

降低已知問題的風險Mitigation of known issues
如果您遇到上述問題,可以採取以下任一種方式來解決︰If you encounter the issues listed above, you can address them by doing any of the following:

  • 升級至 .NET Framework 4.6.2。Upgrade to the .NET Framework 4.6.2. 隨附於 .NET Framework 4.6.2 中的新版 64 位元編譯器可以解決這些已知問題。The new 64-bit compiler included with the .NET Framework 4.6.2 addresses each of these known issues.

  • 執行 Windows Update,確定您的 Windows 已更新至最新版本。Ensure that your version of Windows is up to date by running Windows Update. .NET Framework 4.6 和 4.6.1 的服務更新可解決上述問題中除了 Unboxing 作業之 NullReferenceException 以外的所有問題。Service updates to the .NET Framework 4.6 and 4.6.1 address each of these issues except the NullReferenceException in an unboxing operation.

  • 使用舊版 64 位元 JIT 編譯器編譯。Compile with the older 64-bit JIT compiler. 如需如何進行的詳細資訊,請參閱降低其他問題的風險一節。See the Mitigation of other issues section for more information on how to do this. 降低其他問題的風險Mitigation of other issues
    如果舊版和新版 64 位元 JIT 編譯器編譯的程式碼之間有任何差異,或是使用新版 64 位元 JIT 編譯器編譯的應用程式偵錯版本和發行版本之間有任何差異,您可以使用舊版 64 位元 JIT 編譯器搭配下列方式來編譯應用程式:If you encounter any other difference in behavior between code compiled with the older 64-bit compiler and the new 64-bit JIT compiler, or between the debug and release versions of your app that are both compiled with the new 64-bit JIT compiler, you can do the following to compile your app with the older 64-bit JIT compiler:

  • 以每個應用程式為基礎,您可以將 < 元素新增至應用程式的設定檔。On a per-application basis, you can add the < element to your application's configuration file. 下列程式碼會停止以新版 64 位元 JIT 編譯器進行編譯,改用舊版 64 位元 JIT 編譯器。The following disables compilation with the new 64-bit JIT compiler and instead uses the legacy 64-bit JIT compiler.

    <?xml version ="1.0"?>
    <configuration>
      <runtime>
       <useLegacyJit enabled="1" />
      </runtime>
    </configuration>
    
  • 若以每一使用者為基礎,您可以將名為 useLegacyJitREG_DWORD 值加入至登錄的 HKEY_CURRENT_USER\SOFTWARE\Microsoft\.NETFramework 索引鍵。On a per-user basis, you can add a REG_DWORD value named useLegacyJit to the HKEY_CURRENT_USER\SOFTWARE\Microsoft\.NETFramework key of the registry. 值為 1 會啟用舊版 64 位元 JIT 編譯器;值為 0 會停用它,並啟用新版 64 位元 JIT 編譯器。A value of 1 enables the legacy 64-bit JIT compiler; a value of 0 disables it and enables the new 64-bit JIT compiler.

  • 若以每一電腦為基礎,您可以將名為 useLegacyJitREG_DWORD 值加入至登錄的 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework 索引鍵。On a per-machine basis, you can add a REG_DWORD value named useLegacyJit to the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework key of the registry. 值為 1 會啟用舊版 64 位元 JIT 編譯器;值為 0 會停用它,並啟用新版 64 位元 JIT 編譯器。A value of 1 enables the legacy 64-bit JIT compiler; a value of 0 disables it and enables the new 64-bit JIT compiler. 您也可以前往 Microsoft Connect 回報錯誤,讓我們知道問題所在。You can also let us know about the problem by reporting a bug on Microsoft Connect.

名稱Name Value
影響範圍Scope EdgeEdge
版本Version 4.64.6
類型Type 正在重定目標Retargeting

網路Networking

憑證 EKU OID 驗證Certificate EKU OID validation

詳細資料Details

從 .NET Framework 4.6 開始,SslStreamServicePointManager 類別會執行增強金鑰使用方法 (EKU) 物件識別碼 (OID) 驗證。Starting with .NET Framework 4.6, the SslStream or ServicePointManager classes perform enhanced key use (EKU) object identifier (OID) validation. 增強金鑰使用方法 (EKU) 延伸模組是表示使用金鑰之應用程式的物件識別碼 (OID) 集合。An enhanced key usage (EKU) extension is a collection of object identifiers (OIDs) that indicate the applications that use the key. EKU OID 驗證會使用遠端憑證回呼,以確保遠端憑證有用於預定目的的正確 OID。EKU OID validation uses remote certificate callbacks to ensure that the remote certificate has the correct OIDs for the intended purpose.

建議Suggestion

如果不需要這項變更,您可以將下列參數新增至 <AppContextSwitchOverrides> ` 應用程式佈建檔的中的,以停用憑證 EKU OID 驗證:If this change is undesirable, you can disable certificate EKU OID validation by adding the following switch to the <AppContextSwitchOverrides> in the ` of your app configuration file:

<runtime>
  <AppContextSwitchOverrides value="Switch.System.Net.DontCheckCertificateEKUs=true" />
</runtime>

重要

提供此設定的目的,只是為了回溯相容性。This setting is provided for backward compatibility only. 不建議用於其他用途。Its use is otherwise not recommended.

名稱Name Value
影響範圍Scope MinorMinor
版本Version 4.64.6
類型Type 正在重定目標Retargeting

受影響的 APIAffected APIs

ServicePointManager.SecurityProtocol 的預設值是 SecurityProtocolType.System.DefaultDefault value of ServicePointManager.SecurityProtocol is SecurityProtocolType.System.Default

詳細資料Details

從以 .NET Framework 4.7 為目標的應用程式開始,ServicePointManager.SecurityProtocol 屬性是 SecurityProtocolType.SystemDefaultStarting with apps that target the .NET Framework 4.7, the default value of the ServicePointManager.SecurityProtocol property is SecurityProtocolType.SystemDefault. 這項變更可以讓以 SslStream 為基礎的 .NET Framework 網路 API (例如 FTP、HTTPS 及 SMTP) 繼承作業系統的預設安全性通訊協定,而不要使用由 .NET Framework 定義的硬式編碼值。This change allows .NET Framework networking APIs based on SslStream (such as FTP, HTTPS, and SMTP) to inherit the default security protocols from the operating system instead of using hard-coded values defined by the .NET Framework. 預設值會依作業系統和系統管理員執行的任何自訂設定而異。The default varies by operating system and any custom configuration performed by the system administrator. 如需每個 Windows 作業系統版本中預設 SChannel 通訊協定的資訊,請參閱 Protocols in TLS/SSL (Schannel SSP) (TLS/SSL 中的通訊協定 (Schannel SSP))。For information on the default SChannel protocol in each version of the Windows operating system, see Protocols in TLS/SSL (Schannel SSP).

目標是舊版 .NET Framework 的應用程式,ServicePointManager.SecurityProtocol 屬性的預設值視目標的 .NET framework 版本而定。For applications that target an earlier version of the .NET Framework, the default value of the ServicePointManager.SecurityProtocol property depends on the version of the .NET Framework targeted. 如需詳細資訊,請參閱從 .NET Framework 4.5.2 移轉到 4.6 的重定目標變更的網路區段See the Networking section of Retargeting Changes for Migration from .NET Framework 4.5.2 to 4.6 for more information.

建議Suggestion

這項變更會影響目標為 .NET Framework 4.7 或更新版本的應用程式。This change affects applications that target the .NET Framework 4.7 or later versions. 如果您偏好使用定義的通訊協定,而不是依賴系統預設,您可以明確設定 ServicePointManager.SecurityProtocol 屬性的值。If you prefer to use a defined protocol rather than relying on the system default, you can explicitly set the value of the ServicePointManager.SecurityProtocol property. 如果不需要這項變更,您可以將設定設定新增至 <runtime> 應用程式佈建檔的區段,以退出宣告。If this change is undesirable, you can opt out of it by adding a configuration setting to the <runtime> section of your application configuration file. 下列範例顯示 <runtime> 區段及 Switch.System.Net.DontEnableSystemDefaultTlsVersions 選擇退出參數:The following example shows both the <runtime> section and the Switch.System.Net.DontEnableSystemDefaultTlsVersions opt-out switch:

<runtime>
  <AppContextSwitchOverrides value="Switch.System.Net.DontEnableSystemDefaultTlsVersions=true" />
</runtime>
名稱Name Value
範圍Scope MinorMinor
版本Version 4.74.7
類型Type 正在重定目標Retargeting

受影響的 APIAffected APIs

在 System.Net.ServicePointManager 和 System.Net.Security.SslStream 只支援 Tls 1.0、1.1 及 1.2 通訊協定Only Tls 1.0, 1.1 and 1.2 protocols supported in System.Net.ServicePointManager and System.Net.Security.SslStream

詳細資料Details

從 .NET Framework 4.6 開始,只有 ServicePointManagerSslStream 類別可以使用 Tls1.0、Tls1.1 或 Tls 1.2 這三種通訊協定之一。Starting with the .NET Framework 4.6, the ServicePointManager and SslStream classes are only allowed to use one of the following three protocols: Tls1.0, Tls1.1, or Tls1.2. 不支援 SSL3.0 通訊協定與 RC4 編碼器。The SSL3.0 protocol and RC4 cipher are not supported.

建議Suggestion

建議的緩和措施是將伺服器端應用程式升級至 Tls1.0、Tls1.1 或 Tls1.2。The recommended mitigation is to upgrade the sever-side app to Tls1.0, Tls1.1, or Tls1.2. 如果這並不可行,或是用戶端應用程式已中斷,則可使用 System.AppContext 類別搭配下列兩種方式之一,停用這項功能:If this is not feasible, or if client apps are broken, the System.AppContext class can be used to opt out of this feature in either of two ways:

  • 以程式設計方式設定上的相容性參數 System.AppContext ,如這裡所述。By programmatically setting compat switches on the System.AppContext, as explained here.
  • 將下列程式行加入至 app.config 檔案的 <runtime> 區段:By adding the following line to the <runtime> section of the app.config file:
<AppContextSwitchOverrides value="Switch.System.Net.DontEnableSchUseStrongCrypto=true"/>
名稱Name Value
影響範圍Scope MinorMinor
版本Version 4.64.6
類型Type 正在重定目標Retargeting

受影響的 APIAffected APIs

SslStream 支援 TLS 警示SslStream supports TLS Alerts

詳細資料Details

失敗的 TLS 信號交換之後,第一個 I/O 讀取/寫入作業將會擲回 System.IO.IOException 與內部 System.ComponentModel.Win32Exception 例外狀況。After a failed TLS handshake, an System.IO.IOException with an inner System.ComponentModel.Win32Exception exception will be thrown by the first I/O Read/Write operation. System.ComponentModel.Win32Exception.NativeErrorCode System.ComponentModel.Win32Exception 可以使用 tls 和 SSL 警示的安全通道錯誤碼,將的程式碼對應至遠端方的 tls 警示。如需詳細資訊,請參閱 RFC 2246:區段7.2.2 錯誤警示The System.ComponentModel.Win32Exception.NativeErrorCode code for the System.ComponentModel.Win32Exception can be mapped to the TLS Alert from the remote party using the Schannel error codes for TLS and SSL alerts.For more information, see RFC 2246: Section 7.2.2 Error alerts.
.NET Framework 4.6.2 和更早版本的行為是如果另一方交握失敗,傳輸通道 (通常是 TCP 連線) 會在寫入或讀取期間逾時,並在之後立即拒絕連線。The behavior in .NET Framework 4.6.2 and earlier is that the transport channel (usually TCP connection) will timeout during either Write or Read if the other party failed the handshake and immediately afterwards rejected the connection.

建議Suggestion

呼叫網路 I/O API (例如 Read(Byte[], Int32, Int32)/Write(Byte[], Int32, Int32)) 的應用程式,應該處理 IOExceptionSystem.TimeoutExceptionApplications calling network I/O APIs such as Read(Byte[], Int32, Int32)/Write(Byte[], Int32, Int32) should handle IOException or System.TimeoutException.
從 .NET Framework 4.7 開始,預設會啟用 TLS 警示功能。The TLS Alerts feature is enabled by default starting with .NET Framework 4.7. 以 .NET Framework 4.0 到 4.6.2 版為目標且在 .NET Framework 4.7 或更高版本的系統上執行的應用程式,會停用此功能以保留相容性。Applications targeting versions of the .NET Framework from 4.0 through 4.6.2 running on a .NET Framework 4.7 or higher system will have the feature disabled to preserve compatibility.
若為在 .NET Framework 4.7 或更新版本上執行之 .NET Framework 4.6 和更新版本的應用程式,您可以使用下列組態 API 來啟用或停用此功能。The following configuration API is available to enable or disable the feature for .NET Framework 4.6 and later applications running on .NET Framework 4.7 or later.

  • 以程式設計方式:必須是應用程式執行的第一件事,因為 ServicePointManager 只會初始化一次:Programmatically: Must be the very first thing the application does since ServicePointManager will initialize only once:

    AppContext.SetSwitch("TestSwitch.LocalAppContext.DisableCaching", true);
    
    // Set to 'false' to enable the feature in .NET Framework 4.6 - 4.6.2.
    AppContext.SetSwitch("Switch.System.Net.DontEnableTlsAlerts", true);
    
  • AppConfig:AppConfig:

    <runtime>
      <AppContextSwitchOverrides value="Switch.System.Net.DontEnableTlsAlerts=true"/>
      <!-- Set to 'false' to enable the feature in .NET Framework 4.6 - 4.6.2. -->
    </runtime>
    
  • 登錄機碼 (電腦全域) :將值設定為,以 false 啟用 .NET Framework 4.6-4.6.2 中的功能。Registry key (machine global): Set the Value to false to enable the feature in .NET Framework 4.6 - 4.6.2.

    Key: HKLM\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\AppContext\Switch.System.Net.DontEnableTlsAlerts
    - Type: String
    - Value: "true"
    
名稱Name Value
範圍Scope EdgeEdge
版本Version 4.74.7
類型Type 正在重定目標Retargeting

受影響的 APIAffected APIs

TLS 1.x 依預設會將 SCH_SEND_AUX_RECORD 旗標傳遞至基礎的 SCHANNEL APITLS 1.x by default passes the SCH_SEND_AUX_RECORD flag to the underlying SCHANNEL API

詳細資料Details

使用 TLS 1.x 時,.NET Framework 依賴基礎的 Windows SCHANNEL API。When using TLS 1.x, the .NET Framework relies on the underlying Windows SCHANNEL API. 從 .NET Framework 4.6 開始,預設會傳遞 SCH_SEND_AUX_RECORD 旗標給 SCHANNL。Starting with .NET Framework 4.6, the SCH_SEND_AUX_RECORD flag is passed by default to SCHANNEL. 這會導致 SCHANNEL 分割資料,以便加密成兩個不同的記錄,第一個是單一位元組,第二個則是 n-1 個位元組。在罕見的情況下,這會中斷用戶端與假設資料位於單一記錄中的現有伺服器之間的通訊。This causes SCHANNEL to split data to be encrypted into two separate records, the first as a single byte and the second as n-1 bytes.In rare cases, this breaks communication between clients and existing servers that make the assumption that the data resides in a single record.

建議Suggestion

如果這項變更會中斷與現有伺服器的通訊,您可以停用傳送 SCH_SEND_AUX_RECORD 旗標,並還原先前的行為,不將資料分割成個別的記錄,其方法是新增下列參數到應用程式組態檔 <runtime> 區段中的 <AppContextSwitchOverrides> 項目:If this change breaks communication with an existing server, you can disable sending the SCH_SEND_AUX_RECORD flag and restore the previous behavior of not splitting data into separate records by adding the following switch to the <AppContextSwitchOverrides> element in the <runtime> section of your app configuration file:

<runtime>
  <AppContextSwitchOverrides value="Switch.System.Net.DontEnableSchSendAuxRecord=true" />
</runtime>

重要

提供此設定的目的,只是為了回溯相容性。This setting is provided for backward compatibility only. 不建議用於其他用途。Its use is otherwise not recommended.

名稱Name Value
範圍Scope EdgeEdge
版本Version 4.64.6
類型Type 正在重定目標Retargeting

受影響的 APIAffected APIs

安全性Security

CspParameters.ParentWindowHandle 現在預期有 HWND 值CspParameters.ParentWindowHandle now expects HWND value

詳細資料Details

.NET Framework 2.0 中引進的 ParentWindowHandle 值,可讓應用程式註冊父視窗控制代碼值,因而存取金鑰所需的任何 UI (如 PIN 提示或同意對話方塊) 在指定的視窗會開啟為強制回應子項。從以 .NET Framework 4.7 為目標的應用程式開始,Windows Forms 應用程式可以使用如下的程式碼設定 ParentWindowHandle 屬性:The ParentWindowHandle value, introduced in .NET Framework 2.0, allows an application to register a parent window handle value such that any UI required to access the key (such as a PIN prompt or consent dialog) opens as a modal child to the specified window.Starting with apps that target the .NET Framework 4.7, a Windows Forms application can set the ParentWindowHandle property with code like the following:

cspParameters.ParentWindowHandle = form.Handle;

在舊版 .NET Framework 中,值必須為 System.IntPtr,代表存放 HWND 值之記憶體中的位置。In previous versions of the .NET Framework, the value was expected to be an System.IntPtr representing a location in memory where the HWND value resided. 在 Windows 7 和舊版中,將屬性設為 form.Handle 不會有任何作用,但在 Windows 8 和更新的版本中,則會導致 "System.Security.Cryptography.CryptographicException:參數不正確。"Setting the property to form.Handle on Windows 7 and earlier versions had no effect, but on Windows 8 and later versions, it results in a "System.Security.Cryptography.CryptographicException: The parameter is incorrect."

建議Suggestion

以 .NET Framework 4.7 或更新版本為目標的應用程式若要註冊父視窗關聯性,建議使用以下的簡化格式︰Applications targeting .NET Framework 4.7 or higher wishing to register a parent window relationship are encouraged to use the simplified form:

cspParameters.ParentWindowHandle = form.Handle;

使用者如已發現要傳遞的正確值,是 form.Handle 值所在之記憶體位置的位址,則可以藉由將 AppContext 參數 Switch.System.Security.Cryptography.DoNotAddrOfCspParentWindowHandle 設為 true 以選擇退出行為變更:Users who had identified that the correct value to pass was the address of a memory location which held the value form.Handle can opt out of the behavior change by setting the AppContext switch Switch.System.Security.Cryptography.DoNotAddrOfCspParentWindowHandle to true:

  • 以程式設計方式設定 AppContext 的相容性參數,如這裡所述。By programmatically setting compat switches on the AppContext, as explained here.
  • 將下列程式行加入至 app.config 檔案的 <runtime> 區段:By adding the following line to the <runtime> section of the app.config file:
<runtime>
 <AppContextSwitchOverrides value="Switch.System.Security.Cryptography.DoNotAddrOfCspParentWindowHandle=true"/>
</runtime>

相反地,若使用者想在應用程式在舊版 .NET Framework 下載入時,選擇加入 .NET Framework 4.7 執行階段上的新行為,可以將 AppContext 參數設為 falseConversely, users who wish to opt in to the new behavior on the .NET Framework 4.7 runtime when the application loads under older .NET Framework versions can set the AppContext switch to false.

名稱Name Value
範圍Scope MinorMinor
版本Version 4.74.7
類型Type 正在重定目標Retargeting

受影響的 APIAffected APIs

RSACng 現在會正確地載入非標準金鑰大小的 RSA 金鑰RSACng now correctly loads RSA keys of non-standard key size

詳細資料Details

在 .NET Framework 4.6.2 之前,使用非標準的 RSA 憑證金鑰大小客戶,無法透過 System.Security.Cryptography.X509Certificates.RSACertificateExtensions.GetRSAPublicKey(X509Certificate2)System.Security.Cryptography.X509Certificates.RSACertificateExtensions.GetRSAPrivateKey(X509Certificate2) 擴充方法存取這些金鑰。In .NET Framework versions prior to 4.6.2, customers with non-standard key sizes for RSA certificates are unable to access those keys via the System.Security.Cryptography.X509Certificates.RSACertificateExtensions.GetRSAPublicKey(X509Certificate2) and System.Security.Cryptography.X509Certificates.RSACertificateExtensions.GetRSAPrivateKey(X509Certificate2) extension methods. 會擲回 System.Security.Cryptography.CryptographicException 以及「不支援要求的金鑰大小」訊息。A System.Security.Cryptography.CryptographicException with the message "The requested key size is not supported" is thrown. 在 .NET Framework 4.6.2 中,已修正此問題。In .NET Framework 4.6.2 this issue has been fixed. 同樣地,ImportParameters(RSAParameters)ImportParameters(RSAParameters) 現在可以使用非標準的金鑰大小,而不會擲回 System.Security.Cryptography.CryptographicExceptionSimilarly, ImportParameters(RSAParameters) and ImportParameters(RSAParameters) now work with non-standard key sizes without throwing a System.Security.Cryptography.CryptographicException.

建議Suggestion

如果有任何例外狀況處理邏輯會依賴先前的行為,也就是使用非標準的金鑰大小時會擲回 System.Security.Cryptography.CryptographicException,請考慮移除該邏輯。If there is any exception handling logic that relies on the previous behavior where a System.Security.Cryptography.CryptographicException is thrown when non-standard key sizes are used, consider removing the logic.

名稱Name Value
影響範圍Scope EdgeEdge
版本Version 4.6.24.6.2
類型Type 正在重定目標Retargeting

受影響的 APIAffected APIs

SignedXml.GetPublicKey RSACng 會在 net462 (或 lightup) 上傳回 RSACng,而無重定目標變更SignedXml.GetPublicKey returns RSACng on net462 (or lightup) without retargeting change

詳細資料Details

從 .NET Framework 4.6.2 開始,SignedXml.GetPublicKey 方法所傳回的物件具象類型 (毫不奇怪地) 從 CryptoServiceProvider 實作變更為 Cng 實作。Starting with the .NET Framework 4.6.2, the concrete type of the object returned by the SignedXml.GetPublicKey method changed (without a quirk) from a CryptoServiceProvider implementation to a Cng implementation. 這是因為實作從使用 certificate.PublicKey.Key 變更為使用內部 certificate.GetAnyPublicKey,它會轉送給 RSACertificateExtensions.GetRSAPublicKeyThis is because the implementation changed from using certificate.PublicKey.Key to using the internal certificate.GetAnyPublicKey which forwards to RSACertificateExtensions.GetRSAPublicKey.

建議Suggestion

從在 .NET Framework 4.7.1 上執行的應用程式開始,您可以使用 .NET Framework 4.6.1 和更早版本中預設使用的 CryptoServiceProvider 實作,方法是將下列設定參數新增至您應用程式設定檔的 runtime 區段:Starting with apps running on the .NET Framework 4.7.1, you can use the CryptoServiceProvider implementation used by default in the .NET Framework 4.6.1 and earlier versions by adding the following configuration switch to the runtime section of your app config file:

<AppContextSwitchOverrides value="Switch.System.Security.Cryptography.Xml.SignedXmlUseLegacyCertificatePrivateKey=true" />
名稱Name Value
影響範圍Scope EdgeEdge
版本Version 4.6.24.6.2
類型Type 正在重定目標Retargeting

受影響的 APIAffected APIs

SslStream 支援 TLS 警示SslStream supports TLS Alerts

詳細資料Details

失敗的 TLS 信號交換之後,第一個 I/O 讀取/寫入作業將會擲回 System.IO.IOException 與內部 System.ComponentModel.Win32Exception 例外狀況。After a failed TLS handshake, an System.IO.IOException with an inner System.ComponentModel.Win32Exception exception will be thrown by the first I/O Read/Write operation. System.ComponentModel.Win32Exception.NativeErrorCode System.ComponentModel.Win32Exception 可以使用 tls 和 SSL 警示的安全通道錯誤碼,將的程式碼對應至遠端方的 tls 警示。如需詳細資訊,請參閱 RFC 2246:區段7.2.2 錯誤警示The System.ComponentModel.Win32Exception.NativeErrorCode code for the System.ComponentModel.Win32Exception can be mapped to the TLS Alert from the remote party using the Schannel error codes for TLS and SSL alerts.For more information, see RFC 2246: Section 7.2.2 Error alerts.
.NET Framework 4.6.2 和更早版本的行為是如果另一方交握失敗,傳輸通道 (通常是 TCP 連線) 會在寫入或讀取期間逾時,並在之後立即拒絕連線。The behavior in .NET Framework 4.6.2 and earlier is that the transport channel (usually TCP connection) will timeout during either Write or Read if the other party failed the handshake and immediately afterwards rejected the connection.

建議Suggestion

呼叫網路 I/O API (例如 Read(Byte[], Int32, Int32)/Write(Byte[], Int32, Int32)) 的應用程式,應該處理 IOExceptionSystem.TimeoutExceptionApplications calling network I/O APIs such as Read(Byte[], Int32, Int32)/Write(Byte[], Int32, Int32) should handle IOException or System.TimeoutException.
從 .NET Framework 4.7 開始,預設會啟用 TLS 警示功能。The TLS Alerts feature is enabled by default starting with .NET Framework 4.7. 以 .NET Framework 4.0 到 4.6.2 版為目標且在 .NET Framework 4.7 或更高版本的系統上執行的應用程式,會停用此功能以保留相容性。Applications targeting versions of the .NET Framework from 4.0 through 4.6.2 running on a .NET Framework 4.7 or higher system will have the feature disabled to preserve compatibility.
若為在 .NET Framework 4.7 或更新版本上執行之 .NET Framework 4.6 和更新版本的應用程式,您可以使用下列組態 API 來啟用或停用此功能。The following configuration API is available to enable or disable the feature for .NET Framework 4.6 and later applications running on .NET Framework 4.7 or later.

  • 以程式設計方式:必須是應用程式執行的第一件事,因為 ServicePointManager 只會初始化一次:Programmatically: Must be the very first thing the application does since ServicePointManager will initialize only once:

    AppContext.SetSwitch("TestSwitch.LocalAppContext.DisableCaching", true);
    
    // Set to 'false' to enable the feature in .NET Framework 4.6 - 4.6.2.
    AppContext.SetSwitch("Switch.System.Net.DontEnableTlsAlerts", true);
    
  • AppConfig:AppConfig:

    <runtime>
      <AppContextSwitchOverrides value="Switch.System.Net.DontEnableTlsAlerts=true"/>
      <!-- Set to 'false' to enable the feature in .NET Framework 4.6 - 4.6.2. -->
    </runtime>
    
  • 登錄機碼 (電腦全域) :將值設定為,以 false 啟用 .NET Framework 4.6-4.6.2 中的功能。Registry key (machine global): Set the Value to false to enable the feature in .NET Framework 4.6 - 4.6.2.

    Key: HKLM\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\AppContext\Switch.System.Net.DontEnableTlsAlerts
    - Type: String
    - Value: "true"
    
名稱Name Value
範圍Scope EdgeEdge
版本Version 4.74.7
類型Type 正在重定目標Retargeting

受影響的 APIAffected APIs

Visual Basic .NETVisual Basic .NET

VB.NET 不再支援 System.Windows API 的部分命名空間限定性條件VB.NET no longer supports partial namespace qualification for System.Windows APIs

詳細資料Details

從 .NET Framework 4.5.2 開始,VB.NET 專案無法以部分限定的命名空間來指定 System.Windows API。Beginning in .NET Framework 4.5.2, VB.NET projects cannot specify System.Windows APIs with partially-qualified namespaces. 例如,參考 Windows.Forms.DialogResult 將會失敗。For example, referring to Windows.Forms.DialogResult will fail. 相反地,程式碼必須參考完整名稱 (DialogResult),或匯入特定命名空間並只參考 System.Windows.Forms.DialogResultInstead, code must refer to the fully qualified name (DialogResult) or import the specific namespace and refer simply to System.Windows.Forms.DialogResult.

建議Suggestion

您應該更新程式碼,以簡單名稱 (並匯入相關命名空間) 或完整名稱參考 System.Windows API。Code should be updated to refer to System.Windows APIs either with simple names (and importing the relevant namespace) or with fully qualified names.

名稱Name Value
影響範圍Scope MinorMinor
版本Version 4.5.24.5.2
類型Type 正在重定目標Retargeting

Windows Communication Foundation (WCF)Windows Communication Foundation (WCF)

使用 Null 引數呼叫 CreateDefaultAuthorizationContext 已變更Calling CreateDefaultAuthorizationContext with a null argument has changed

詳細資料Details

使用 Null authorizationPolicies 引數呼叫 System.IdentityModel.Policy.AuthorizationContext.CreateDefaultAuthorizationContext(IList<IAuthorizationPolicy>) 所傳回的 System.IdentityModel.Policy.AuthorizationContext 實作,已變更其在 .NET Framework 4.6 中的實作。The implementation of the System.IdentityModel.Policy.AuthorizationContext returned by a call to the System.IdentityModel.Policy.AuthorizationContext.CreateDefaultAuthorizationContext(IList<IAuthorizationPolicy>) with a null authorizationPolicies argument has changed its implementation in the .NET Framework 4.6.

建議Suggestion

在少數情況下,使用自訂驗證的 WCF 應用程式,在行為上可能會有些許差異。In rare cases, WCF apps that use custom authentication may see behavioral differences. 在此情況下,您可使用下列兩種方式之一還原舊版行為:In such cases, the previous behavior can be restored in either of two ways:

  • 以 .NET Framework 4.6 之前的舊版為目標,重新編譯您的應用程式。Recompile your app to target an earlier version of the .NET Framework than 4.6. 對於裝載在 IIS 上的服務,請使用 <httpRuntime targetFramework="x.x"> 項目,將目標設為舊版 .NET Framework。For IIS-hosted services, use the <httpRuntime targetFramework="x.x"> element to target an earlier version of the .NET Framework.

  • 將下列行加入 app.config 檔案中的 <appSettings> 區段:Add the following line to the <appSettings> section of your app.config file:

    <add key="appContext.SetSwitch:Switch.System.IdentityModel.EnableCachedEmptyDefaultAuthorizationContext" value="true" />
    
名稱Name Value
影響範圍Scope MinorMinor
版本Version 4.64.6
類型Type 正在重定目標Retargeting

受影響的 APIAffected APIs

使用可重新進入服務時,可能會造成死結Deadlock may result when using Reentrant services

詳細資料Details

可重新進入服務可能會造成死結,將服務的執行個體限制為一次執行一個執行緒。A deadlock may result in a Reentrant service, which restricts instances of the service to one thread of execution at a time. 容易發生此問題的服務在其程式碼中會有下列 ServiceBehaviorAttributeServices prone to encounter this problem will have the following ServiceBehaviorAttribute in their code:

[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)]

建議Suggestion

若要解決此問題,您可執行以下動作:To address this issue, you can do the following:

[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)]
  • 安裝 .NET Framework 4.6.2 的最新更新,或升級至更新版本的 .NET Framework。Install the latest update to the .NET Framework 4.6.2, or upgrade to a later version of the .NET Framework. 這會停用 OperationContext.Current 中的 ExecutionContext 流程。This disables the flow of the ExecutionContext in OperationContext.Current. 這是可設定的行為;相當於在您的組態檔中新增下列應用程式設定:This behavior is configurable; it is equivalent to adding the following app setting to your configuration file:
<appSettings>
  <add key="Switch.System.ServiceModel.DisableOperationContextAsyncFlow" value="true" />
</appSettings>

Reentrant 服務的值 Switch.System.ServiceModel.DisableOperationContextAsyncFlow 絕對不可設定為 falseThe value of Switch.System.ServiceModel.DisableOperationContextAsyncFlow should never be set to false for Reentrant services.

名稱Name Value
範圍Scope MinorMinor
版本Version 4.6.24.6.2
類型Type 正在重定目標Retargeting

受影響的 APIAffected APIs

OperationContext.Current 在 using 子句中進行呼叫時,可能會傳回 NullOperationContext.Current may return null when called in a using clause

詳細資料Details

如果符合下列所有條件,則 OperationContext.Current 可能會傳回 null,而且可能會導致 NullReferenceExceptionOperationContext.Current may return null and a NullReferenceException may result if all of the following conditions are true:

using (new OperationContextScope(OperationContext.Current))
{
    // OperationContext.Current is null.
    OperationContext context = OperationContext.Current;

    // ...
}

建議Suggestion

若要解決此問題,您可執行以下動作:To address this issue, you can do the following:

  • 如下所示修改您的程式碼,以具現化新的非 null Current 物件:Modify your code as follows to instantiate a new non- null Current object:

    OperationContext ocx = OperationContext.Current;
    using (new OperationContextScope(OperationContext.Current))
    {
        OperationContext.Current = new OperationContext(ocx.Channel);
    
        // ...
    }
    
  • 安裝 .NET Framework 4.6.2 的最新更新,或升級至更新版本的 .NET Framework。Install the latest update to the .NET Framework 4.6.2, or upgrade to a later version of the .NET Framework. 這會停用 OperationContext.Current 中的 ExecutionContext 流程,並還原 WCF 應用程式在 .NET Framework 4.6.1 和舊版中的行為。This disables the flow of the ExecutionContext in OperationContext.Current and restores the behavior of WCF applications in the .NET Framework 4.6.1 and earlier versions. 這是可設定的行為;相當於在您的組態檔中新增下列應用程式設定:This behavior is configurable; it is equivalent to adding the following app setting to your configuration file:

    <appSettings>
      <add key="Switch.System.ServiceModel.DisableOperationContextAsyncFlow" value="true" />
    </appSettings>
    

    如果這項變更並不適當,且您的應用程式相依於作業內容之間流動的執行內容,您可以啟用其流程,如下所示:If this change is undesirable and your application depends on execution context flowing between operation contexts, you can enable its flow as follows:

    <appSettings>
      <add key="Switch.System.ServiceModel.DisableOperationContextAsyncFlow" value="false" />
    </appSettings>
    
名稱Name Value
影響範圍Scope EdgeEdge
版本Version 4.6.24.6.2
類型Type 正在重定目標Retargeting

受影響的 APIAffected APIs

DataContractJsonSerializer 的控制字元序列化現在與 ECMAScript V6 和 V8 相容Serialization of control characters with DataContractJsonSerializer is now compatible with ECMAScript V6 and V8

詳細資料Details

在 .NET Framework 4.6.2 和舊版中,並未 System.Runtime.Serialization.Json.DataContractJsonSerializer 以與 ECMAScript V6 和 V8 標準相容的方式序列化某些特殊控制字元,例如 \b、\f 和 \t。In .NET Framework 4.6.2 and earlier versions, the System.Runtime.Serialization.Json.DataContractJsonSerializer did not serialize some special control characters, such as \b, \f, and \t, in a way that was compatible with the ECMAScript V6 and V8 standards. 從 .NET Framework 4.7 開始,這些控制字元的序列化會與 ECMAScript V6 和 V8 相容。Starting with .NET Framework 4.7, serialization of these control characters is compatible with ECMAScript V6 and V8.

建議Suggestion

若為以 .NET Framework 4.7 為目標的應用程式,會預設啟用此功能。For apps that target the .NET Framework 4.7, this feature is enabled by default. 如果不需要此行為,您可將下列程式行加入至 app.config 或 web.config 檔案的 <runtime> 區段,以選擇退出此功能:If this behavior is not desirable, you can opt out of this feature by adding the following line to the <runtime> section of the app.config or web.config file:

<runtime>
  <AppContextSwitchOverrides value="Switch.System.Runtime.Serialization.DoNotUseECMAScriptV6EscapeControlCharacter=false" />
</runtime>
名稱Name Value
影響範圍Scope EdgeEdge
版本Version 4.74.7
類型Type 正在重定目標Retargeting

受影響的 APIAffected APIs

使用 TransportWithMessageCredential 安全性模式的 WCF 繫結WCF binding with the TransportWithMessageCredential security mode

詳細資料Details

從 .NET Framework 4.6.1 開始,使用 TransportWithMessageCredential 安全性模式的 WCF 繫結可以設定以接收具有不帶正負號 "to" 標頭的非對稱安全性金鑰訊息。根據預設,不帶正負號的 "to" 標頭會繼續在 .NET Framework 4.6.1 中遭到拒絕。Beginning in the .NET Framework 4.6.1, WCF binding that uses the TransportWithMessageCredential security mode can be set up to receive messages with unsigned "to" headers for asymmetric security keys.By default, unsigned "to" headers will continue to be rejected in .NET Framework 4.6.1. 其只有在應用程式使用 Switch.System.ServiceModel.AllowUnsignedToHeader 組態參數來接受此新的作業模式時才會接受。They will only be accepted if an application opts into this new mode of operation using the Switch.System.ServiceModel.AllowUnsignedToHeader configuration switch.

建議Suggestion

由於這是可選擇加入的功能,因此不會影響現有應用程式的行為。Because this is an opt-in feature, it should not affect the behavior of existing apps.
若要控制是否使用新的行為,請使用下列組態設定:To control whether the new behavior is used or not, use the following configuration setting:

<runtime>
  <AppContextSwitchOverrides value="Switch.System.ServiceModel.AllowUnsignedToHeader=true" />
</runtime>
名稱Name Value
影響範圍Scope 透明Transparent
版本Version 4.6.14.6.1
類型Type 正在重定目標Retargeting

受影響的 APIAffected APIs

WCF 訊息安全性現在能夠使用 TLS1.1 和 TLS1.2WCF message security now is able to use TLS1.1 and TLS1.2

詳細資料Details

從 .NET Framework 4.7 開始,除了 SSL3.0 和 TLS1.0 之外,客戶還可以透過應用程式組態設定,在 WCF 訊息安全性設定 TLS1.1 或 TLS1.2。Starting in the .NET Framework 4.7, customers can configure either TLS1.1 or TLS1.2 in WCF message security in addition to SSL3.0 and TLS1.0 through application configuration settings.

建議Suggestion

在 .NET Framework 4.7 中,預設會停用 WCF 訊息安全性中的 TLS1.1 和 TLS1.2 支援。In the .NET Framework 4.7, support for TLS1.1 and TLS1.2 in WCF message security is disabled by default. 您可以將下行新增到 app.config 或 web.config 檔案的 <runtime> 區段來啟用它:You can enable it by adding the following line to the <runtime> section of the app.config or web.config file:

<runtime>
<AppContextSwitchOverrides value="Switch.System.ServiceModel.DisableUsingServicePointManagerSecurityProtocols=false;Switch.System.Net.DontEnableSchUseStrongCrypto=false" />
</runtime>
名稱Name Value
影響範圍Scope EdgeEdge
版本Version 4.74.7
類型Type 正在重定目標Retargeting

WCF 傳輸安全性支援使用 CNG 儲存的憑證WCF transport security supports certificates stored using CNG

詳細資料Details

從以 .NET Framework 4.6.2 為目標的應用程式開始,WCF 傳輸安全性支援使用 Windows 密碼編譯程式庫 (CNG) 儲存的憑證。Starting with apps that target the .NET Framework 4.6.2, WCF transport security supports certificates stored using the Windows Cryptography Library (CNG). 這項支援僅限於具有公開金鑰的憑證,且指數長度不能超過 32 位元。This support is limited to certificates with a public key that has an exponent no more than 32 bits in length. 當應用程式以 .NET Framework 4.6.2 為目標時,此功能預設為開啟。在舊版 .NET Framework 中,嘗試搭配 CSG 金鑰儲存提供者使用 X509 憑證會擲回例外狀況。When an application targets the .NET Framework 4.6.2, this feature is on by default.In earlier versions of the .NET Framework, the attempt to use X509 certificates with a CSG key storage provider throws an exception.

建議Suggestion

應用程式是以 .NET Framework 4.6.1 和更早版本為目標,但卻執行於 .NET Framework 4.6.2 當中,則可將下列這一行新增至 app.config 或 web.config 檔的 <runtime> 區段,來啟用支援 CNG 憑證:Apps that target the .NET Framework 4.6.1 and earlier but are running on the .NET Framework 4.6.2 can enable support for CNG certificates by adding the following line to the <runtime> section of the app.config or web.config file:

<runtime>
  <AppContextSwitchOverrides value="Switch.System.ServiceModel.DisableCngCertificates=false" />
</runtime>

這也可以用程式設計方式,以下列程式碼完成︰This can also be done programmatically with the following code:

private const string DisableCngCertificates = @"Switch.System.ServiceModel.DisableCngCertificate";

AppContext.SetSwitch(disableCngCertificates, false);
Const DisableCngCertificates As String = "Switch.System.ServiceModel.DisableCngCertificates"
AppContext.SetSwitch(disableCngCertificates, False)

請注意,由於這項變更,將不再執行任何倚賴使用 CNG 憑證嘗試起始安全通訊失敗的任何例外住況處理程式碼。Note that, because of this change, any exception handling code that depends on the attempt to initiate secure communication with a CNG certificate to fail will no longer execute.

名稱Name Value
影響範圍Scope MinorMinor
版本Version 4.6.24.6.2
類型Type 正在重定目標Retargeting

X509CertificateClaimSet.FindClaims 會考慮所有 claimTypesX509CertificateClaimSet.FindClaims Considers All claimTypes

詳細資料Details

在目標為 .NET Framework 4.6.1 的應用程式中,如果 X509 宣告集是初始化自 SAN 欄位中含有多個 DNS 項目的憑證,System.IdentityModel.Claims.X509CertificateClaimSet.FindClaims(String, String) 方法會嘗試使用所有 DNS 項目來比對 claimType 引數。若是以舊版 .NET Framework 為目標的應用程式,則 System.IdentityModel.Claims.X509CertificateClaimSet.FindClaims(String, String) 方法僅會嘗試使 claimType 引數符合最後一個 DNS 項目。In apps that target the .NET Framework 4.6.1, if an X509 claim set is initialized from a certificate that has multiple DNS entries in its SAN field, the System.IdentityModel.Claims.X509CertificateClaimSet.FindClaims(String, String) method attempts to match the claimType argument with all the DNS entries.For apps that target previous versions of the .NET Framework, the System.IdentityModel.Claims.X509CertificateClaimSet.FindClaims(String, String) method attempts to match the claimType argument only with the last DNS entry.

建議Suggestion

這項變更只會影響以 .NET Framework 4.6.1 為目標的應用程式。This change only affects applications targeting the .NET Framework 4.6.1. 您可以使用 DisableMultipleDNSEntries 相容性參數來停用這項變更 (如果以 4.6.1 以前版本為目標則可啟用)。This change may be disabled (or enabled if targeting pre-4.6.1) with the DisableMultipleDNSEntries compatibility switch.

名稱Name Value
影響範圍Scope MinorMinor
版本Version 4.6.14.6.1
類型Type 正在重定目標Retargeting

受影響的 APIAffected APIs

Windows FormsWindows Forms

針對 IMessageFilter.PreFilterMessage 的可重新進入實作,Application.FilterMessage 不會再擲回例外狀況Application.FilterMessage no longer throws for re-entrant implementations of IMessageFilter.PreFilterMessage

詳細資料Details

在 .NET Framework 4.6.1 之前,使用呼叫 System.Windows.Forms.Application.AddMessageFilter(IMessageFilter)System.Windows.Forms.Application.RemoveMessageFilter(IMessageFilter)PreFilterMessage(Message) 呼叫 FilterMessage(Message) (同時也呼叫DoEvents()) 會造成 System.IndexOutOfRangeExceptionPrior to the .NET Framework 4.6.1, calling FilterMessage(Message) with an PreFilterMessage(Message) which called System.Windows.Forms.Application.AddMessageFilter(IMessageFilter) or System.Windows.Forms.Application.RemoveMessageFilter(IMessageFilter) (while also calling DoEvents()) would cause an System.IndexOutOfRangeException.

從目標為 .NET Framework 4.6.1 的應用程式開始,不會再擲回此例外狀況,而且可能會使用如上所述的可重新進入篩選。Beginning with applications targeting the .NET Framework 4.6.1, this exception is no longer thrown, and re-entrant filters as described above may be used.

建議Suggestion

請注意,FilterMessage(Message) 將不再針對上述的可重新進入 PreFilterMessage(Message) 行為進行擲回。Be aware that FilterMessage(Message) will no longer throw for the re-entrant PreFilterMessage(Message) behavior described above. 這只會影響以 .NET Framework 4.6.1 為目標的應用程式。藉由使用 DontSupportReentrantFilterMessage 相容性參數,以 .NET Framework 4.6.1 為目標的應用程式可退出這項變更 (或以舊版 Framework 為目標的應用程式可加入這項變更)。This only affects applications targeting the .NET Framework 4.6.1.Apps targeting the .NET Framework 4.6.1 can opt out of this change (or apps targeting older Frameworks may opt in) by using the DontSupportReentrantFilterMessage compatibility switch.

名稱Name Value
影響範圍Scope EdgeEdge
版本Version 4.6.14.6.1
類型Type 正在重定目標Retargeting

受影響的 APIAffected APIs

DataObject.GetData 現在會以 UTF-8 形式來擷取資料DataObject.GetData now retrieves data as UTF-8

詳細資料Details

若為以 .NET Framework 4.5.1 為目標的應用程式,或者在 .NET Framework 4.5.1 或舊版上執行的應用程式,DataObject.GetData 會以 ASCII 字串形式來擷取 HTML 格式的資料。For apps that target the .NET Framework 4 or that run on the .NET Framework 4.5.1 or earlier versions, DataObject.GetData retrieves HTML-formatted data as an ASCII string. 因此,非 ASCII 字元 (ASCII 碼大於 0x7F 的字元) 會以兩個隨機字元表示。As a result, non-ASCII characters (characters whose ASCII codes are greater than 0x7F) are represented by two random characters.

若為以 .NET Framework 4.5 或更新版本為目標並且在 .NET Framework 4.5.2 上執行的應用程式,DataObject.GetData 會以 UTF-8 形式來擷取 HTML 格式的資料,以正確地表示大於 0x7F 的字元。For apps that target the .NET Framework 4.5 or later and run on the .NET Framework 4.5.2, DataObject.GetData retrieves HTML-formatted data as UTF-8, which represents characters greater than 0x7F correctly.

建議Suggestion

如果針對 HTML 格式字串的編碼問題實作了因應措施 (例如將從 [剪貼簿] 擷取的 HTML 字串傳遞至 System.Text.UTF8Encoding.GetString(Byte[], Int32, Int32) 以明確將其編碼),並將目標從應用程式 4 版重定為 4.5 版,則應該移除該因應措施。如果因故需要舊版行為,應用程式可以將目標設為 .NET Framework 4.0 來取得該行為。If you implemented a workaround for the encoding problem with HTML-formatted strings (for example, by explicitly encoding the HTML string retrieved from the Clipboard by passing it to System.Text.UTF8Encoding.GetString(Byte[], Int32, Int32)) and you're retargeting your app from version 4 to 4.5, that workaround should be removed.If the old behavior is needed for some reason, the app can target the .NET Framework 4.0 to get that behavior.

名稱Name Value
影響範圍Scope EdgeEdge
版本Version 4.5.24.5.2
類型Type 正在重定目標Retargeting

受影響的 APIAffected APIs

Icon.ToBitmap 成功將具有 PNG 畫面格的圖示轉換成點陣圖物件Icon.ToBitmap successfully converts icons with PNG frames into Bitmap objects

詳細資料Details

從以 .NET Framework 4.6 為目標的應用程式開始,Icon.ToBitmap 方法可將具有 PNG 框架的圖示成功轉換成點陣圖物件。Starting with the apps that target the .NET Framework 4.6, the Icon.ToBitmap method successfully converts icons with PNG frames into Bitmap objects.

在以 .NET Framework 4.5.2 (含) 之前版本為目標的應用程式中,如果圖示物件具有 PNG 框架,則 Icon.ToBitmap 方法會擲回 ArgumentOutOfRangeException 例外狀況。In apps that target the .NET Framework 4.5.2 and earlier versions, the Icon.ToBitmap method throws an ArgumentOutOfRangeException exception if the Icon object has PNG frames.

這項變更會影響重新撰寫之以 .NET Framework 4.6 為目標的應用程式,以及針對圖示物件具有 PNG 框架時所擲回的 ArgumentOutOfRangeException 實作特殊處理的應用程式。This change affects apps that are recompiled to target the .NET Framework 4.6 and that implement special handling for the ArgumentOutOfRangeException that is thrown when an Icon object has PNG frames. 以 .NET Framework 4.6 執行時,轉換會成功,且不再擲回 ArgumentOutOfRangeException ,因此不會再叫用例外狀況處理常式。When running under the .NET Framework 4.6, the conversion is successful, an ArgumentOutOfRangeException is no longer thrown, and therefore the exception handler is no longer invoked.

建議Suggestion

如果不需要這項行為,您可以在 app.config 檔案的 <runtime> 區段中新增下列項目,以保留舊版行為:If this behavior is undesirable, you can retain the previous behavior by adding the following element to the <runtime> section of your app.config file:

<AppContextSwitchOverrides
value="Switch.System.Drawing.DontSupportPngFramesInIcons=true" />

如果 app.config 檔案已經包含 AppContextSwitchOverrides 項目,則應以下列程式碼將新值與值屬性合併:If the app.config file already contains the AppContextSwitchOverrides element, the new value should be merged with the value attribute like this:

<AppContextSwitchOverrides
value="Switch.System.Drawing.DontSupportPngFramesInIcons=true;<previous key>=<previous value>" />
名稱Name Value
影響範圍Scope MinorMinor
版本Version 4.64.6
類型Type 正在重定目標Retargeting

受影響的 APIAffected APIs

MemberDescriptor.Equals 的實作不正確Incorrect implementation of MemberDescriptor.Equals

詳細資料Details

MemberDescriptor.Equals 方法的原始實作會比較正在比較之物件的兩個不同字串屬性:分類名稱與描述字串。The original implementation of the MemberDescriptor.Equals method compares two different string properties from the objects being compared: the category name and the description string. 修正方法是比較第一個物件的 Category 和第二個物件的 Category,比較第一個物件的 Description 和第二個物件的 DescriptionThe fix is to compare the Category of the first object to the Category of the second one, and the Description of the first to the Description of the second.

建議Suggestion

如果您的應用程式相依於當描述項相等時有時會傳回 falseMemberDescriptor.Equals,而且您的目標是 .NET Framework 4.6.2 版或更新版本,則有數個選項:If your application depends on MemberDescriptor.Equals sometimes returning false when descriptors are equivalent, and you are targeting the .NET Framework 4.6.2 or later, you have several options:

<runtime>
  <AppContextSwitchOverrides value="Switch.System.MemberDescriptorEqualsReturnsFalseIfEquivalent=true" />
</runtime>

如果您的應用程式目標設為 .NET Framework 4.6.1 或較舊版本,但在 .NET Framework 4.6.2 或更新版本上執行,而您想要啟用這項變更,您可以在 app.config 檔案中新增下列值,將相容性參數設為 falseIf your application targets .NET Framework 4.6.1 or earlier and is running on the .NET Framework 4.6.2 or later and you want this change enabled, you can set the compatibility switch to false by adding the following value to the app.config file:

<runtime>
  <AppContextSwitchOverrides value="Switch.System.MemberDescriptorEqualsReturnsFalseIfEquivalent=false" />
</runtime>
名稱Name Value
影響範圍Scope EdgeEdge
版本Version 4.6.24.6.2
類型Type 正在重定目標Retargeting

受影響的 APIAffected APIs

Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF)

ImageSourceConverter.ConvertFrom 之例外狀況處理程式碼中的 NullReferenceExceptionNullReferenceException in exception handling code from ImageSourceConverter.ConvertFrom

詳細資料Details

ConvertFrom(ITypeDescriptorContext, CultureInfo, Object) 的例外狀況處理程式碼錯誤已導致擲回不正確的 System.NullReferenceException,而不是預期的例外狀況 (System.IO.DirectoryNotFoundExceptionSystem.IO.FileNotFoundException)。An error in the exception handling code for ConvertFrom(ITypeDescriptorContext, CultureInfo, Object) caused an incorrect System.NullReferenceException to be thrown instead of the intended exception ( System.IO.DirectoryNotFoundException or System.IO.FileNotFoundException). 這項變更會修正該錯誤,讓該方法現在擲回正確的例外狀況。This change corrects that error so that the method now throws the right exception.

根據預設,所有以 .NET Framework 4.6.2 和更早版本為目標的應用程式會繼續擲回 System.NullReferenceException 以提供相容性。By default all applications targeting .NET Framework 4.6.2 and earlier continue to throw System.NullReferenceException for compatibility. 以 .NET Framework 4.7 和以上版本為目標的開發人員應該會看到正確的例外狀況。Developers targeting .NET Framework 4.7 and above should see the right exceptions.

建議Suggestion

開發人員若想要在以 .NET Framework 4.7 或更新版本為目標時還原成取得 System.NullReferenceException,可以在其應用程式的 App.config 檔案中新增/合併下列程式碼:Developers who wish to revert to getting System.NullReferenceException when targeting .NET Framework 4.7 or later can add/merge the following to their application's App.config file:

<configuration>
<runtime>
<AppContextSwitchOverrides value="Switch.System.Windows.Media.ImageSourceConverter.OverrideExceptionWithNullReferenceException=true"/>
</runtime>
</configuration>
名稱Name Value
影響範圍Scope EdgeEdge
版本Version 4.74.7
類型Type 正在重定目標Retargeting

受影響的 APIAffected APIs

star-column 空間的 WPF 方格配置WPF Grid allocation of space to star-columns

詳細資料Details

從 .NET Framework 4.7 開始,WPF 取代了 Grid 用來配置 *-column 空間的演算法。Starting with the .NET Framework 4.7, WPF replaces the algorithm that Grid uses to allocate space to *-columns. 在以下幾種情況下,這會使指派給 *-column 的實際寬度產生變化:This will change the actual width assigned to *-columns in a number of cases:

  • 當一或多個資料 * 行的寬度下限或上限覆寫該上的比例配置時。When one or more *-columns also have a minimum or maximum width that overrides the proportional allocation for that colum. (寬度下限可能衍生自明確的 MinWidth 宣告,或衍生自從資料行的內容取得的隱含下限。(The minimum width can derive from an explicit MinWidth declaration, or from an implicit minimum obtained from the column's content. 寬度上限僅能明確地從 MaxWidth 宣告定義)。The maximum width can only be defined explicitly, from a MaxWidth declaration.)

  • 當一或多個 *-columns 宣告極大的 *-weight 時 (大於 10^298)。When one or more *-columns declare an extremely large *-weight, greater than 10^298.

  • 當 *-weights 的差異足以發生浮點不穩定 (溢位、反向溢位、精確度失準) 時。When the *-weights are sufficiently different to encounter floating-point instability (overflow, underflow, loss of precision).

  • 當版面配置進位已啟用,且有效顯示 DPI 夠高時。When layout rounding is enabled, and the effective display DPI is sufficiently high. 在前兩個狀況中,新演算法產生的寬度可能明顯不同於舊演算法產生的寬度;在最後一個狀況中,差異最多會是一或兩個像素。In the first two cases, the widths produced by the new algorithm can be significantly different from those produced by the old algorithm; in the last case, the difference will be at most one or two pixels.

    新的演算法修正了舊演算法中的數個錯誤:The new algorithm fixes several bugs present in the old algorithm:

  • 資料行的總配置可能會超過方格的寬度。Total allocation to columns can exceed the Grid's width. 資料行的按比例共用若低於其大小下限,配置空間時就可能發生這個狀況。This can occur when allocating space to a column whose proportional share is less than its minimum size. 此演算法會配置大小下限,因此,其他資料行的可用空間會減少。The algorithm allocates the minimum size, which decreases the space available to other columns. 如果沒有要配置的 *-columns,總配置將會過大。If there are no *-columns left to allocate, the total allocation will be too large.

  • 總配置的方格寬度可能會不足。Total allocation can fall short of the Grid's width. 這是第 1 點的雙重問題,在為資料行配置空間時,若其按比例共用超過大小上限,但缺少可使用剩餘空間的 *-columns 時,就會發生這個狀況。This is the dual problem to #1, arising when allocating to a column whose proportional share is greater than its maximum size, with no *-columns left to take up the slack.

  • 兩個 *-column 的配置可能不是依其 *-weight 按比例分配。Two *-columns can receive allocations not proportional to their *-weights. 相較於第 1 點/第 2 點,這是程度較輕的錯誤,在為 *-columns A、B 和 C (依此順序) 配置空間時,若 B 的按比例共用違反其下限 (或上限) 條件約束,就會發生這個狀況。This is a milder version of #1/#2, arising when allocating to *-columns A, B, and C (in that order), where B's proportional share violates its min (or max) constraint. 如上所述,這會使資料行 C 的可用的空間產生變化,可能會獲得較 A 更少 (或更多) 的比例配置,As above, this changes the space available to column C, who gets less (or more) proportional allocation than A did,

  • 權數極大 (> 10^298) 的資料行一律會視為擁有 10 ^298 的權數。Columns with extremely large weights (> 10^298) are all treated as if they had weight 10^298. 它們之間 (及權數較小的資料行之間) 的比例差異則可忽略。Proportional differences between them (and between columns with slightly smaller weights) are not honored.

  • 無法正確處理擁有無限權數的資料行。Columns with infinite weights are not handled correctly. [事實上,您無法將權數設為無限大,但這是人為限制。[Actually you can't set a weight to Infinity, but this is an artificial restriction. 配置程式碼會嘗試處理它,但成效不彰。]The allocation code was trying to handle it, but doing a bad job.]

  • 避免溢位、反向溢位時的幾個小問題、精確度失準及類似的浮點數問題。Several minor problems while avoiding overflow, underflow, loss of precision and similar floating-point issues.

  • 版面配置進位的調整在 DPI 足夠高的情況下不正確。Adjustments for layout rounding are incorrect at sufficiently high DPI. 新的演算法會產生符合下列準則的結果︰The new algorithm produces results that meet the following criteria:

    A.A. 指派給 *-column 的實際寬度永遠不會低於其寬度下限或高於其寬度上限。The actual width assigned to a *-column is never less than its minimum width nor greater than its maximum width.
    B.B. 未指派其最小值或最大寬度的每個資料行都會被指派寬度與其粗細的比例。若要精確地說,如果兩個資料行分別以寬度 x 和 y宣告,而且兩個數據行都沒有收到其最小或最大寬度,則指派給資料行的實際寬度 v 和 w 的比例相同: v/w = = x/y。Each -column that is not assigned its minimum or maximum width is assigned a width proportional to its -weight. To be precise, if two columns are declared with width x and y respectively, and if neither column receives its minimum or maximum width, the actual widths v and w assigned to the columns are in the same proportion: v / w == x / y.
    C.C. 配置給多層式資料行的總寬度, " " * 等於配置給條件約束資料行之後可用的空間 (固定、自動和資料行,這些資料行會配置給它們的 * 最小或最大寬度) 。The total width allocated to "proportional" *-columns is equal to the space available after allocating to the constrained columns (fixed, auto, and *-columns that are allocated their min or max width). 這可能是零,例如,若寬度下限的總和超過方格可用的寬度。This might be zero, for instance if the sum of the minimum widths exceeds the Grid's available width.
    D.D. 以上所述是就「理想」的版面配置而言。All these statements are to be interpreted with respect to the "ideal" layout. 當版面配置進位作用中時,實際寬度與理想寬度最多會相差一個像素。When layout rounding is in effect, the actual widths can differ from the ideal widths by as much as one pixel.
    舊的演算法能實現 (A) 準則,卻無法實現上述狀況中的其他準則。The old algorithm honored (A) but failed to honor the other criteria in the cases outlined above.

    本文中有關資料行和寬度的所有內容也適用於資料列和高度。Everything said about columns and widths in this article applies as well to rows and heights.

建議Suggestion

根據預設,以 .NET Framework 4.7 開始的 .NET Framework 版本為目標的應用程式會看見新的演算法,而以 .NET Framework 4.6.2 或更舊版本為目標的應用程式會看見舊的演算法。By default, apps that target versions of the .NET Framework starting with the .NET Framework 4.7 will see the new algorithm, while apps that target the .NET Framework 4.6.2 or earlier versions will see the old algorithm.

若要覆寫預設值,請使用下列組態設定︰To override the default, use the following configuration setting:

<runtime>
<AppContextSwitchOverrides value="Switch.System.Windows.Controls.Grid.StarDefinitionsCanExceedAvailableSpace=true" />
</runtime>

true 會選取舊的演算法,false 會選取新的演算法。The value true selects the old algorithm, false selects the new algorithm.

名稱Name Value
範圍Scope MinorMinor
版本Version 4.74.7
類型Type 正在重定目標Retargeting

邊界的 WPF 版面配置進位已變更WPF layout rounding of margins has changed

詳細資料Details

邊界的進位方式以及邊界內部的框線和背景皆有所變更。The way in which margins are rounded and borders and the background inside of them has changed. 此變更的結果:As a result of this change:

  • 項目寬度或高度的增減最多不超過一個像素。The width or height of elements may grow or shrink by at most one pixel.
  • 物件的位置的位最多不超過一個像素。The placement of an object can move by at most one pixel.
  • 置中項目的垂直或水平位移最多不超過一個像素。Centered elements can be vertically or horizontally off center by at most one pixel. 預設只有以 .NET Framework 4.6 為目標的應用程式才會啟用此新版面配置。By default, this new layout is enabled only for apps that target the .NET Framework 4.6.

建議Suggestion

由於此修改會停用高 DPI 之 WPF 控制項右側或底端的裁剪功能,因此,應用程式若是以舊版 .NET Framework 為目標,但要在 .NET Framework 4.6 上執行,可將下行加入 app.config 檔案中的 <runtime> 區段來選擇使用此新行為:Since this modification tends to eliminate clipping of the right or bottom of WPF controls at high DPIs, apps that target earlier versions of the .NET Framework but are running on the .NET Framework 4.6 can opt into this new behavior by adding the following line to the <runtime> section of the app.config file:

<AppContextSwitchOverrides value="Switch.MS.Internal.DoNotApplyLayoutRoundingToMarginsAndBorderThickness=false" />'

應用程式若是以 .NET Framework 4.6 為目標,但想使用先前的配置演算法來呈現 WPF 控制項,可將下行新增至 app.config 檔案中的 <runtime> 區段,以執行此作業:Apps that target the .NET Framework 4.6 but want WPF controls to render using the previous layout algorithm can do so by adding the following line to the <runtime> section of the app.config file:

<AppContextSwitchOverrides value="Switch.MS.Internal.DoNotApplyLayoutRoundingToMarginsAndBorderThickness=true" />'.
名稱Name Value
影響範圍Scope MinorMinor
版本Version 4.64.6
類型Type 正在重定目標Retargeting

WPF 指標式觸控堆疊WPF Pointer-Based Touch Stack

詳細資料Details

這項變更將能夠啟用選用的 WM_POINTER 式 WPF 觸控/手寫筆堆疊。This change adds the ability to enable an optional WM_POINTER based WPF touch/stylus stack. 開發人員若未明確地啟用此項目,應該不會看到任何 WPF 觸控/手寫筆行為的變更。以下是選用之 WM_POINTER 式觸控/手寫筆堆疊的目前已知問題:Developers that do not explicitly enable this should see no change in WPF touch/stylus behavior.Current Known Issues With optional WM_POINTER based touch/stylus stack:

  • 不支援即時筆跡。No support for real-time inking.
  • 雖然筆跡和手寫筆外掛程式還能運作,但它們是在 UI 執行緒上處理,可能會導致效能不佳。While inking and StylusPlugins will still work, they will be processed on the UI Thread which can lead to poor performance.
  • 從觸控/手寫筆事件提升為滑鼠事件的變更,因而產生行為變更Behavioral changes due to changes in promotion from touch/stylus events to mouse events
  • 操作可能有不同的行為Manipulation may behave differently
  • 拖放動作無法對觸控輸入顯示適當的回應Drag/Drop will not show appropriate feedback for touch input
  • 這不影響手寫筆輸入This does not affect stylus input
  • 無法再針對觸控/手寫筆事件起始拖放動作Drag/Drop can no longer be initiated on touch/stylus events
  • 這可能會使應用程式停止回應到偵測到滑鼠輸入為止。This can potentially hang the application until mouse input is detected.
  • 開發人員應改為從滑鼠事件起始拖放動作。Instead, developers should initiate drag and drop from mouse events.

建議Suggestion

想要啟用此堆疊的開發人員可以將以下內容新增/合併至其應用程式的 App.config 檔案:Developers who wish to enable this stack can add/merge the following to their application's App.config file:

<configuration>
<runtime>
<AppContextSwitchOverrides value="Switch.System.Windows.Input.Stylus.EnablePointerSupport=true"/>
</runtime>
</configuration>

移除此項目或將其值設為 false 可關閉這個選用堆疊。請注意,此堆疊僅適用於 Windows 10 Creators Update 和更新版本。Removing this or setting the value to false will turn this optional stack off.Note that this stack is available only on Windows 10 Creators Update and above.

名稱Name Value
影響範圍Scope EdgeEdge
版本Version 4.74.7
類型Type 正在重定目標Retargeting

Windows Workflow Foundation (WF)Windows Workflow Foundation (WF)

工作流程總和檢查碼從 MD5 變更為 SHA1Workflow checksums changed from MD5 to SHA1

詳細資料Details

為了支援使用 Visual Studio 進行偵錯,工作流程執行階段會使用雜湊演算法為工作流程執行個體產生總和檢查碼。To support debugging with Visual Studio, the Workflow runtime generates a checksum for a workflow instance using a hashing algorithm. 在 .NET Framework 4.6.2 和更早版本中,工作流程總和檢查碼雜湊使用 MD5 演算法,它會在啟用 FIPS 的系統上造成問題。In the .NET Framework 4.6.2 and earlier versions, workflow checksum hashing used the MD5 algorithm, which caused issues on FIPS-enabled systems. 從 .NET Framework 4.7 開始,演算法是 SHA1。Starting with the .NET Framework 4.7, the algorithm is SHA1. 如果您的程式碼已保存這些總和檢查碼,就會不相容。If your code has persisted these checksums, they will be incompatible.

建議Suggestion

如果您的程式碼因為總和檢查碼失敗而無法載入工作流程執行個體,請嘗試將 AppContext 參數 "Switch.System.Activities.UseMD5ForWFDebugger" 設為 true。在程式碼中:If your code is unable to load workflow instances due to a checksum failure, try setting the AppContext switch "Switch.System.Activities.UseMD5ForWFDebugger" to true.In code:

System.AppContext.SetSwitch("Switch.System.Activities.UseMD5ForWFDebugger", true);

或者,在組態中:Or in configuration:

<configuration>
  <runtime>
    <AppContextSwitchOverrides value="Switch.System.Activities.UseMD5ForWFDebugger=true" />
  </runtime>
</configuration>
名稱Name Value
影響範圍Scope MinorMinor
版本Version 4.74.7
類型Type 正在重定目標Retargeting

WorkflowDesigner.Load 不會移除符號屬性WorkflowDesigner.Load doesn't remove symbol property

詳細資料Details

如果工作流程設計工具是以 .NET Framework 4.5 為目標,並使用 Load() 方法載入重新裝載的 3.5 工作流程,則會在儲存工作流程時擲回 System.Xaml.XamlDuplicateMemberExceptionWhen targeting the .NET Framework 4.5 in the workflow designer, and loading a re-hosted 3.5 workflow with the Load() method, a System.Xaml.XamlDuplicateMemberException is thrown while saving the workflow.

建議Suggestion

只有在工作流程設計工具是以 .NET Framework 4.5 為目標時才會出現此 Bug,因此可藉由將 WorkflowDesigner.Context.Services.GetService&lt;DesignerConfigurationService&gt;().TargetFrameworkName 設定為 .NET Framework 4.0 來解決。或者,可以使用 Load(String) 方法載入工作流桯來避免問題,而不要使用 Load()This bug only manifests when targeting .NET Framework 4.5 in the workflow designer, so it can be worked around by setting the WorkflowDesigner.Context.Services.GetService&lt;DesignerConfigurationService&gt;().TargetFrameworkName to the 4.0 .NET Framework.Alternatively, the issue may be avoided by using the Load(String) method to load the workflow, instead of Load().

名稱Name Value
影響範圍Scope 主要Major
版本Version 4.54.5
類型Type 正在重定目標Retargeting

受影響的 APIAffected APIs

XML、XSLTXML, XSLT

無效的代理字組會擲回 XmlWriterXmlWriter throws on invalid surrogate pairs

詳細資料Details

針對以 .NET Framework 4.5.2 或之前版本為目標的應用程式,使用例外狀況後援處理寫入無效的 Surrogate 字組時不一定每次都會擲回例外狀況。For apps that target the .NET Framework 4.5.2 or previous versions, writing an invalid surrogate pair using exception fallback handling does not always throw an exception. 針對以 .NET Framework 4.6 為目標的應用程式,嘗試寫入無效的代理字組會擲回 System.ArgumentException 例外狀況。For apps that target the .NET Framework 4.6, attempting to write an invalid surrogate pair throws an System.ArgumentException.

建議Suggestion

如有必要,可以將目標設為 .NET Framework 4.5.2 或更早版本以避免這項中斷。If necessary, this break can be avoided by targeting the .NET Framework 4.5.2 or earlier. 或者,可以將無效的代理字組字組預先處理成有效的 XML,再寫入它們。Alternatively, invalid surrogate pairs can be pre-processed into valid xml prior to writing them.

名稱Name Value
影響範圍Scope EdgeEdge
版本Version 4.64.6
類型Type 正在重定目標Retargeting

受影響的 APIAffected APIs

如果使用複合索引鍵,而且一個索引鍵為空白,XSD 結構描述驗證現在會正確地偵測唯一條件約束的違規XSD Schema validation now correctly detects violations of unique constraints if compound keys are used and one key is empty

詳細資料Details

.NET Framework 4.6 之前的版本有錯誤 (bug),會導致 XSD 驗證在其中一個索引鍵為空白時,無法偵測複合索引鍵上的唯一條件約束。Versions of the .NET Framework prior to 4.6 had a bug that caused XSD validation to not detect unique constraints on compound keys if one of the keys was empty. 在 .NET Framework 4.6 中,已修正此問題。In the .NET Framework 4.6, this issue is corrected. 這會導致更正確的驗證,但也可能會導致之前可驗證的某些 XML 無法驗證。This will result in more correct validation, but it may also result in some XML not validating which previously would have.

建議Suggestion

如果需要較鬆散的 .NET Framework 4.0 驗證,正在驗證的應用程式可以將目標設為 .NET Framework 4.5 版 (或舊版)。If looser .NET Framework 4.0 validation is needed, the validating application can target version 4.5 (or earlier) of the .NET Framework. 不過,重定目標為 .NET Framework 4.6 時,應完成程式碼檢閱,以確保重複的複合索引鍵 (如本問題說明中所述) 不會導致無效。When retargeting to .NET Framework 4.6, however, code review should be done to be sure that duplicate compound keys (as described in this issue's description) are not expected to validate.

名稱Name Value
影響範圍Scope EdgeEdge
版本Version 4.64.6
類型Type 正在重定目標Retargeting