Visual Studio 2022 displays the following error message while attempting to launch an existing AWS Lambda project using either .NET 6 or .NET 8.
"The working directory 'C:\{directory}\bin\net8.0' specified in the 'Mock Lambda Test Tool' debug profile does not exist"
Additionally the Visual Studio Amazon Web Services output window presents the following information.
"Some Toolkit components could not be initialized. Some functionality may not work during this IDE session."
Temporary fixes
Working if the project "Properties" window is opened by the user at least once before trying the test tool.
If you open the "debug launch profiles UI" dialog via the "Mock Lambda Test Tool" button drop down "TheApplication Debug Properties" context menu option at least once before trying the tool.
However if you restart Visual Studio the problem is repeated.
Workaround but not ideal fix
The error suggests that when a Visual Studio 2022 lambda project is loaded the $(Configuration) project variable is empty or not initialized.
Then the Mock Lambda Test Tool is trying to load it's runtime from the following output directory by default
\bin\net8.0\
However when the $(Configuration) variable is initialised by either the extension or Visual Studio it correctly uses
\bin\Debug\net8.0\
My workaround is to hard code the configuration working directory variable, but this is not ideal as this is always reverted unless the file is made uneditable by unticking the write file permissions in windows explorer.
When the test utility is launched, it automatically reverts the launchSettings file to default.
Changes
Remove the $(Configuration) variable and make the file uneditable.
Then open launchSettings.json file properties in windows explorer and select file permissions for the current user and untick write permissions. This will stop the AWS Toolkit extension for Visual Studio 2022 from reverting the launchSettings.json file back to default settings.
To Reproduce
This error is only encountered on an existing project using Visual Studio 2022 (AWS Toolkit 1.55.0.0) with .NET 6 / .NET 8
Open an existing AWS Lambda function and ensure there are no tabs open (exit tabs if there are any active)
View solution properties and ensure: "Single Startup Project" is selected
Configuration: Either
Working directory: .\\bin\\$(Configuration)\\net8.0
Check the lambda project is "Set as Startup Project"
Click the "Mock Lambda Test Tool" debug icon and the error message will be displayed
Show output from: Amazon Web Services output window
There is no error using Visual Studio 2019 (AWS Toolkit 1.55.0.0) with .NET Core 3.1
Expected behavior
The launchSettings.json should not reset unless configured by a setting in Visual Studio.
The $(Configuration) variable should be pre-initialised so that when we launch “Mock Lambda Test Tool” immediately after loading Visual Studio 2022 it will not display the error.
"The working directory 'C:\{directory}\bin\net8.0' specified in the 'Mock Lambda Test Tool' debug profile does not exist"
Example
WHEN Visual Studio 2022 loads an existing AWS lambda solution .NET 6 or .NET 8
AND the lambda project is already set as the start-up project
AND there are no file tabs open
AND the user clicks the "Mock Lambda Test Tool" debug icon
THEN the test utility is loaded
2024-07-12 16:25:43,670 [13] INFO Amazon.AWSToolkit.VisualStudio.AWSToolkitPackage - ToolkitContextProvider initialization will retry shortly.
2024-07-12 16:25:46,670 [28] INFO Amazon.AWSToolkit.VisualStudio.AWSToolkitPackage - ToolkitContextProvider Initialize attempt 6
2024-07-12 16:25:46,670 [28] INFO Amazon.AWSToolkit.VisualStudio.AWSToolkitPackage - TryInitializeToolkitContextProviderAsync
2024-07-12 16:25:46,670 [1] ERROR Amazon.AWSToolkit.VisualStudio.AWSToolkitPackage - Failed to initialize ToolkitContextProvider.
Microsoft.VisualStudio.Composition.CompositionFailedException: Expected 1 export(s) with contract name "Amazon.AWSToolkit.Context.IToolkitContextProvider" but found 0 after applying applicable constraints.
at Microsoft.VisualStudio.Composition.ExportProvider.GetExports(ImportDefinition importDefinition)
at Microsoft.VisualStudio.Composition.ExportProvider.GetExports[T,TMetadataView](String contractName, ImportCardinality cardinality)
at Microsoft.VisualStudio.Composition.ExportProvider.GetExport[T,TMetadataView](String contractName)
at Microsoft.VisualStudio.Composition.ExportProvider.GetExportedValue[T]()
at Microsoft.VisualStudio.ComponentModelHost.ComponentModel.GetService[T]()
at Amazon.AWSToolkit.VisualStudio.AWSToolkitPackage.<GetMefComponentAsync>d__79`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Amazon.AWSToolkit.VisualStudio.AWSToolkitPackage.<TryInitializeToolkitContextProviderAsync>d__78.MoveNext()
2024-07-12 16:25:46,670 [28] ERROR Amazon.AWSToolkit.VisualStudio.AWSToolkitPackage - Unable to initialize ToolkitContextProvider. Some functionality may not work during this IDE session.
2024-07-12 16:25:52,748 [1] ERROR Amazon.AWSToolkit.VisualStudio.Lambda.LambdaTesterUtilities - Error configuring Lambda Tester on project. FileName: , FullName: , UniqueName: <MiscFiles>
System.Exception: Unable to determine project FileName
at Amazon.AWSToolkit.VisualStudio.Lambda.LambdaTesterUtilities.<EnsureLambdaTesterConfiguredAsync>d__2.MoveNext()
2024-07-12 16:26:12,033 [10] DEBUG Amazon.AWSToolkit.Telemetry.Internal.TelemetryPublisher - Telemetry Publisher loop has stopped.
Development System
Windows Version: Windows 11 23H2, Version: 10.0.22631.0 (22631.3880)
Visual Studio Version: VS Professional 2022, Version: 17.10.4
AWS Toolkit for Visual Studio Version: 1.55.0.0
Additional context
Manually reinstalling the test tool did not resolve the issue
Description
Visual Studio 2022 displays the following error message while attempting to launch an existing AWS Lambda project using either .NET 6 or .NET 8.
Additionally the Visual Studio Amazon Web Services output window presents the following information.
"Some Toolkit components could not be initialized. Some functionality may not work during this IDE session."
Temporary fixes
However if you restart Visual Studio the problem is repeated.
Workaround but not ideal fix
The error suggests that when a Visual Studio 2022 lambda project is loaded the $(Configuration) project variable is empty or not initialized.
Then the Mock Lambda Test Tool is trying to load it's runtime from the following output directory by default
\bin\net8.0\
However when the $(Configuration) variable is initialised by either the extension or Visual Studio it correctly uses
\bin\Debug\net8.0\
My workaround is to hard code the configuration working directory variable, but this is not ideal as this is always reverted unless the file is made uneditable by unticking the write file permissions in windows explorer.
When the test utility is launched, it automatically reverts the launchSettings file to default.
Changes Remove the $(Configuration) variable and make the file uneditable.
Properties\\launchSettings.json
"Working directory" value:.\\bin\\$(Configuration)\\net8.0
=>.\\bin\\Debug\\net8.0
To Reproduce
This error is only encountered on an existing project using Visual Studio 2022 (AWS Toolkit 1.55.0.0) with .NET 6 / .NET 8
.\\bin\\$(Configuration)\\net8.0
Show output from: Amazon Web Services output window
There is no error using Visual Studio 2019 (AWS Toolkit 1.55.0.0) with .NET Core 3.1
Expected behavior
The launchSettings.json should not reset unless configured by a setting in Visual Studio.
The $(Configuration) variable should be pre-initialised so that when we launch “Mock Lambda Test Tool” immediately after loading Visual Studio 2022 it will not display the error.
Toolkit Logs
Attachment 2024-07-12_16-25-30_5192.txt
Exception message
Development System
Additional context
Manually reinstalling the test tool did not resolve the issue
This same issue is replicated in .NET 6
https://developercommunity.visualstudio.com/t/Visual-Studio-2022-Professional-automati/10691564?