Skip to content

Commit b32666d

Browse files
CopilotmarcpopMSFT
andcommitted
Fix error display by ensuring GetManifests is called before checking error state
- ShowWorkloadsInfo now calls GetManifests() before checking error message - This ensures _exceptionToThrow is populated when manifests from workload set are missing - Changed InitializeManifests to always throw if error exists (not just when no manifests loaded) - Fixed redundant error message display logic - Error now properly shown in dotnet --info and dotnet workload --info Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
1 parent 9d3bd1e commit b32666d

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

src/Cli/dotnet/Commands/Workload/WorkloadInfoHelper.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,25 @@ internal void ShowWorkloadsInfo(IReporter? reporter = null, string? dotnetDir =
124124
{
125125
reporter ??= Reporter.Output;
126126

127-
var versionInfo = ManifestProvider.GetWorkloadVersion();
128-
129127
// Get the error message if manifests are missing
128+
// We need to call GetManifests() first to ensure _exceptionToThrow is populated
129+
// if manifests from a workload set are missing
130130
string? manifestError = null;
131131
if (ManifestProvider is SdkDirectoryWorkloadManifestProvider sdkProvider)
132132
{
133+
// Calling GetManifests().Count() forces enumeration which populates the error state
134+
try
135+
{
136+
_ = ManifestProvider.GetManifests().Count();
137+
}
138+
catch
139+
{
140+
// Ignore errors here - we'll get the message via GetManifestErrorMessage
141+
}
133142
manifestError = sdkProvider.GetManifestErrorMessage();
134143
}
144+
145+
var versionInfo = ManifestProvider.GetWorkloadVersion();
135146

136147
void WriteUpdateModeAndAnyError(string indent = "")
137148
{
@@ -153,9 +164,9 @@ void WriteUpdateModeAndAnyError(string indent = "")
153164
{
154165
reporter.WriteLine(indent + string.Format(CliCommandStrings.WorkloadSetFromGlobalJsonNotInstalled, versionInfo.Version, versionInfo.GlobalJsonPath));
155166
}
156-
else
167+
else if (manifestError == null)
157168
{
158-
// Workload set is installed but manifests are missing
169+
// Workload set is installed but manifests are missing - only show generic message if we don't have a specific error
159170
reporter.WriteLine(indent + CliCommandStrings.WorkloadsNotInstalledRunWorkloadUpdate);
160171
}
161172
}

src/Resolvers/Microsoft.NET.Sdk.WorkloadManifestReader/WorkloadResolver.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ private void InitializeManifests()
8585
{
8686
LoadManifestsFromProvider(_manifestProvider);
8787

88-
// If manifests from a workload set are missing, check if we got an error
89-
// This will be shown when trying to use workloads but manifests are not available
88+
// If manifests from a workload set are missing, throw the error when trying to use workloads
89+
// This ensures errors are shown when building apps that require workloads
9090
if (_manifestProvider is SdkDirectoryWorkloadManifestProvider sdkProvider)
9191
{
9292
var manifestError = sdkProvider.GetManifestErrorMessage();
93-
if (manifestError != null && _manifests.Count == 0)
93+
if (manifestError != null)
9494
{
95-
// No manifests were loaded and there's an error - this means workloads won't work
96-
// Throw the error so users know what's wrong
95+
// There's an error with missing manifests from a workload set
96+
// Throw it so users know what's wrong
9797
throw new FileNotFoundException(manifestError);
9898
}
9999
}

0 commit comments

Comments
 (0)