diff --git a/src/Azure/Azure.Quantum.Client/Machine/QuantumMachineFactory.cs b/src/Azure/Azure.Quantum.Client/Machine/QuantumMachineFactory.cs index ef9654c10ca..94ab65f2368 100644 --- a/src/Azure/Azure.Quantum.Client/Machine/QuantumMachineFactory.cs +++ b/src/Azure/Azure.Quantum.Client/Machine/QuantumMachineFactory.cs @@ -15,23 +15,37 @@ public static class QuantumMachineFactory /// The execution target for job submission. /// The connection string for the Azure storage account. /// A quantum machine for job submission targeting targetName. - public static IQuantumMachine? CreateMachine(Workspace workspace, string targetName, string storageAccountConnectionString) + public static IQuantumMachine? CreateMachine(IWorkspace workspace, string targetName, string storageAccountConnectionString) { - if (string.IsNullOrEmpty(targetName)) - { - return null; - } - var machineName = - targetName.StartsWith("ionq.") + targetName is null + ? null + : targetName.StartsWith("ionq.") ? "Microsoft.Quantum.Providers.IonQ.Targets.IonQQuantumMachine, Microsoft.Quantum.Providers.IonQ" : targetName.StartsWith("honeywell.") ? "Microsoft.Quantum.Providers.Honeywell.Targets.HoneywellQuantumMachine, Microsoft.Quantum.Providers.Honeywell" : null; - return machineName is null + + Type machineType = null; + if (machineName != null) + { + // First try to load the signed assembly with the correct version, then try the unsigned one. + try + { + machineType = Type.GetType($"{machineName}, Version={typeof(IWorkspace).Assembly.GetName().Version}, Culture=neutral, PublicKeyToken=40866b40fd95c7f5"); + } + catch + { + machineType = null; + } + + machineType ??= Type.GetType(machineName, throwOnError: true); + } + + return machineType is null ? null : (IQuantumMachine)Activator.CreateInstance( - Type.GetType(machineName, throwOnError: true), + machineType, targetName, storageAccountConnectionString, workspace);