This topic has not yet been rated - Rate this topic

ServiceBase.ServiceName Property

Updated: December 2010

Gets or sets the short name used to identify the service to the system.

Namespace:  System.ServiceProcess
Assembly:  System.ServiceProcess (in System.ServiceProcess.dll)
[TypeConverterAttribute("System.Diagnostics.Design.StringValueConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[ServiceProcessDescriptionAttribute("SBServiceName")]
public string ServiceName { get; set; }

Property Value

Type: System.String
The name of the service.
Exception Condition
InvalidOperationException

The service has already been started. The ServiceName property cannot be changed once the service has started.

ArgumentException

The specified name is a zero-length string or is longer than MaxNameLength, or the specified name contains forward slash or backslash characters.

The ServiceName identifies the service to the Service Control Manager. The value of this property must be identical to the name recorded for the service in the ServiceInstaller.ServiceName property of the corresponding installer class. In code, the ServiceName of the service is usually set in the main() function of the executable.

The ServiceName is also used to specify the EventLog.Source associated with the EventLog property. This EventLog is an instance that writes service command information to the Application log.

The ServiceName, which supplies the source string for the event log, must be set before the service writes to the event log. Trying to access the event log before the source name is set causes an exception to be thrown.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Date

History

Reason

December 2010

Clarified the conditions for ArgumentException.

Customer feedback.

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Problem with .Net 4 Client Profile
The ServiceBase class is part of the .Net 4.0 Client Profile, but the TypeConverter attribute on this property references a type that is not part of the .Net 4.0 Client Profile.  This causes runtime errors when using reflection or technologies such as XAML that use reflection under the hood.  For example, you cannot instantiate a ServiceBase-derived object in XAML under the Client Profile, like so: $0$0 $0<local:MyService ServiceName="This property causes a XamlParseException" />$0 $0 $0
$0
$0$0 $0 $0