diff --git a/src/TwinGet.Core/Packaging/PackageService.cs b/src/TwinGet.Core/Packaging/PackageService.cs index 580e7f4..dcd3155 100644 --- a/src/TwinGet.Core/Packaging/PackageService.cs +++ b/src/TwinGet.Core/Packaging/PackageService.cs @@ -168,13 +168,11 @@ private static async Task SavePlcLibraryAsync(IPackCommand packCommand) StaTaskScheduler staTaskScheduler = new(1); - using var ai = new ThreadLocal(() => new AutomationInterface()); - // Begin AutomationInterface. var initAiTask = Task.Factory.StartNew( () => { - var _ = ai.Value; // We do this so that ThreadLocal inititalize AutomationInterface(); + return new AutomationInterface(); }, CancellationToken.None, TaskCreationOptions.None, @@ -195,21 +193,19 @@ private static async Task SavePlcLibraryAsync(IPackCommand packCommand) var savePlcLibTask = initAiTask.ContinueWith( (prevTask) => { - prevTask.Wait(); + using AutomationInterface ai = prevTask.Result; lock (libraryPathLock) { try { // Suppress because we are in try block. -#pragma warning disable CS8602 // Dereference of a possibly null reference. libraryPath = - ai.Value.SavePlcProject( + ai.SavePlcProject( packCommand.Path, packCommand.OutputDirectory, resolvedSolution ) ?? string.Empty; -#pragma warning restore CS8602 // Dereference of a possibly null reference. } catch (PackagingException ex) { diff --git a/src/TwinGet.TwincatInterface/TwincatProject.cs b/src/TwinGet.TwincatInterface/TwincatProject.cs index bc03948..3486e7a 100644 --- a/src/TwinGet.TwincatInterface/TwincatProject.cs +++ b/src/TwinGet.TwincatInterface/TwincatProject.cs @@ -42,12 +42,12 @@ public TwincatProject(EnvDTE.Project project) _plcProjects = new(TryGetPlcProjects(_systemManager, _project.FullName)); } - private static IReadOnlyList TryGetPlcProjects( + private static List TryGetPlcProjects( ITcSysManagerAlias systemManager, string filePath ) { - List plcProjects = new(); + List plcProjects = []; ArgumentException.ThrowIfNullOrEmpty(filePath, nameof(filePath)); diff --git a/test/Test.Utils.Test/TestTwincatProjectTests.cs b/test/Test.Utils.Test/TestTwincatProjectTests.cs index 04331fb..6fba8f6 100644 --- a/test/Test.Utils.Test/TestTwincatProjectTests.cs +++ b/test/Test.Utils.Test/TestTwincatProjectTests.cs @@ -1,7 +1,7 @@ // This file is licensed to you under MIT license. using FluentAssertions; -namespace Test.Utils; +namespace Test.Utils.Test; public class TestTwincatProjectTests {