Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After upgrading Microsoft.CodeAnalysis.CSharp.Workspace from 4.2.0 to 4.3.0 it started throwing at runtime #63921

Closed
Swiftly1 opened this issue Sep 11, 2022 · 0 comments · Fixed by #72712
Assignees
Milestone

Comments

@Swiftly1
Copy link

Swiftly1 commented Sep 11, 2022

Version Used:

4.3.0

Error Thrown:

Unhandled exception. System.InvalidOperationException: Service of type 'Microsoft.CodeAnalysis.Classification.IEmbeddedLanguageClassificationService' is required to accomplish the task but is not available from the workspace. at Microsoft.CodeAnalysis.Host.HostLanguageServices.GetRequiredService[TLanguageService]() in /_/src/Workspaces/Core/Portable/Workspace/Host/HostLanguageServices.cs:line 39 at Microsoft.CodeAnalysis.Classification.Classifier.GetClassifiedSpans(HostWorkspaceServices workspaceServices, Project project, SemanticModel semanticModel, TextSpan textSpan, ClassificationOptions options, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/Classification/Classifier.cs:line 61 at Microsoft.CodeAnalysis.Classification.Classifier.GetClassifiedSpansAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/Classification/Classifier.cs:line 31 at Program.Main()

Workaround:

Adding:

<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Features" Version="4.3.0" />

Repro:

img

using System;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Classification;
	
public class Program
{
	private static readonly ImmutableArray<MetadataReference> _coreReferences =
	ImmutableArray.Create<MetadataReference>
	(
		MetadataReference.CreateFromFile(typeof(object).Assembly.Location
	));
	
	public static void Main()
	{
		var code = "public void Test() {}";
		var host = MefHostServices.Create(MefHostServices.DefaultAssemblies);
		var sourceText = SourceText.From(code);
		var workspace = new AdhocWorkspace(host);

		var doc = workspace
				  .AddProject("Test", LanguageNames.CSharp)
				  .AddMetadataReferences(_coreReferences)
				  .AddDocument("TestFile", sourceText);

		var spans = Classifier.GetClassifiedSpansAsync(doc, new TextSpan(0, code.Length)).GetAwaiter().GetResult();
	}
}

/cc @sharwell

Suspected patch
#61994

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Sep 11, 2022
@arkalyanms arkalyanms added Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Sep 14, 2022
@arkalyanms arkalyanms added this to the 17.4 milestone Sep 14, 2022
@arkalyanms arkalyanms modified the milestones: 17.4, 17.6 P3 Jan 17, 2023
@sharwell sharwell reopened this Mar 25, 2024
sharwell added a commit to sharwell/roslyn that referenced this issue Mar 25, 2024
…layer

The default implementation of IEmbeddedLanguageClassificationService is
provided in the features layer, so make sure it is consumed as optional
in the workspaces layer.

Fixes dotnet#63921
GrahamTheCoder added a commit to icsharpcode/CodeConverter that referenced this issue Apr 21, 2024
The issue says it's fixed, but the tests can't run due to the issue
GrahamTheCoder added a commit to icsharpcode/CodeConverter that referenced this issue Apr 21, 2024
This is fixed again in a later version of roslyn but we can't update due to another bug
dotnet/roslyn#63921
GrahamTheCoder added a commit to TymurGubayev/CodeConverter that referenced this issue Jul 20, 2024
Require roslyn , >=4.8.0 for ref return fix: dotnet/roslyn#68194
Require roslyn <= ~4.1.0 or >=4.11.0 for span classification fix: dotnet/roslyn#63921
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants