Creates an object for the specified application domain based on type, virtual and physical paths, and a Boolean value indicating failure behavior when an object of the specified type already exists.
- appId
- The unique identifier for the application that owns the object.
- type
- The type of the object to create.
- virtualPath
- The virtual path to the application.
- physicalPath
- The physical path to the application.
- failIfExists
- true to throw an exception if an object of the specified type is currently registered; false to return the existing registered object of the specified type.
A new object of the specified type.
The ApplicationManager.CreateObject(string, Type, string, string, bool) method is used to create and register objects in the application. Only one object of each type can be created. If you need to create multiple objects of the same type, you must implement an object factory. For more information, see the code example in this topic.
Each application, identified by a unique application identifier, runs in its own application domain. The ApplicationManager.CreateObject(string, Type, string, string, bool) method creates an object of the specified type in the application domain of the application specified in the appID parameter. If an application domain does not exist for the specified application, one is created before the object is created.
The failIfExists parameter controls the behavior of the ApplicationManager.CreateObject(string, Type, string, string, bool) method when an object of the specified type already exists in the application. When failIfExists is true, the ApplicationManager.CreateObject(string, Type, string, string, bool) method throws an InvalidOperationException exception.
When failIfExists is false, the ApplicationManager.CreateObject(string, Type, string, string, bool) method returns the existing registered object of the specified type.
The ApplicationManager.CreateObject(string, Type, string, string, bool) method calls the overload that takes an additional throwOnError parameter with throwOnError set to false.