This documentation is archived and is not being maintained.

AppDomain.SetData Method

Assigns the specified value to the specified application domain property.

[Visual Basic]
Public Overridable Sub SetData( _
   ByVal name As String, _
   ByVal data As Object _
) Implements _AppDomain.SetData
public virtual void SetData(
 string name,
 object data
public: virtual void SetData(
 String* name,
 Object* data
public function SetData(
   name : String,
 data : Object


The name of an application domain property.
The value to set the name property.




Exception Type Condition
AppDomainUnloadedException Operations are attempted on an unloaded application domain.
SecurityException The caller does not have the correct permissions. See the requirements section.


Use this method to insert an entry, or modify the value of an entry in an internal cache of name-data pairs that describe properties of this instance of AppDomain.

The cache automatically contains predefined system entries that are inserted when the application domain is created. You cannot insert or modify system entries with this method. You can inspect their values with the GetData method, or the equivalent AppDomainSetup properties described in the Remarks section of the GetData method. You can modify their values with the appropriate AppDomainSetup properties.

You can insert or modify your own user defined name-data pairs with this method and inspect their values with the GetData method.


[Visual Basic] 
Imports System
Imports System.Reflection

Class ADGetData
   Public Shared Sub Main()
      ' appdomain setup information
      Dim currentDomain As AppDomain = AppDomain.CurrentDomain
      'set predefined system variable application name
      Dim dataName As [String] = "APP_NAME"
      Dim setappname As [String] = "MyApplication"
      currentDomain.SetData(dataName, setappname)
      'Create a new value pair for the appdomain
      Dim dataValue As [String] = "ADVALUE"
      Dim advalue As Int32 = 6
      currentDomain.SetData(dataValue, advalue)
      'get the value specified in the setdata method
      Console.WriteLine((" ADVALUE is: " + currentDomain.GetData("ADVALUE")))
      'get system value specified at appdomainsetup
      Console.WriteLine(("System value for application name:" + currentDomain.GetData("APP_NAME")))
   End Sub 'Main 
End Class 'ADGetData

using System;
using System.Reflection;

class ADGetData 

    public static void Main() 
        // appdomain setup information
        AppDomain currentDomain = AppDomain.CurrentDomain;

        //set predefined system variable application name
        String dataName = "APP_NAME";
        String setappname = "MyApplication";
        currentDomain.SetData(dataName, setappname);

        //Create a new value pair for the appdomain
        String dataValue = "ADVALUE";
        Int32 advalue = 6;
        currentDomain.SetData(dataValue, advalue);

        //get the value specified in the setdata method
        Console.WriteLine(" ADVALUE is: " + currentDomain.GetData("ADVALUE"));

        //get system value specified at appdomainsetup
        Console.WriteLine("System value for application name:" + currentDomain.GetData("APP_NAME"));

#using <mscorlib.dll>

using namespace System;
using namespace System::Reflection;

int main() {
   // appdomain setup information
   AppDomain*  currentDomain = AppDomain::CurrentDomain;

   //set predefined system variable application name
   String*  dataName = S"APP_NAME";
   String*  setappname = S"MyApplication";
   currentDomain->SetData(dataName, setappname);

   //Create a new value pair for the appdomain
   String*  dataValue = S"ADVALUE";
   Int32 advalue = 6;
   currentDomain->SetData(dataValue, __box(advalue));

   //get the value specified in the setdata method
   Console::WriteLine(S" ADVALUE is: {0}", currentDomain->GetData(S"ADVALUE"));

   //get system value specified at appdomainsetup
   Console::WriteLine(S"System value for application name: {0}", currentDomain->GetData(S"APP_NAME"));


[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

AppDomain Class | AppDomain Members | System Namespace | GetData