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

Support not referencing VB #168

Closed
svick opened this issue Jan 28, 2021 · 2 comments · Fixed by #169
Closed

Support not referencing VB #168

svick opened this issue Jan 28, 2021 · 2 comments · Fixed by #169

Comments

@svick
Copy link
Contributor

svick commented Jan 28, 2021

I want to use Buildalyzer.Workspaces, but without referencing Microsoft.CodeAnalysis.VisualBasic.Workspaces (because I have a custom build of Microsoft.CodeAnalysis.CSharp.Worspaces). When I try to do that, I get the following exception:

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.CodeAnalysis.VisualBasic, Version=3.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
File name: 'Microsoft.CodeAnalysis.VisualBasic, Version=3.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
at Buildalyzer.Workspaces.AnalyzerResultExtensions.CreateParseOptions(IAnalyzerResult analyzerResult, String languageName)
at Buildalyzer.Workspaces.AnalyzerResultExtensions.GetProjectInfo(IAnalyzerResult analyzerResult, Workspace workspace, ProjectId projectId)
at Buildalyzer.Workspaces.AnalyzerResultExtensions.AddToWorkspace(IAnalyzerResult analyzerResult, Workspace workspace, Boolean addProjectReferences)
at Buildalyzer.Workspaces.AnalyzerResultExtensions.GetWorkspace(IAnalyzerResult analyzerResult, Boolean addProjectReferences)

This happens because of the following code in CreateCompilationOptions (and similar, but longer code in CreateParseOptions):

https://github.com/daveaglick/Buildalyzer/blob/da88770a2952f7894c05cd0866ef9d766f78aaea/src/Buildalyzer.Workspaces/AnalyzerResultExtensions.cs#L192-L200

This means that JIT compiling the method requires a reference to Microsoft.CodeAnalysis.VisualBasic, even if I only ever want to create C# options.

Extracting the language-specific code into a local function seems to fix this issue.

@daveaglick
Copy link
Collaborator

What an interesting side effect of local functions! I guess because they're "lifted" into separate methods? In any case, I've hit the merge button and am planning a release within the next day or two once I clear the remaining PR backlog. Thanks for the contribution, and sorry for the delay!

@svick
Copy link
Contributor Author

svick commented May 5, 2021

I guess because they're "lifted" into separate methods?

Yes, exactly. Using regular methods would achieve the same effect, but I thought local functions were more appropriate here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants