Export (0) Print
Expand All

AppDomain.GetData Method

Gets the value stored in the current application domain for the specified data name.

[Visual Basic]
Public Overridable Function GetData( _
   ByVal name As String _
) As Object Implements _AppDomain.GetData
public virtual object GetData(
 string name
public: virtual Object* GetData(
 String* name
public function GetData(
   name : String
) : Object;


The name of an application domain property.

Return Value

The value of the name property.




Exception Type Condition
ArgumentNullException name is a null reference (Nothing in Visual Basic).
AppDomainUnloadedException Operations are attempted on an unloaded application domain.


Use this method to retrieve 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 can inspect their values with the GetData method, or the equivalent AppDomainSetup properties. You can modify their values with the appropriate AppDomainSetup properties.

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

The following table describes the name of each predefined system entry and its corresponding AppDomainSetup property.

Value of 'name' Property
"APPBASE" ApplicationBase
"APP_CONFIG_FILE" ConfigurationFile
"DYNAMIC_BASE" DynamicBase
"DEV_PATH" (no property)
"APP_NAME" ApplicationName
"CACHE_BASE" PrivateBinPath
"BINPATH_PROBE_ONLY" PrivateBinPathProbe
"SHADOW_COPY_DIRS" ShadowCopyDirectories
"CACHE_BASE" CachePath
(application specific) LicenseFile


[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 | SetData

© 2014 Microsoft