Share via


WeakReference.Target Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets the object (the target) referenced by the current WeakReference object.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Overridable Property Target As Object
public virtual Object Target { get; set; }

Property Value

Type: System.Object
nulla null reference (Nothing in Visual Basic) if the object referenced by the current WeakReference object has been garbage collected; otherwise, a reference to the object referenced by the current WeakReference object.

Exceptions

Exception Condition
InvalidOperationException

The reference to the target object is invalid. This exception can be thrown while setting this property if the value is a null reference or if the object has been finalized during the set operation.

Remarks

After setting this property to the target object, make sure that there are no other strong references to the object; otherwise, it will not be collected. The object should also be set to null.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.