question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

System.InvalidOperationException: Expected a block containing a conditional expression

See original GitHub issue

Describe the bug Stryker fails

Logs See attached

Expected behavior Stryker succeeds

Desktop (please complete the following information):

  • OS: Windows
  • Type of project: Full Framework
  • Framework Version: net48
  • Stryker Version: 0.22.2

Here is the original method: private List<string> ExtractXmlMessages(string message, out string partialMessage) { List<string> xmlMessages = new List<string>();

		// While we think we have a valid message
		while (true)
		{
			// Remove any junk starting characters which will prevent
			// the ExtractXmlMessage method from working.
			if (StringHelper.Contains(message, XmlStartSymbol) && !StringHelper.StartsWith(message, XmlStartSymbol))
			{
				int numberOfJunkChars = message.IndexOf(XmlStartSymbol, StringComparison.OrdinalIgnoreCase);
				message = message.Remove(0, numberOfJunkChars);
			}

			string completeMessage = ExtractXmlMessage(message, out partialMessage);
			completeMessage = completeMessage.Trim();

			if (String.IsNullOrEmpty(completeMessage))
			{
				break;
			}

			xmlMessages.Add(completeMessage);
			message = partialMessage;
		}
		return xmlMessages;
	}

Here is the log output: [12:17:38 DBG] Remove a mutation helper. [12:17:38 ERR] An error occurred during the mutation test run System.InvalidOperationException: Expected a block containing a conditional expression, found:

	/// <summary>
	/// Extracts all complete xml strings from the given message string.
	/// </summary>
	/// <param name="message"></param>
	/// <param name="partialMessage"></param>
	/// <returns></returns>
	private List<string> ExtractXmlMessages(string message, out string partialMessage)
	{
		List<string> xmlMessages = new List<string>();

		// While we think we have a valid message
		while ((Stryker7YxyYnQrRbPl8fG.MutantControl.IsActive(776)?!(true):(Stryker7YxyYnQrRbPl8fG.MutantControl.IsActive(775)?false:true)))
		{
			// Remove any junk starting characters which will prevent
			// the ExtractXmlMessage method from working.
			if ((Stryker7YxyYnQrRbPl8fG.MutantControl.IsActive(778)?!(StringHelper.Contains(message, XmlStartSymbol) && !StringHelper.StartsWith(message, XmlStartSymbol)):(Stryker7YxyYnQrRbPl8fG.MutantControl.IsActive(777)?StringHelper.Contains(message, XmlStartSymbol) || !StringHelper.StartsWith(message, XmlStartSymbol):StringHelper.Contains(message, XmlStartSymbol) && (Stryker7YxyYnQrRbPl8fG.MutantControl.IsActive(779)?StringHelper.StartsWith(message, XmlStartSymbol):!StringHelper.StartsWith(message, XmlStartSymbol)))))
			{
				int numberOfJunkChars = message.IndexOf(XmlStartSymbol, StringComparison.OrdinalIgnoreCase);
				message = message.Remove(0, numberOfJunkChars);
			}

			string completeMessage = ExtractXmlMessage(message, out partialMessage);
			completeMessage = completeMessage.Trim();

			if ((Stryker7YxyYnQrRbPl8fG.MutantControl.IsActive(780)?!(String.IsNullOrEmpty(completeMessage)):String.IsNullOrEmpty(completeMessage)))
			{
				break;
			}

			xmlMessages.Add(completeMessage);
			message = partialMessage;
		}
		return xmlMessages;
	}

. at Stryker.Core.Instrumentation.BaseEngine1.RemoveInstrumentation(SyntaxNode node) in D:\a\1\s\src\Stryker.Core\Stryker.Core\Instrumentation\BaseEngine.cs:line 26 at Stryker.Core.Mutants.MutantPlacer.RemoveMutant(SyntaxNode nodeToRemove) in D:\a\1\s\src\Stryker.Core\Stryker.Core\Mutants\MutantPlacer.cs:line 106 at Stryker.Core.Compiling.RollbackProcess.RemoveMutantIfStatements(SyntaxTree originalTree, IEnumerable1 diagnosticInfo, Boolean devMode) in D:\a\1\s\src\Stryker.Core\Stryker.Core\Compiling\RollbackProcess.cs:line 227 at Stryker.Core.Compiling.RollbackProcess.Start(CSharpCompilation compiler, ImmutableArray1 diagnostics, Boolean lastAttempt, Boolean devMode) in D:\a\1\s\src\Stryker.Core\Stryker.Core\Compiling\RollbackProcess.cs:line 59 at Stryker.Core.Compiling.CompilingProcess.TryCompilation(Stream ms, Stream symbolStream, CSharpCompilation compilation, EmitResult previousEmitResult, Boolean lastAttempt, Boolean devMode, Int32 retryCount) in D:\a\1\s\src\Stryker.Core\Stryker.Core\Compiling\CompilingProcess.cs:line 110 at Stryker.Core.Compiling.CompilingProcess.Compile(IEnumerable1 syntaxTrees, Stream ilStream, Stream symbolStream, Boolean devMode) in D:\a\1\s\src\Stryker.Core\Stryker.Core\Compiling\CompilingProcess.cs:line 76 at Stryker.Core.MutationTest.CsharpMutationProcess.CompileMutations() in D:\a\1\s\src\Stryker.Core\Stryker.Core\MutationTest\CsharpMutationProcess.cs:line 76 at Stryker.Core.MutationTest.CsharpMutationProcess.Mutate() in D:\a\1\s\src\Stryker.Core\Stryker.Core\MutationTest\CsharpMutationProcess.cs:line 68 at Stryker.Core.MutationTest.MutationTestProcess.Mutate() in D:\a\1\s\src\Stryker.Core\Stryker.Core\MutationTest\MutationTestProcess.cs:line 75 at Stryker.Core.Initialisation.ProjectMutator.MutateProject(IStrykerOptions options, IReporter reporters) in D:\a\1\s\src\Stryker.Core\Stryker.Core\Initialisation\ProjectMutator.cs:line 41 at Stryker.Core.Initialisation.ProjectOrchestrator.MutateProjects(StrykerOptions options, IReporter reporters)+MoveNext() in D:\a\1\s\src\Stryker.Core\Stryker.Core\Initialisation\ProjectOrchestrator.cs:line 61 at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at Stryker.Core.StrykerRunner.RunMutationTest(StrykerOptions options, IEnumerable1 initialLogMessages) in D:\a\1\s\src\Stryker.Core\Stryker.Core\StrykerRunner.cs:line 59 [12:17:38 INF] Time Elapsed 00:00:35.2667064 Unhandled exception. System.InvalidOperationException: Expected a block containing a conditional expression, found:

	/// <summary>
	/// Extracts all complete xml strings from the given message string.
	/// </summary>
	/// <param name="message"></param>
	/// <param name="partialMessage"></param>
	/// <returns></returns>
	private List<string> ExtractXmlMessages(string message, out string partialMessage)
	{
		List<string> xmlMessages = new List<string>();

		// While we think we have a valid message
		while ((Stryker7YxyYnQrRbPl8fG.MutantControl.IsActive(776)?!(true):(Stryker7YxyYnQrRbPl8fG.MutantControl.IsActive(775)?false:true)))
		{
			// Remove any junk starting characters which will prevent
			// the ExtractXmlMessage method from working.
			if ((Stryker7YxyYnQrRbPl8fG.MutantControl.IsActive(778)?!(StringHelper.Contains(message, XmlStartSymbol) && !StringHelper.StartsWith(message, XmlStartSymbol)):(Stryker7YxyYnQrRbPl8fG.MutantControl.IsActive(777)?StringHelper.Contains(message, XmlStartSymbol) || !StringHelper.StartsWith(message, XmlStartSymbol):StringHelper.Contains(message, XmlStartSymbol) && (Stryker7YxyYnQrRbPl8fG.MutantControl.IsActive(779)?StringHelper.StartsWith(message, XmlStartSymbol):!StringHelper.StartsWith(message, XmlStartSymbol)))))
			{
				int numberOfJunkChars = message.IndexOf(XmlStartSymbol, StringComparison.OrdinalIgnoreCase);
				message = message.Remove(0, numberOfJunkChars);
			}

			string completeMessage = ExtractXmlMessage(message, out partialMessage);
			completeMessage = completeMessage.Trim();

			if ((Stryker7YxyYnQrRbPl8fG.MutantControl.IsActive(780)?!(String.IsNullOrEmpty(completeMessage)):String.IsNullOrEmpty(completeMessage)))
			{
				break;
			}

			xmlMessages.Add(completeMessage);
			message = partialMessage;
		}
		return xmlMessages;
	}

. at Stryker.Core.Instrumentation.BaseEngine1.RemoveInstrumentation(SyntaxNode node) in D:\a\1\s\src\Stryker.Core\Stryker.Core\Instrumentation\BaseEngine.cs:line 26 at Stryker.Core.Mutants.MutantPlacer.RemoveMutant(SyntaxNode nodeToRemove) in D:\a\1\s\src\Stryker.Core\Stryker.Core\Mutants\MutantPlacer.cs:line 106 at Stryker.Core.Compiling.RollbackProcess.RemoveMutantIfStatements(SyntaxTree originalTree, IEnumerable1 diagnosticInfo, Boolean devMode) in D:\a\1\s\src\Stryker.Core\Stryker.Core\Compiling\RollbackProcess.cs:line 227 at Stryker.Core.Compiling.RollbackProcess.Start(CSharpCompilation compiler, ImmutableArray1 diagnostics, Boolean lastAttempt, Boolean devMode) in D:\a\1\s\src\Stryker.Core\Stryker.Core\Compiling\RollbackProcess.cs:line 59 at Stryker.Core.Compiling.CompilingProcess.TryCompilation(Stream ms, Stream symbolStream, CSharpCompilation compilation, EmitResult previousEmitResult, Boolean lastAttempt, Boolean devMode, Int32 retryCount) in D:\a\1\s\src\Stryker.Core\Stryker.Core\Compiling\CompilingProcess.cs:line 110 at Stryker.Core.Compiling.CompilingProcess.Compile(IEnumerable1 syntaxTrees, Stream ilStream, Stream symbolStream, Boolean devMode) in D:\a\1\s\src\Stryker.Core\Stryker.Core\Compiling\CompilingProcess.cs:line 76 at Stryker.Core.MutationTest.CsharpMutationProcess.CompileMutations() in D:\a\1\s\src\Stryker.Core\Stryker.Core\MutationTest\CsharpMutationProcess.cs:line 76 at Stryker.Core.MutationTest.CsharpMutationProcess.Mutate() in D:\a\1\s\src\Stryker.Core\Stryker.Core\MutationTest\CsharpMutationProcess.cs:line 68 at Stryker.Core.MutationTest.MutationTestProcess.Mutate() in D:\a\1\s\src\Stryker.Core\Stryker.Core\MutationTest\MutationTestProcess.cs:line 75 at Stryker.Core.Initialisation.ProjectMutator.MutateProject(IStrykerOptions options, IReporter reporters) in D:\a\1\s\src\Stryker.Core\Stryker.Core\Initialisation\ProjectMutator.cs:line 41 at Stryker.Core.Initialisation.ProjectOrchestrator.MutateProjects(StrykerOptions options, IReporter reporters)+MoveNext() in D:\a\1\s\src\Stryker.Core\Stryker.Core\Initialisation\ProjectOrchestrator.cs:line 61 at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at Stryker.Core.StrykerRunner.RunMutationTest(StrykerOptions options, IEnumerable1 initialLogMessages) in D:\a\1\s\src\Stryker.Core\Stryker.Core\StrykerRunner.cs:line 59 at Stryker.CLI.StrykerCLI.RunStryker(StrykerOptions options) in D:\a\1\s\src\Stryker.CLI\Stryker.CLI\StrykerCLI.cs:line 136 at Stryker.CLI.StrykerCLI.<>c__DisplayClass7_0.<Run>b__0() in D:\a\1\s\src\Stryker.CLI\Stryker.CLI\StrykerCLI.cs:line 125 at McMaster.Extensions.CommandLineUtils.CommandLineApplication.<>c__DisplayClass146_0.<OnExecute>b__0(CancellationToken _) at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync(String[] args, CancellationToken cancellationToken) at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args) at Stryker.CLI.StrykerCLI.Run(String[] args) in D:\a\1\s\src\Stryker.CLI\Stryker.CLI\StrykerCLI.cs:line 128 at Stryker.CLI.Program.Main(String[] args) in D:\a\1\s\src\Stryker.CLI\Stryker.CLI\Program.cs:line 16 strykerlogs.txt

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dupdobcommented, Apr 21, 2021

Update report: 0) fix is implemented and looking good in terms of design

  1. unit testing has been improved (try to remove helpers twice)
  2. I have reproduced the problem, in a simpler context
  3. I no longer think there is a (new) larger problem. It turns out this issue occurs when safe mode will be triggered anyway
  4. now the interesting part is what triggered the safe mode here!

The compilation error that triggered a swipe removal of mutations is The out parameter 'partialMessage' must be assigned to before control leaves the current method. Typically, Stryker injects helper to prevent that kind of errors. I will look into this.

1reaction
dupdobcommented, Apr 18, 2021

Update on my first analysis: it was only partially right. What I got right: the annotation signaling a helper were not removed. I have a fix for that, but I want first to try and improve unit testing to prevent regresion. What I got wrong: this was not linked to new compilation attempts (no trace in log of this); so this is more likely there were several errors signaled for this method, resulting in multiple scan for removal. Then, issue #1512 was clearly linked to attempting to remove return default(xxx) a second time; this issue is less clear, but I guess this is linked to an attempt to remove an ‘out variable assignment’ helper a second time.

I already have a version that properly removes the helpers and the associated markers to prevent this kind of crash, but:

  1. I need to improve on unit testing to improve my confidence in the fix
  2. I want to reproduce this issue to ensure I have a full fix
  3. I think this problem may be hiding another subtle issue: it may not be a good idea to eagerly remove helper. Remember this is the first version where this happen.

I’ll keep working on this and update on progress.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No return at the end of · Issue #1512 · stryker-mutator/ ...
Expected behavior Stryker succeeds Desktop (please complete the ... System.InvalidOperationException: No return at the end of #1512.
Read more >
Throw Expressions in C# 7
Learn how to use C# 7's new feature to throw exceptions from expression-bodied members, null-coalescing expressions, and conditional ...
Read more >
Try-with-resources using conditional expression - java
Using javap -c I can see that the resource is closed as expected at the end of the try block. The warning is...
Read more >
Basic Error Handling with Exceptions | C# Methods and ...
In Listing 5.26, there is no finally block, so execution falls through to the System.Console.WriteLine() statement following the try/catch block ...
Read more >
Unit Testing Exceptions in C#
In this article I will work through examples of how to unit test C# code that's expected to throw exceptions.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found