Skip to content

Commit 469e19f

Browse files
committed
Provide actionable error messages for .NET SDK issues
1 parent 745c352 commit 469e19f

File tree

7 files changed

+55
-17
lines changed

7 files changed

+55
-17
lines changed

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Known Issues in 1.25.0
1+
## Known Issues in 1.25.1
22

33
* For Mono-based development (e.g. Unity) that requires full .NET framework, you need to set `"omnisharp.useModernNet": false`.
44
* After selecting a solution filter (*.slnf) from the project selector, the solution's name will be displayed in the status bar instead of the filter's.
@@ -12,7 +12,10 @@
1212
* Renaming symbol fails within a file that had recently been renamed without saving changes.
1313
* As a workaround, make an edit within the file before using Rename Symbol.
1414

15-
## 1.25.0
15+
## 1.25.1
16+
* Provide actionable error messages for .NET SDK issues ([#5223](https://github.com/OmniSharp/omnisharp-vscode/issues/5223), PR: [#5225](https://github.com/OmniSharp/omnisharp-vscode/pull/5225))
17+
18+
## 1.25.0 (May 24th, 2022)
1619
* Make SDK build of OmniSharp the default ([#5120](https://github.com/OmniSharp/omnisharp-vscode/issues/5120), PR: [#5176](https://github.com/OmniSharp/omnisharp-vscode/pull/5176))
1720
* Add auto complete name to class, interface, enum, struct etc. snippets (PR: [#5198](https://github.com/OmniSharp/omnisharp-vscode/pull/5198))
1821
* Add a fallback for ps in remoteProcessPickerScript ([#4096](https://github.com/OmniSharp/omnisharp-vscode/issues/4096), PR: [#5207](https://github.com/OmniSharp/omnisharp-vscode/pull/5207))

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ If you still need Unity or .NET Framework support, you can set `omnisharp.useMod
2424

2525
See issue [#5120](https://github.com/OmniSharp/omnisharp-vscode/issues/5120) for more details.
2626

27+
## What's new in 1.25.1
28+
* Provide actionable error messages for .NET SDK issues ([#5223](https://github.com/OmniSharp/omnisharp-vscode/issues/5223), PR: [#5225](https://github.com/OmniSharp/omnisharp-vscode/pull/5225))
29+
2730
## What's new in 1.25.0
2831
* Make SDK build of OmniSharp the default ([#5120](https://github.com/OmniSharp/omnisharp-vscode/issues/5120), PR: [#5176](https://github.com/OmniSharp/omnisharp-vscode/pull/5176))
2932
* Add auto complete name to class, interface, enum, struct etc. snippets (PR: [#5198](https://github.com/OmniSharp/omnisharp-vscode/pull/5198))

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "csharp",
33
"publisher": "ms-dotnettools",
4-
"version": "1.25.0",
4+
"version": "1.25.1",
55
"description": "C# for Visual Studio Code (powered by OmniSharp).",
66
"displayName": "C#",
77
"author": "Microsoft Corporation",

src/main.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ export async function activate(context: vscode.ExtensionContext): Promise<CSharp
5757
util.setExtensionPath(extension.extensionPath);
5858

5959
const eventStream = new EventStream();
60+
61+
let platformInfo: PlatformInformation;
62+
try {
63+
platformInfo = await PlatformInformation.GetCurrent();
64+
}
65+
catch (error) {
66+
eventStream.post(new ActivationFailure());
67+
}
68+
6069
const optionStream = createOptionStream(vscode);
6170
let optionProvider = new OptionProvider(optionStream);
6271

@@ -79,7 +88,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<CSharp
7988
eventStream.subscribe(csharpLogObserver.post);
8089

8190
let omnisharpChannel = vscode.window.createOutputChannel('OmniSharp Log');
82-
let omnisharpLogObserver = new OmnisharpLoggerObserver(omnisharpChannel);
91+
let omnisharpLogObserver = new OmnisharpLoggerObserver(omnisharpChannel, platformInfo);
8392
let omnisharpChannelObserver = new OmnisharpChannelObserver(omnisharpChannel, vscode);
8493
eventStream.subscribe(omnisharpLogObserver.post);
8594
eventStream.subscribe(omnisharpChannelObserver.post);
@@ -117,14 +126,6 @@ export async function activate(context: vscode.ExtensionContext): Promise<CSharp
117126
eventStream.subscribe(omnisharpDebugModeLoggerObserver.post);
118127
}
119128

120-
let platformInfo: PlatformInformation;
121-
try {
122-
platformInfo = await PlatformInformation.GetCurrent();
123-
}
124-
catch (error) {
125-
eventStream.post(new ActivationFailure());
126-
}
127-
128129
if (!isSupportedPlatform(platformInfo)) {
129130
const platform: string = platformInfo.platform ? platformInfo.platform : "this platform";
130131
const architecture: string = platformInfo.architecture ? platformInfo.architecture : " and <unknown processor architecture>";

src/observers/OmnisharpLoggerObserver.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@ import { BaseLoggerObserver } from "./BaseLoggerObserver";
77
import { BaseEvent, OmnisharpInitialisation, OmnisharpLaunch, OmnisharpFailure, OmnisharpServerMessage, OmnisharpServerOnServerError, OmnisharpServerOnError, OmnisharpServerMsBuildProjectDiagnostics, OmnisharpServerOnStdErr, OmnisharpEventPacketReceived } from "../omnisharp/loggingEvents";
88
import * as os from 'os';
99
import { EventType } from "../omnisharp/EventType";
10+
import * as vscode from 'vscode';
11+
import { PlatformInformation } from "../platform";
12+
import { Logger } from "../logger";
1013

1114
export class OmnisharpLoggerObserver extends BaseLoggerObserver {
15+
constructor(channel: vscode.OutputChannel | Logger, private platformInformation: PlatformInformation) {
16+
super(channel);
17+
}
18+
1219
public post = (event: BaseEvent) => {
1320
switch (event.type) {
1421
case EventType.OmnisharpInitialisation:
@@ -34,7 +41,7 @@ export class OmnisharpLoggerObserver extends BaseLoggerObserver {
3441
this.handleOmnisharpServerMsBuildProjectDiagnostics(<OmnisharpServerMsBuildProjectDiagnostics>event);
3542
break;
3643
case EventType.OmnisharpServerOnStdErr:
37-
this.logger.append((<OmnisharpServerOnStdErr>event).message);
44+
this.handleOmnisharpServerOnStdErr(<OmnisharpServerOnStdErr>event);
3845
break;
3946
case EventType.OmnisharpEventPacketReceived:
4047
this.handleOmnisharpEventPacketReceived(<OmnisharpEventPacketReceived>event);
@@ -43,9 +50,27 @@ export class OmnisharpLoggerObserver extends BaseLoggerObserver {
4350
}
4451

4552
private handleOmnisharpServerOnServerError(event: OmnisharpServerOnServerError) {
53+
if (event.err.cmd === "dotnet --version") {
54+
this.logger.appendLine('[ERROR] A .NET 6 SDK was not found. Please install the latest SDK from https://dotnet.microsoft.com/en-us/download/dotnet/6.0.');
55+
return;
56+
}
57+
else if (event.err.message?.startsWith("Found dotnet version")) {
58+
this.logger.appendLine(`[ERROR] ${event.err} Please install the latest SDK from https://dotnet.microsoft.com/en-us/download/dotnet/6.0.`);
59+
return;
60+
}
61+
4662
this.logger.appendLine('[ERROR] ' + event.err);
4763
}
4864

65+
private handleOmnisharpServerOnStdErr(event: OmnisharpServerOnStdErr) {
66+
if (event.message.startsWith("System.BadImageFormatException: Could not load file or assembly")) {
67+
this.logger.appendLine(`[ERROR] A .NET 6 SDK for ${this.platformInformation.architecture} was not found. Please install the latest ${this.platformInformation.architecture} SDK from https://dotnet.microsoft.com/en-us/download/dotnet/6.0.`);
68+
return;
69+
}
70+
71+
this.logger.appendLine('[STDERR] ' + event.message);
72+
}
73+
4974
private handleOmnisharpInitialisation(event: OmnisharpInitialisation) {
5075
this.logger.appendLine(`Starting OmniSharp server at ${event.timeStamp.toLocaleString()}`);
5176
this.logger.increaseIndent();

test/unitTests/logging/OmnisharpLoggerObserver.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@ import { should, expect } from 'chai';
66
import { getNullChannel } from '../testAssets/Fakes';
77
import { OmnisharpLoggerObserver } from '../../../src/observers/OmnisharpLoggerObserver';
88
import { OmnisharpServerMsBuildProjectDiagnostics, EventWithMessage, OmnisharpServerOnStdErr, OmnisharpServerMessage, OmnisharpServerOnServerError, OmnisharpInitialisation, OmnisharpLaunch, OmnisharpServerOnError, OmnisharpFailure, OmnisharpEventPacketReceived } from '../../../src/omnisharp/loggingEvents';
9+
import { OutputChannel } from 'vscode';
10+
import { PlatformInformation } from '../../../src/platform';
911

1012
suite("OmnisharpLoggerObserver", () => {
1113
suiteSetup(() => should());
1214

1315
let logOutput = "";
14-
let observer = new OmnisharpLoggerObserver({
16+
let channel = <OutputChannel>{
1517
...getNullChannel(),
16-
append: (text: string) => { logOutput += text; },
18+
append: (text: string) => { logOutput += text; }
19+
};
20+
let observer = new OmnisharpLoggerObserver(channel, <PlatformInformation>{
21+
architecture: "x128",
22+
platform: "TestOS"
1723
});
1824

1925
setup(() => {

0 commit comments

Comments
 (0)