MissingManifestResourceException 类


主程序集不包含非特定区域性的资源和适当的附属程序集缺少时引发的异常。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
public class MissingManifestResourceException : SystemException
type MissingManifestResourceException = class
    inherit SystemException
Public Class MissingManifestResourceException
Inherits SystemException


.NET 应用.NET apps

在 .NET Framework 和 .NET Core 应用程序中,如果尝试检索资源失败,因为无法从特定程序集加载非特定区域性的资源集,则会引发 MissingManifestResourceExceptionIn .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 类主题中的 "处理 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. 例如,如果对 ResourceManager.ResourceManager(String, Assembly) 方法的调用中的 baseName 参数指定了没有命名空间的资源集的根名称,但在将该资源集存储在其程序集中时,将为该资源集分配一个命名空间,则对 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.");
          string filename = Environment.GetCommandLineArgs()[1].Trim();
          // Check whether the file exists.
          if (! File.Exists(filename)) {
             Console.WriteLine("{0} does not exist.", filename);
          // 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", ""));
    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", ""))
       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 (而不是 GlobalResources)的值提供给 ResourceManager.ResourceManager(String, Assembly) 构造函数的 baseName 参数,则会引发此异常。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 使用值为0x80131532 的 HRESULT COR_E_MISSINGMANIFESTRESOURCE。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 应用中,如果找不到首选区域性的资源,则在下列情况下会引发 MissingManifestResourceExceptionAs 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 类的新实例。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 类的新实例。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.



获取键/值对的集合,这些键/值对提供有关该异常的其他用户定义信息。Gets a collection of key/value pairs that provide additional user-defined information about the exception.

(继承自 Exception)

获取或设置指向与此异常关联的帮助文件链接。Gets or sets a link to the help file associated with this exception.

(继承自 Exception)

获取或设置 HRESULT(一个分配给特定异常的编码数字值)。Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception.

(继承自 Exception)

获取导致当前异常的 Exception 实例。Gets the Exception instance that caused the current exception.

(继承自 Exception)

获取描述当前异常的消息。Gets a message that describes the current exception.

(继承自 Exception)

获取或设置导致错误的应用程序或对象的名称。Gets or sets the name of the application or the object that causes the error.

(继承自 Exception)

获取调用堆栈上的即时框架字符串表示形式。Gets a string representation of the immediate frames on the call stack.

(继承自 Exception)

获取引发当前异常的方法。Gets the method that throws the current exception.

(继承自 Exception)



确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)

当在派生类中重写时,返回 Exception,它是一个或多个并发的异常的根本原因。When overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions.

(继承自 Exception)

用作默认哈希函数。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)

获取当前实例的运行时类型。Gets the runtime type of the current instance.

(继承自 Exception)

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)

创建并返回当前异常的字符串表示形式。Creates and returns a string representation of the current exception.

(继承自 Exception)



当异常被序列化用来创建包含有关该异常的徐列出数据的异常状态对象时会出现该问题。Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception.

(继承自 Exception)