Index: Application/Riskeer/src/Application.Riskeer.Migration.Console/Application.Riskeer.Migration.Console.csproj =================================================================== diff -u -r7bc776a67192d321093444684e47bcb8135bedee -rd1a351eab5810228ad9247ba1f2bebf81ac26969 --- Application/Riskeer/src/Application.Riskeer.Migration.Console/Application.Riskeer.Migration.Console.csproj (.../Application.Riskeer.Migration.Console.csproj) (revision 7bc776a67192d321093444684e47bcb8135bedee) +++ Application/Riskeer/src/Application.Riskeer.Migration.Console/Application.Riskeer.Migration.Console.csproj (.../Application.Riskeer.Migration.Console.csproj) (revision d1a351eab5810228ad9247ba1f2bebf81ac26969) @@ -1,4 +1,4 @@ - + Migratiehulpprogramma Exe @@ -15,6 +15,7 @@ + Index: Application/Riskeer/src/Application.Riskeer.Migration.Console/RiskeerMigrationTool.cs =================================================================== diff -u -r27811d785a73e74fe0b36f838f1cf4c2e4d8027b -rd1a351eab5810228ad9247ba1f2bebf81ac26969 --- Application/Riskeer/src/Application.Riskeer.Migration.Console/RiskeerMigrationTool.cs (.../RiskeerMigrationTool.cs) (revision 27811d785a73e74fe0b36f838f1cf4c2e4d8027b) +++ Application/Riskeer/src/Application.Riskeer.Migration.Console/RiskeerMigrationTool.cs (.../RiskeerMigrationTool.cs) (revision d1a351eab5810228ad9247ba1f2bebf81ac26969) @@ -19,12 +19,18 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; +using System.IO; +using System.Linq; +using System.Reflection; +using Core.Common.Assembly; + namespace Application.Riskeer.Migration.Console { /// /// Entry point to the console application that can migrate a project database file to a newer version. /// - public static class RiskeerMigrationTool + public static partial class RiskeerMigrationTool { /// /// Main migration application. @@ -37,8 +43,45 @@ /// public static void Main(string[] args) { - var riskeerMigrationConsole = new RiskeerMigrationConsole(); - riskeerMigrationConsole.ExecuteConsoleTool(args); + SetupAssemblyResolver(); + + InitializeConsole(args); } + + private static void SetupAssemblyResolver() + { + string assemblyDirectory = Path.Combine(GetApplicationDirectory(), "Built-in", "Managed"); + + Assembly GetAssemblyResolver(object sender, ResolveEventArgs args) + { + return Assembly.LoadFrom(Path.Combine(assemblyDirectory, "Core", "Core.Common.Assembly.dll")); + } + + AppDomain.CurrentDomain.AssemblyResolve += GetAssemblyResolver; + + InitializeAssemblyResolver(assemblyDirectory); + + AppDomain.CurrentDomain.AssemblyResolve -= GetAssemblyResolver; + } + + private static void InitializeAssemblyResolver(string assemblyDirectory) + { + if (AssemblyResolver.RequiresInitialization) + { + AssemblyResolver.Initialize(assemblyDirectory); + } + } + + private static string GetApplicationDirectory() + { + DirectoryInfo executingAssemblyDirectoryInfo = Directory.GetParent(Assembly.GetExecutingAssembly().Location); + + while (executingAssemblyDirectoryInfo.GetDirectories().All(di => di.Name != "Application")) + { + executingAssemblyDirectoryInfo = Directory.GetParent(executingAssemblyDirectoryInfo.FullName); + } + + return Path.Combine(executingAssemblyDirectoryInfo.FullName, "Application"); + } } } \ No newline at end of file Index: Application/Riskeer/src/Application.Riskeer.Migration.Console/RiskeerMigrationToolInitialize.cs =================================================================== diff -u --- Application/Riskeer/src/Application.Riskeer.Migration.Console/RiskeerMigrationToolInitialize.cs (revision 0) +++ Application/Riskeer/src/Application.Riskeer.Migration.Console/RiskeerMigrationToolInitialize.cs (revision d1a351eab5810228ad9247ba1f2bebf81ac26969) @@ -0,0 +1,34 @@ +// Copyright (C) Stichting Deltares 2019. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +namespace Application.Riskeer.Migration.Console +{ + // Partial class introduced for avoiding problems related to dynamically resolving assemblies + // (SetupAssemblyResolver must be called before any dependencies are needed). + public static partial class RiskeerMigrationTool + { + private static void InitializeConsole(string[] args) + { + var riskeerMigrationConsole = new RiskeerMigrationConsole(); + riskeerMigrationConsole.ExecuteConsoleTool(args); + } + } +} \ No newline at end of file