MissingSatelliteAssemblyException MissingSatelliteAssemblyException MissingSatelliteAssemblyException MissingSatelliteAssemblyException Class

定义

默认区域性资源的附属程序集丢失时引发的异常。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
继承
MissingSatelliteAssemblyExceptionMissingSatelliteAssemblyExceptionMissingSatelliteAssemblyExceptionMissingSatelliteAssemblyException
属性

示例

下面的示例使用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#,替换vbccsc,并替换.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. 默认情况下,默认区域性的资源位于主程序集和一个MissingManifestResourceException如果资源管理器会尝试检索,但找不到默认区域性的资源,将引发。By 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. 但是,.NET Framework 将加载应用程序的默认区域性的资源从附属程序集如果NeutralResourcesLanguageAttribute属性指定的值UltimateResourceFallbackLocation.Satellite为位置参数。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. 在这种情况下,MissingSatelliteAssemblyException资源管理器尝试检索默认区域性和中指定的区域性的附属程序集的资源时将引发异常NeutralResourcesLanguageAttribute缺少属性。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 使用 HRESULT COR_E_MISSINGSATELLITEASSEMBLY,其值 0x80131536。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() MissingSatelliteAssemblyException() MissingSatelliteAssemblyException()

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

MissingSatelliteAssemblyException(SerializationInfo, StreamingContext) MissingSatelliteAssemblyException(SerializationInfo, StreamingContext) MissingSatelliteAssemblyException(SerializationInfo, StreamingContext) MissingSatelliteAssemblyException(SerializationInfo, StreamingContext)

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

MissingSatelliteAssemblyException(String) MissingSatelliteAssemblyException(String) MissingSatelliteAssemblyException(String) MissingSatelliteAssemblyException(String)

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

MissingSatelliteAssemblyException(String, Exception) MissingSatelliteAssemblyException(String, Exception) MissingSatelliteAssemblyException(String, Exception) 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(String, String) MissingSatelliteAssemblyException(String, String) 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 CultureName CultureName CultureName

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

Data Data Data Data

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

(Inherited from Exception)
HelpLink HelpLink HelpLink HelpLink

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

(Inherited from Exception)
HResult HResult HResult HResult

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

(Inherited from Exception)
InnerException InnerException InnerException InnerException

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

(Inherited from Exception)
Message Message Message Message

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

(Inherited from Exception)
Source Source Source Source

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

(Inherited from Exception)
StackTrace StackTrace StackTrace StackTrace

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

(Inherited from Exception)
TargetSite TargetSite TargetSite TargetSite

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

(Inherited from Exception)

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

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

(Inherited from Object)
GetBaseException() GetBaseException() GetBaseException() GetBaseException()

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

(Inherited from Exception)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext)

当在派生类中重写时,用关于异常的信息设置 SerializationInfoWhen overridden in a derived class, sets the SerializationInfo with information about the exception.

(Inherited from Exception)
GetType() GetType() GetType() GetType()

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

(Inherited from Exception)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

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

(Inherited from Object)
ToString() ToString() ToString() ToString()

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

(Inherited from Exception)

事件

SerializeObjectState SerializeObjectState SerializeObjectState SerializeObjectState

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

(Inherited from Exception)

适用于

另请参阅