diff --git a/src/Perf/IIDOptimizer/Program.cs b/src/Perf/IIDOptimizer/Program.cs index 225bc621d..2aa1e20f3 100644 --- a/src/Perf/IIDOptimizer/Program.cs +++ b/src/Perf/IIDOptimizer/Program.cs @@ -40,7 +40,7 @@ class Program arity: ArgumentArity.ZeroOrMore ); - static async Task Main(string[] args) + static int Main(string[] args) { var rootCommand = new RootCommand { }; // friendlier option names @@ -53,7 +53,8 @@ static async Task Main(string[] args) rootCommand.AddOption(_references); rootCommand.Handler = CommandHandler.Create>(GuidPatch); - await rootCommand.InvokeAsync(args); + Task retVal = rootCommand.InvokeAsync(args); + return retVal.Result; } private static ReaderParameters MakeReaderParams(ReferenceAssemblyResolver resolver) @@ -72,7 +73,7 @@ private static ReaderParameters MakeReaderParams(ReferenceAssemblyResolver resol // Set WinRT.Runtime.dll -- either we are patching it, or it is in the references - private static AssemblyDefinition ResolveWinRTRuntime(AssemblyDefinition targetAssemblyDefinition, ReferenceAssemblyResolver resolver) + private static AssemblyDefinition? ResolveWinRTRuntime(AssemblyDefinition targetAssemblyDefinition, ReferenceAssemblyResolver resolver) { AssemblyDefinition? winRTRuntimeAssembly = null; @@ -81,14 +82,21 @@ private static AssemblyDefinition ResolveWinRTRuntime(AssemblyDefinition targetA winRTRuntimeAssembly = targetAssemblyDefinition; } else - { + { var winrtAssembly = targetAssemblyDefinition .MainModule .AssemblyReferences .Where(refAssembly => refAssembly.Name == "WinRT.Runtime") - .First(); - - winRTRuntimeAssembly = resolver.Resolve(winrtAssembly); + .FirstOrDefault(); + + if (winrtAssembly == default(AssemblyNameReference)) + { + winRTRuntimeAssembly = null; + } + else + { + winRTRuntimeAssembly = resolver.Resolve(winrtAssembly); + } } return winRTRuntimeAssembly; @@ -133,6 +141,12 @@ private static int GuidPatch(string targetAssembly, string outputDirectory, IEnu Console.WriteLine($"\tAssembly : {e.AssemblyReference.Name}"); return -1; } + catch (Exception e) + { + Console.WriteLine("Failed with unexpected exception."); + Console.WriteLine($"{e}"); + return -1; + } } } }