diff --git a/src/Simulation/QCTraceSimulator/Utils.cs b/src/Simulation/QCTraceSimulator/Utils.cs index e80ea791..09cb826f 100644 --- a/src/Simulation/QCTraceSimulator/Utils.cs +++ b/src/Simulation/QCTraceSimulator/Utils.cs @@ -120,9 +120,11 @@ namespace Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime stream.Position = 0; // Deserialize the graph into a new set of objects and // return the root of the graph (deep copy) to the caller - T res = formatter.Deserialize(stream) as T; - Debug.Assert(res != null); - return res; + object res = formatter.Deserialize(stream); + if (res.GetType() != typeof(T)) { + throw new ApplicationException("Deserialization failed while copying an object."); + } + return (T)res; } }