Share via


ContentManager.ReadAsset Generic Method

Low-level worker method that reads asset data.

Namespace: Microsoft.Xna.Framework.Content
Assembly: Microsoft.Xna.Framework (in microsoft.xna.framework.dll)

Syntax

protected T ReadAsset<T> (
         string assetName,
         Action<IDisposable> recordDisposableObject
)

Type Parameters

  • T
    Type of the asset specified for loading.

Parameters

  • assetName
    The name of the asset to be loaded from disk.
  • recordDisposableObject
    Delegate function for handling the disposition of assets. If recordDisposableObject is null, the default lifespan tracking and management is used, so unloading or disposing of the content manager frees everything that has been loaded through it. If recordDisposableObject specifies a valid delegate, that delegate is used instead of the default lifespan tracking and is called every time the loader encounters a type that implements IDisposable. You must use your own code to unload assets loaded in this fashion, since ContentManager's Unload method will not be aware of them.

Return Value

Returns the loaded asset.

Exceptions

Exception type Condition
ObjectDisposedException ReadAsset was called after the ContentManager was disposed.
ArgumentNullException The assetName argument is null.

Remarks

This protected method loads an .xnb file from disk. Unlike ContentManager's public Load method, it always returns a new copy of the specified asset, even if the asset has been loaded previously.

You can customize how shared assets are managed by overriding ContentManager's Load method. In your own Load method, keep track of what has been loaded, and call ReadAsset when you need a new asset from disk.

See Also

Reference

ContentManager Class
ContentManager Members
Microsoft.Xna.Framework.Content Namespace

Platforms

Xbox 360, Windows XP SP2, Windows Vista