MissingManifestResourceException 類別

定義

如果主要組件沒有包含中性文化特性 (Culture) 的資源,且遺漏適當的附屬組件,所擲回的例外狀況。The exception that is thrown if the main assembly does not contain the resources for the neutral culture, and an appropriate satellite assembly is missing.

public ref class MissingManifestResourceException : SystemException
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class MissingManifestResourceException : SystemException
type MissingManifestResourceException = class
    inherit SystemException
Public Class MissingManifestResourceException
Inherits SystemException
繼承
MissingManifestResourceException
屬性

備註

.NET 應用程式.NET apps

在 .NET Framework 和 .net Core 應用程式MissingManifestResourceException中, 當嘗試抓取資源失敗時, 會擲回, 因為無法從特定元件載入中性文化特性的資源集。In .NET Framework and .NET Core apps, MissingManifestResourceException is thrown when the attempt to retrieve a resource fails because the resource set for the neutral culture could not be loaded from a particular assembly. 雖然當您嘗試抓取特定資源時, 會擲回例外狀況, 但它是因為載入資源集而不是找出資源失敗所造成。Although the exception is thrown when you try to retrieve a particular resource, it is caused by the failure to load the resource set rather than the failure to find the resource.

注意

如需詳細資訊, 請參閱ResourceManager類別主題中的「處理 system.resources.missingmanifestresourceexception 例外狀況」一節。For additional information, see the "Handling a MissingManifestResourceException Exception" section in the ResourceManager class topic.

例外狀況的主要原因包括下列各項:The main causes of the exception include the following:

  • 資源集不是由其完整名稱所識別。The resource set is not identified by its fully qualified name. 例如, 如果對baseName ResourceManager.ResourceManager(String, Assembly)方法的呼叫中的參數指定不含命名空間之資源集的根名稱, 但資源集是儲存在其元件中時指派ResourceManager.GetString , 則呼叫方法擲回這個例外狀況。For example, if the baseName parameter in the call to the ResourceManager.ResourceManager(String, Assembly) method specifies the root name of the resource set without a namespace, but the resource set is assigned a namespace when it is stored in its assembly, the call to the ResourceManager.GetString method throws this exception.

    如果您已將包含預設文化特性資源的 .resources 檔案內嵌在可執行檔中, 而您的MissingManifestResourceException應用程式擲回, 則可以使用反映工具 (例如 IL 解譯器(Ildasm))來判斷完整的資源的名稱。If you have embedded the .resources file that contains the default culture's resources in your executable and your app is throwing a MissingManifestResourceException, you can use a reflection tool such as the IL Disassembler (Ildasm.exe) to determine the fully qualified name of the resource. 在 [ILDasm] 中, 按兩下可執行檔的資訊清單標籤以開啟資訊清單視窗。In ILDasm, double click the executable's MANIFEST label to open the MANIFEST window. 資源會顯示.mresource為專案, 並在外部元件參考和自訂群組件層級屬性之後列出。Resources appear as .mresource items and are listed after external assembly references and custom assembly-level attributes. 您也可以編譯下列簡單的公用程式, 其中會列出元件中內嵌資源的完整名稱, 其名稱會以命令列參數的形式傳遞給它。You can also compile the following simple utility, which lists the fully qualified names of embedded resources in the assembly whose name is passed to it as a command-line parameter.

    using System;
    using System.IO;
    using System.Reflection;
    using System.Resources;
    
    public class Example
    {
       public static void Main()
       {
          if (Environment.GetCommandLineArgs().Length == 1) { 
             Console.WriteLine("No filename.");
             return;
          }
          
          string filename = Environment.GetCommandLineArgs()[1].Trim();
          // Check whether the file exists.
          if (! File.Exists(filename)) {
             Console.WriteLine("{0} does not exist.", filename);
             return;
          }   
          
          // Try to load the assembly.
          Assembly assem = Assembly.LoadFrom(filename);
          Console.WriteLine("File: {0}", filename);
             
          // Enumerate the resource files.
          string[] resNames = assem.GetManifestResourceNames();
          if (resNames.Length == 0)
             Console.WriteLine("   No resources found.");
    
          foreach (var resName in resNames)
             Console.WriteLine("   Resource: {0}", resName.Replace(".resources", ""));
    
          Console.WriteLine();
       }
    }
    
    Imports System.IO
    Imports System.Reflection
    Imports System.Resources
    
    Module Example
       Public Sub Main()
          If Environment.GetCommandLineArgs.Length = 1 Then 
             Console.WriteLine("No filename.")
             Exit Sub
          End If
          Dim filename As String = Environment.GetCommandLineArgs(1).Trim()
          ' Check whether the file exists.
          If Not File.Exists(filename) Then
             Console.WriteLine("{0} does not exist.", filename)
             Exit Sub
          End If   
          
          ' Try to load the assembly.
          Dim assem As Assembly = Assembly.LoadFrom(filename)
          Console.WriteLine("File: {0}", filename)
             
          ' Enumerate the resource files.
          Dim resNames() As String = assem.GetManifestResourceNames()
          If resNames.Length = 0 Then
             Console.WriteLine("   No resources found.")
          End If
          For Each resName In resNames
             Console.WriteLine("   Resource: {0}", resName.Replace(".resources", ""))
          Next
          Console.WriteLine()
       End Sub
    End Module
    
  • 您可以依據資源檔名稱 (連同其選擇性命名空間) 及其副檔名 (而不是單獨使用其命名空間和根檔案名) 來識別資源集。You identify the resource set by its resource file name (along with its optional namespace) and its file extension rather than by its namespace and root file name alone. 例如, 如果中性文化特性GlobalResources的資源集命名為, 而且您將GlobalResources.resources ( baseName而不是GlobalResources) 的值提供給此函式的參數ResourceManager.ResourceManager(String, Assembly) , 就會擲回這個例外狀況。For example, this exception is thrown if the neutral culture's resource set is named GlobalResources and you supply a value of GlobalResources.resources (instead of GlobalResources) to the baseName parameter of the ResourceManager.ResourceManager(String, Assembly) constructor.

  • 找不到在方法呼叫中識別的特定文化特性資源集, 而且無法載入回溯資源集。The culture-specific resource set that is identified in a method call cannot be found, and the fallback resource set cannot be loaded. 例如, 如果您建立英文 (美國) 和俄羅斯 (俄文) 文化特性的附屬元件, 但無法提供中性文化特性的資源集, 則如果應用程式目前的文化特性是英文 (英國), 就會擲回此例外狀況。For example, if you create satellite assemblies for the English (United States) and Russia (Russian) cultures but you fail to provide a resource set for the neutral culture, this exception is thrown if your app's current culture is English (Great Britain).

MissingManifestResourceException使用 HRESULT COR_E_MISSINGMANIFESTRESOURCE, 其值為0x80131532。MissingManifestResourceException uses the HRESULT COR_E_MISSINGMANIFESTRESOURCE, which has the value 0x80131532.

MissingManifestResourceException使用支援參考Equals相等的預設實值。MissingManifestResourceException uses the default Equals implementation, which supports reference equality.

如需執行個體的初始屬性值的清單MissingManifestResourceException,請參閱MissingManifestResourceException建構函式。For a list of initial property values for an instance of MissingManifestResourceException, see the MissingManifestResourceException constructors.

注意

我們建議您在主要元件中包含一組中性的資源, 因此如果無法使用附屬元件, 您的應用程式將不會失敗。We recommend that you include a neutral set of resources in your main assembly, so your app won't fail if a satellite assembly is unavailable.

通用 Windows 平臺 (UWP) 應用程式Universal Windows Platform (UWP) apps

UWP 應用程式會在單一套件資源索引 (pri) 檔案中, 部署多個文化特性的資源, 包括中性文化特性。UWP apps deploy resources for multiple cultures, including the neutral culture, in a single package resource index (.pri) file. 因此, 在 UWP 應用程式中, 如果找不到慣用文化特性的資源, MissingManifestResourceException則會在下列任一情況下擲回:As a result, in a UWP app, if resources for the preferred culture cannot be found, the MissingManifestResourceException is thrown under either of the following conditions:

  • 應用程式不包含 pri 檔案, 或無法開啟 pri 檔案。The app does not include a .pri file, or the .pri file could not be opened.

  • 應用程式的 pri 檔案不包含指定根名稱的資源集。The app's .pri file does not contain a resource set for the given root name.

建構函式

MissingManifestResourceException()

使用預設屬性,初始化 MissingManifestResourceException 類別的新執行個體。Initializes a new instance of the MissingManifestResourceException class with default properties.

MissingManifestResourceException(SerializationInfo, StreamingContext)

從序列化資料中,初始化 MissingManifestResourceException 類別的新執行個體。Initializes a new instance of the MissingManifestResourceException class from serialized data.

MissingManifestResourceException(String)

使用指定的錯誤訊息,初始化 MissingManifestResourceException 類別的新執行個體。Initializes a new instance of the MissingManifestResourceException class with the specified error message.

MissingManifestResourceException(String, Exception)

使用指定的錯誤訊息以及造成此例外狀況的內部例外狀況的參考,初始化 MissingManifestResourceException 類別的新執行個體。Initializes a new instance of the MissingManifestResourceException class with a specified error message and a reference to the inner exception that is the cause of this exception.

屬性

Data

取得提供例外狀況之其他使用者定義相關資訊的索引鍵/值組集合。Gets a collection of key/value pairs that provide additional user-defined information about the exception.

(繼承來源 Exception)
HelpLink

取得或設定與這個例外狀況相關聯的說明檔連結。Gets or sets a link to the help file associated with this exception.

(繼承來源 Exception)
HResult

取得或設定 HRESULT,它是指派給特定例外狀況的編碼數值。Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception.

(繼承來源 Exception)
InnerException

取得造成目前例外狀況的 Exception 執行個體。Gets the Exception instance that caused the current exception.

(繼承來源 Exception)
Message

取得描述目前例外狀況的訊息。Gets a message that describes the current exception.

(繼承來源 Exception)
Source

取得或設定造成錯誤的應用程式或物件的名稱。Gets or sets the name of the application or the object that causes the error.

(繼承來源 Exception)
StackTrace

取得呼叫堆疊上即時運算框架的字串表示。Gets a string representation of the immediate frames on the call stack.

(繼承來源 Exception)
TargetSite

取得擲回目前例外狀況的方法。Gets the method that throws the current exception.

(繼承來源 Exception)

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetBaseException()

在衍生類別中覆寫時,傳回一或多個後續的例外狀況的根本原因 ExceptionWhen overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions.

(繼承來源 Exception)
GetHashCode()

作為預設雜湊函數。Serves as the default hash function.

(繼承來源 Object)
GetObjectData(SerializationInfo, StreamingContext)

在衍生類別中覆寫時,使用例外狀況的資訊設定 SerializationInfoWhen overridden in a derived class, sets the SerializationInfo with information about the exception.

(繼承來源 Exception)
GetType()

取得目前執行個體的執行階段類型。Gets the runtime type of the current instance.

(繼承來源 Exception)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
ToString()

建立並傳回目前例外狀況的字串表示。Creates and returns a string representation of the current exception.

(繼承來源 Exception)

事件

SerializeObjectState

當例外狀況序列化,以建立包含例外狀況相關序列化資料的例外狀況狀態物件時,就會發生此事件。Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception.

(繼承來源 Exception)

適用於

另請參閱