Export/import fails with InvalidOperationException in Octopus 3

We have exported our Octopus Deploy server (version 3.1.3) using the Octopus Server Manager, and now we are trying to import it into a fresh Octopus installation (version 3.1.4). While importing we get the following error message:

System.InvalidOperationException: Sequence contains more than one matching element
    at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source, Func`2 predicate)
    at Octopus.Migrator.ImportProcess.ImportController.ImportScript(ImportContext context, String scriptFile) in Y:\work\refs\tags\3.1.4\source\Octopus.Migrator\ImportProcess\ImportController.cs:line 444
    at Octopus.Migrator.ImportProcess.ImportController.ImportScripts(ImportContext context) in Y:\work\refs\tags\3.1.4\source\Octopus.Migrator\ImportProcess\ImportController.cs:line 410
    at Octopus.Migrator.ImportProcess.ImportController.Import(IImportedDocumentSource backup) in Y:\work\refs\tags\3.1.4\source\Octopus.Migrator\ImportProcess\ImportController.cs:line 112
    at Octopus.Migrator.Commands.ImportFilesCommand.Start() in Y:\work\refs\tags\3.1.4\source\Octopus.Migrator\Commands\ImportFilesCommand.cs:line 90
    at Octopus.Shared.Startup.AbstractCommand.Octopus.Shared.Startup.ICommand.Start(String[] commandLineArguments, ICommandRuntime commandRuntime, OptionSet commonOptions) in Y:\work\refs\tags\3.1.4\source\Octopus.Shared\Startup\AbstractCommand.cs:line 57
    at Octopus.Shared.Startup.ConsoleHost.Run(Action`1 start, Action shutdown) in Y:\work\refs\tags\3.1.4\source\Octopus.Shared\Startup\ConsoleHost.cs:line 72
    at Octopus.Shared.Startup.OctopusProgram.Run() in Y:\work\refs\tags\3.1.4\source\Octopus.Shared\Startup\OctopusProgram.cs:line 87

It appears to occur while importing the different steps for projects. The preceeding logs looks like this (redacted with some imaginary names):

INFO    Examining script file C:\Temp\TestExport\Projects\MyProj\MyProj - Create My Application - Create My Application - Script.ps1
INFO      [Project, K:MyProj, N:'MyProj', S:Projects-40, D:-05da0de1259, O:]
INFO      deploymentprocess-Projects-40
INFO       Create CCAT Application - Script.ps1 skipped because no overwrites selected
INFO    Examining script file C:\Temp\TestExport\Projects\MyProj\MyProj - Create My Application - AlternateNet - Create My Application - AlternateNet - Script.ps1
INFO      [Project, K:MyProj, N:'MyProj', S:Projects-40, D:-05da0de1259, O:]
INFO      deploymentprocess-Projects-40

By doing some testing I have come to the conclusion that it is caused by a dash character (’-’) in step names with the same value up until the dash, e.g.:

Create My Application
Create My Application - AlternateNet

This generates the two scripts:

MyProj - Create My Application - Create My Application - Script.ps1
MyProj - Create My Application - AlternateNet - Create My Application - AlternateNet - Script.ps1

If I change the step name to not use dashes, e.g. to Create My Application with AlternateNet the import of the step succeeds (although the entire import later failed on another step following the same convention).

Hi,

Thanks for getting in touch. I’m very sorry to hear you are experiencing this issue. We have a github issue created for this: https://github.com/OctopusDeploy/Issues/issues/2024

I’m gonna add this ticket as reference on that ticket. The info you provided will come in handy when working on the fix.

Thanks,

Dalmiro

Hi,
We have made a fix to the migrator that should now allow this import to take place without needing to rename the steps. As you noted, the problem seems to have stemmed from the fact that it wasn’t taking into consideration the use case where one step name was a substring of another.
Try to perform an import with version 3.2.3 when its released early next week and let us know how the process goes.
Thanks for your patience and for bringing this issue to our attention,
Rob