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:

文化特性Culture 資源名稱/值Resource name/value 檔案名稱File name
英文English 歡迎 = HelloGreet=Hello 歡迎 .txtGreet.en.txt
法文French 歡迎 = BonjourGreet=Bonjour 歡迎 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,並以 .cs取代 .vb 延伸模組。If 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 使用 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 類別的新執行個體。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()

在衍生類別中覆寫時,傳回一或多個後續的例外狀況的根本原因 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)

適用於

另請參閱