MissingSatelliteAssemblyException 类

定义

默认区域性资源的附属程序集丢失时引发的异常。The exception that is thrown when the satellite assembly for the resources of the default culture is missing.

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

示例

下面的示例使用 NeutralResourcesLanguageAttribute 特性来指示英语是应用的默认区域性,并将其资源存储在附属程序集中。The following example uses the NeutralResourcesLanguageAttribute attribute to indicate that English is the app's default culture and that its resources are stored in a satellite assembly. 此示例本身包含英语和法语区域性的 .txt 文件中的资源,如下表所述:The example itself includes resources in .txt files for the English and French cultures, as described in the following table:

CultureCulture 资源名称/值Resource name/value 文件名称File name
英语English Greet=HelloGreet=Hello Greet.en.txtGreet.en.txt
法语French Greet=BonjourGreet=Bonjour Greet.fr.txtGreet.fr.txt

以下源代码构建一个应用程序,该应用程序首先将当前 UI 区域性更改为法语(法国),然后再更改为俄语(俄罗斯),并在这两种情况下显示适当的区域性特定资源。The following source code builds an app that changes the current UI culture first to French (France) and then to Russian (Russia) and displays an appropriate culture-specific resource in both cases.

using System;
using System.Globalization;
using System.Resources;
using System.Threading;

[assembly:NeutralResourcesLanguageAttribute("en", UltimateResourceFallbackLocation.Satellite)]

public class Example
{
   public static void Main()
   {
      ResourceManager rm = new ResourceManager("GreetResources", typeof(Example).Assembly); 
      Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("fr-FR");
      Console.WriteLine("The current UI culture is {0}", Thread.CurrentThread.CurrentUICulture.Name);
      Console.WriteLine(rm.GetString("Greet"));
      
      Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("ru-RU");
      Console.WriteLine("The current UI culture is {0}", Thread.CurrentThread.CurrentUICulture.Name);
      Console.WriteLine(rm.GetString("Greet"));
   }
}
// The example displays the following output when created using BuildNoDefault.bat: 
//    The current UI culture is fr-FR
//    Bonjour
//    The current UI culture is ru-RU
//    
//    Unhandled Exception: System.Resources.MissingSatelliteAssemblyException: 
//    The satellite assembly named "HelloWorld.resources.dll, PublicKeyToken=" for fallback culture 
//    "en" either could not be found or could not be loaded. This is generally a setup problem. 
//    Please consider reinstalling or repairing the application.
//       at System.Resources.ManifestBasedResourceGroveler.HandleSatelliteMissing()
//       at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo cult
//    ure, Dictionary`2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackC
//    rawlMark& stackMark)
//       at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture
//    , Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark)
//       at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean
//     createIfNotExists, Boolean tryParents)
//       at System.Resources.ResourceManager.GetString(String name, CultureInfo culture)
//       at Example.Main()
// The example displays the following output when created using BuildDefault.bat:
//    The current UI culture is fr-FR
//    Bonjour
//    The current UI culture is ru-RU
//    Hello
Imports System.Globalization
Imports System.Resources
Imports System.Threading

<assembly:NeutralResourcesLanguageAttribute("en", UltimateResourceFallbackLocation.Satellite)>

Module Example
   Public Sub Main()
      Dim rm As New ResourceManager("GreetResources", GetType(Example).Assembly) 
      Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("fr-FR")
      Console.WriteLine("The current UI culture is {0}", Thread.CurrentThread.CurrentUICulture.Name)
      Console.WriteLine(rm.GetString("Greet"))
      
      Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("ru-RU")
      Console.WriteLine("The current UI culture is {0}", Thread.CurrentThread.CurrentUICulture.Name)
      Console.WriteLine(rm.GetString("Greet"))
   End Sub
End Module
' The example displays the following output:
'    The current UI culture is fr-FR
'    Bonjour
'    The current UI culture is ru-RU
'    
'    Unhandled Exception: System.Resources.MissingSatelliteAssemblyException: 
'    The satellite assembly named "HelloWorld.resources.dll, PublicKeyToken=" for fallback culture 
'    "en" either could not be found or could not be loaded. This is generally a setup problem. 
'    Please consider reinstalling or repairing the application.
'       at System.Resources.ManifestBasedResourceGroveler.HandleSatelliteMissing()
'       at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo cult
'    ure, Dictionary`2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackC
'    rawlMark& stackMark)
'       at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture
'    , Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark)
'       at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean
'     createIfNotExists, Boolean tryParents)
'       at System.Resources.ResourceManager.GetString(String name, CultureInfo culture)
'       at Example.Main()
' The example displays the following output when created using BuildDefault.bat:
'    The current UI culture is fr-FR
'    Bonjour
'    The current UI culture is ru-RU
'    Hello

您可以使用以下批处理文件生成并执行该示例的C#版本。You can use the following batch file to build and execute the C# version of the example. 如果使用 Visual Basic,请将 csc 替换为 vbc,并将 .cs 扩展名替换为 .vbIf you're using Visual Basic, replace csc with vbc, and replace the .cs extension with .vb. 当执行该示例时,它会显示法语语言字符串,但当当前区域性为俄语(俄罗斯)时将引发 MissingSatelliteAssemblyException 异常。When the example is executed, it displays a French language string but throws a MissingSatelliteAssemblyException exception when the current culture is Russian (Russia). 这是因为包含默认区域性的资源的附属程序集 en\HelloWorld.dll 不存在。This is because the satellite assembly en\HelloWorld.dll that contains the resources of the default culture does not exist.

  
vbc HelloWorld.vb  
  
md fr  
resgen Greet.fr.txt  
al /out:fr\HelloWorld.resources.dll /culture:fr /embed:GreetResources.fr.resources  
  
HelloWorld  
  

您可以使用以下批处理文件生成并执行该示例的 Visual Basic 版本。You can use the following batch file to build and execute the Visual Basic version of the example. 如果使用C#的是,请将 vbc 替换为 csc,并将 .vb 扩展替换为 .csIf you're using C#, replace vbc with csc, and replace the .vb extension with .cs. 当执行该示例时,如果当前 UI 区域性为法语(法国),则它将显示法语的字符串。When the example is executed, it displays a French language string when the current UI culture is French (France). 当当前 UI 区域性为俄罗斯(俄语)时,它会显示英语语言字符串,因为俄文语言资源不存在,但资源管理器可以从附属程序集 en\HelloWorld2.dll. 加载默认区域性的资源。When the current UI culture is Russia (Russian), it displays an English language string because Russian language resources do not exist, but the resource manager is able to load the resources of the default culture from the satellite assembly en\HelloWorld2.dll.

  
vbc HelloWorld.vb /out:HelloWorld2.exe  
  
md fr  
resgen GreetResources.fr.txt  
al /out:fr\HelloWorld2.resources.dll /culture:fr /embed:GreetResources.fr.resources  
  
md en  
resgen GreetResources.en.txt  
al /out:en\HelloWorld2.resources.dll /culture:en /embed:GreetResources.en.resources  
  
HelloWorld2  
  

注解

默认区域性是在找不到合适的区域性特定资源的情况下,加载资源的区域性。The default culture is the culture whose resources are loaded if the appropriate culture-specific resources cannot be found. 默认情况下,默认区域性的资源位于主程序集中,如果资源管理器尝试检索默认区域性的资源但找不到该资源,则会引发 MissingManifestResourceExceptionBy default, resources for the default culture are located in the main assembly, and a MissingManifestResourceException is thrown if the resource manager tries to retrieve but cannot find a resource for the default culture. 但是,如果 NeutralResourcesLanguageAttribute 特性指定 location 参数的 UltimateResourceFallbackLocation.Satellite 值,则 .NET Framework 将从附属程序集中加载应用的默认区域性的资源。However, the .NET Framework will load the resources for an app's default culture from a satellite assembly if the NeutralResourcesLanguageAttribute attribute specifies a value of UltimateResourceFallbackLocation.Satellite for the location parameter. 在这种情况下,如果资源管理器尝试检索默认区域性的资源,而缺少 NeutralResourcesLanguageAttribute 特性中指定的区域性的附属程序集,则会引发 MissingSatelliteAssemblyException 异常。When this is the case, the MissingSatelliteAssemblyException exception is thrown when the resource manager tries to retrieve a resource of the default culture and the satellite assembly for the culture specified in the NeutralResourcesLanguageAttribute attribute is missing. 请注意,异常由资源检索方法(例如 ResourceManager.GetStringResourceManager.GetObject)引发,而不是在实例化 ResourceManager 对象时引发。Note that the exception is thrown by a resource retrieval method such as ResourceManager.GetString or ResourceManager.GetObject, and not when the ResourceManager object is instantiated.

MissingSatelliteAssemblyException 使用值为0x80131536 的 HRESULT COR_E_MISSINGSATELLITEASSEMBLY。MissingSatelliteAssemblyException uses the HRESULT COR_E_MISSINGSATELLITEASSEMBLY, which has the value 0x80131536.

MissingSatelliteAssemblyException 使用默认的 Equals 实现,该实现支持引用相等性。MissingSatelliteAssemblyException uses the default Equals implementation, which supports reference equality.

有关 MissingSatelliteAssemblyException 类的实例的初始属性值的列表,请参阅 MissingSatelliteAssemblyException 构造函数。For a list of initial property values for an instance of the MissingSatelliteAssemblyException class, see the MissingSatelliteAssemblyException constructors.

备注

应始终使用 NeutralResourcesLanguageAttribute 特性来定义应用的默认区域性,以便在特定区域性的资源不可用时,应用程序将显示可接受的行为。You should always use the NeutralResourcesLanguageAttribute attribute to define your app's default culture so that if a resource for a specific culture is unavailable, your application will display acceptable behavior.

构造函数

MissingSatelliteAssemblyException()

使用默认属性初始化 MissingSatelliteAssemblyException 类的新实例。Initializes a new instance of the MissingSatelliteAssemblyException class with default properties.

MissingSatelliteAssemblyException(SerializationInfo, StreamingContext)

用序列化数据初始化 MissingSatelliteAssemblyException 类的新实例。Initializes a new instance of the MissingSatelliteAssemblyException class from serialized data.

MissingSatelliteAssemblyException(String)

使用指定的错误消息初始化 MissingSatelliteAssemblyException 类的新实例。Initializes a new instance of the MissingSatelliteAssemblyException class with the specified error message.

MissingSatelliteAssemblyException(String, Exception)

使用指定的错误消息和对作为此异常原因的内部异常的引用来初始化 MissingSatelliteAssemblyException 类的新实例。Initializes a new instance of the MissingSatelliteAssemblyException class with a specified error message and a reference to the inner exception that is the cause of this exception.

MissingSatelliteAssemblyException(String, String)

用指定的错误信息和非特定区域性的名称初始化 MissingSatelliteAssemblyException 类的新实例。Initializes a new instance of the MissingSatelliteAssemblyException class with a specified error message and the name of a neutral culture.

属性

CultureName

获取默认区域性的名称。Gets the name of the default culture.

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()

当在派生类中重写时,返回 Exception,它是一个或多个并发的异常的根本原因。When 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)

适用于

另请参阅