Use reflection instead of Activator to create new driver instance

This commit is contained in:
2023-02-19 11:00:47 +01:00
parent aa612c1f89
commit 14b2e498ae

View File

@@ -86,7 +86,12 @@ namespace TestApp
if (_Driver is null || !_Driver.GetType().Equals(driverType))
{
var newDriverObject = Activator.CreateInstance(driverType);
var newDriverConstructor = driverType.GetConstructor(Array.Empty<Type>());
if (newDriverConstructor is null) {
throw new InvalidOperationException($"Type {driverType} does not have a parameterless constructor!");
}
var newDriverObject = newDriverConstructor.Invoke(null, Array.Empty<object>());
if (newDriverObject is null)
{
throw new InvalidOperationException("Could not instantiate driver!");