使用 Microsoft 登入
登入或建立帳戶。
您好:
選取其他帳戶。
您有多個帳戶
選擇您要用來登入的帳戶。

簡介

若要在安裝Microsoft Visual Studio 2012 更新 2之後,可能會發生可攜式類別庫的問題。本文說明這些問題和其因應措施。

問題 1

狀況

您可以使用資源來建置可移植的類別庫專案,安裝Visual Studio 2012 更新 2之後,您可能會收到下列錯誤訊息︰

'設計成用 System.Type' 沒有包含 '組件' 的定義,而且找不到任何擴充方法 '組件' 接受的型別 '設計成用 System.Type' 的第一個引數 (您是否遺漏 using 指示詞或組件參考?)

注意當您使用 Microsoft Visual C# 時,您會收到這個錯誤。

'組件' 不是 '設計成用 system.type' 成員

注意當您使用 Microsoft Visual Basic 時,您會收到這個錯誤。

其中一個下列的平台為目標專案中時,就會發生這個問題︰

  • Microsoft.NET Framework 4.5 和.NET 對 Windows 存放區的應用程式

  • .NET Framework 4.5 和 Windows Phone 8

  • .NET Framework 4.5,對 Windows 存放區的應用程式,.NET 和 Windows Phone 8


因應措施

若要解決這個問題,請修正設計工具產生的程式碼資源檔。若要這麼做,請按兩下 [錯誤訊息中,,,然後執行下列步驟︰

針對視覺化 C#

  1. 加入下列 using 指示詞︰

    using System.Reflection;
  2. 找到下列的程式碼︰

    typeof(Resource1).Assembly

    該程式碼取代下列程式碼中︰

    typeof(Resource1).GetTypeInfo().Assembly

下列程式碼是有此問題的範例︰

        /// <summary> 
/// Returns the cached ResourceManager instance used by this class.

/// </summary>

[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]internal static global::System.Resources.ResourceManager ResourceManager { get {

if (object.ReferenceEquals(resourceMan, null)) {

global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("PortableClassLibrary2.Resource1", typeof(Resource1).Assembly);

resourceMan = temp;

}

return resourceMan;
}
}


Visual Basic

  1. 加入下列 using 指示詞︰

    Imports System.Reflection;
  2. 找到下列的程式碼︰

    GetType(Resource1).Assembly

    該程式碼取代下列程式碼中︰

    GetType(Resource1).GetTypeInfo().Assembly

下列程式碼是有此問題的範例︰

        '''<summary>
''' Returns the cached ResourceManager instance used by this class.

'''</summary>

<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _

Friend Shared ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager

Get

If Object.ReferenceEquals(resourceMan, Nothing) Then

Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("PortableClassLibrary1.Resource1", GetType(Resource1).Assembly)

resourceMan = temp

End If

Return resourceMan

End Get

End Property


問題 2

狀況

若要建置可移植的類別庫專案,安裝Visual Studio 2012 更新 2之後,您無法使用資源。此外,可能會收到許多不同的錯誤訊息。例如,您可能會收到下列錯誤訊息之一︰

'System.Net.HttpStatusCode' 的型別被定義在未被參考的組件。您必須加入至組件參考 ' System.Net、 版本 = 2.0.5.0,文化特性 = 中性,PublicKeyToken = 7cec85d7bea7798e,Retargetable = Yes'。


無法隱含轉換成的型別 'System.Net.HttpStatusCode' ' System.Net.HttpStatusCode [%programfiles%\Reference Assemblies\Microsoft\Framework\。NETPortable\v4.5\Profile\Profile78\System.Net.Primitives.dll]'


請注意其中一個下列的平台為目標專案中時,就會發生這個問題︰

  • .NET Framework 4.5 和 Windows Phone 8

  • .NET Framework 4.5,對 Windows 存放區的應用程式,.NET 和 Windows Phone 8


原因

之所以發生這個問題,是因為當 Visual Studio 2012 更新 2 之後安裝 Windows Phone 軟體開發套件 (SDK) 8.0,才安裝。因此,下列檔案已刪除︰

  • %programfiles%\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.5\Profile\Profile49\System.Net.dll

  • %programfiles%\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.5\Profile\Profile49\System.ServiceModel.dll

  • %programfiles%\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.5\Profile\Profile78\System.Net.dll

  • %programfiles%\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.5\Profile\Profile78\System.ServiceModel.dll


因應措施

若要解決這個問題,請執行 Visual Studio 2012 修復程式。若要執行這項操作,請參考下列步驟:

  1. 按一下 [開始],按一下 [控制台]、 按一下 [程式集],然後按一下程式和功能

  2. 以滑鼠右鍵按一下 [已安裝的 Visual Studio 2012 的版本,然後按一下 [變更

  3. Visual Studio 2012 安裝程式精靈開啟時,請按一下 [修復]。

注意如果您設定新的開發人員環境時,要避免這個問題,您應該先安裝 Visual Studio 2012 更新 2 才能安裝 Windows Phone 8.0 SDK。

狀態

Microsoft 已確認這是<套用>一節所列出的 Microsoft 產品的問題。

需要更多協助嗎?

想要其他選項嗎?

探索訂閱權益、瀏覽訓練課程、瞭解如何保護您的裝置等等。

社群可協助您詢問並回答問題、提供意見反應,以及聆聽來自具有豐富知識的專家意見。

這項資訊有幫助嗎?

您對語言品質的滿意度如何?
以下何者是您會在意的事項?
按下 [提交] 後,您的意見反應將用來改善 Microsoft 產品與服務。 您的 IT 管理員將能夠收集這些資料。 隱私權聲明。

感謝您的意見反應!

×