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)

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

Type Parameters

Type of the asset specified for loading.


Type: String
The name of the asset to be loaded from disk.
Type: Action<IDisposable>
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.

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

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.

Xbox 360, Windows 7, Windows Vista, Windows XP, Windows Phone

Community Additions