Partager via


ContentManager.Load Generic Method

Loads an asset that has been processed by the Content Pipeline.

Syntax

'Declaration
Public Overridable Function Load(Of T) ( _
         assetName As String _
) As T 
public virtual T Load<T> (
         string assetName
)
public:
generic<typename T>
virtual T Load(
         String assetName
)

Type Parameters

Parameters

  • assetName
    Type: String
    Asset name, relative to the loader root directory, and not including the .xnb extension.

Return Value

Type: T
The loaded asset. Repeated calls to load the same asset will return the same object instance.

Exceptions

Exception type Condition
ObjectDisposedException Load was called after the ContentManager was disposed.
ArgumentNullException The assetName argument is null.
ContentLoadException The type of the assetName in the file does not match the type of asset requested as specified by T.

Remarks

Before a ContentManager can load an asset, you need to add the asset to your game project using the steps described in How to: Add Game Assets to a Content Project.

The following are the Content Pipeline run-time classes supported by Load and the file formats they are associated with.

Effect Class .fx
Model Class .fbx, .x
SpriteFont Class

.bmp, .spritefont, .dds, .dib, .hdr, .jpg, .pfm, .png, .ppm, and .tga

Bb197848.note(en-us,XNAGameStudio.42).gifNote
The default content processor for .bmp files is the texture processor. To process a .bmp file for use as a Sprite Font, click Sprite Font Texture - XNA Framework in the Properties pane for the .bmp file after it is added to the project.
Texture Class, Texture2D Class .bmp, .dds, .dib, .hdr, .jpg, .pfm, .png, .ppm, and .tga
TextureCube Class .dds

Note that these are the formats of the original assets; after processing, all assets will be .xnb files.

Example

To load a Model from the directory .\content\models\ with the asset name of "box":

Model model = contentManager.Load<Model>( ".\\content\\models\\box" );

Requirements

Namespace: Microsoft.Xna.Framework.Content

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

See Also

Tasks

How to:Add a Resource

Reference

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

Platforms

Windows Phone