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

UWP App Compiler Errors in x64 Release mode but not Debug mode. #67187

Open
Calphalon opened this issue Mar 4, 2023 · 4 comments
Open

UWP App Compiler Errors in x64 Release mode but not Debug mode. #67187

Calphalon opened this issue Mar 4, 2023 · 4 comments

Comments

@Calphalon
Copy link

Version Used:
Microsoft.CodeAnalysis.Analyzers v3.3.3

Steps to Reproduce:

  1. Create App using Microsoft.CodeAnalysis.Analyzers (in my case using VB)
  2. Compile in for x64 Release with .NET Native on
  3. Receive many Erros and Warnings

A case was created with the Visual Studio Team here (note, with x64, not x86 as I originally wrote).
After much back and forth and me providing them a sample project that exhibited the errors, they decided it was not their problem:

This issue seems to be caused by Microsoft.CodeAnalysis and not Visual Studio. Please file a GitHub issue with that product at https://github.com/dotnet/roslyn stating that Microsoft.CodeAnalysis is using C# features incompatible with .NET native.

Diagnostic Id:

Received many errors such as:

Severity Code Description Project File Line Source Error ILT0038: ‘Microsoft.CodeAnalysis.Formatting.AutoFormattingOptions’ is a value type with a default constructor. Value types with default constructors are not currently supported. Consider using an explicit initialization function instead.

And warnings such as:

Severity Code Description Project File Line Source Tool
Warning MCG : warning MCG0001: [MarshalAs(UnmanagedType=(Default), ElementType=(Default))] with type ‘Microsoft.DiaSymReader.VariantStructure’ is not supported.This signature is located on ‘System.Void Microsoft.DiaSymReader.ISymUnmanagedWriter5.DefineConstant2(System.String, Microsoft.DiaSymReader.VariantStructure, System.Int32)’.

Expected Behavior:
I expect it to compile correctly.

Actual Behavior:
Did not compile correctly.

Note that I was able to fix this by adding an ExcludeAssets directive to the .vbproj folder as such:

<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic">
<Version>4.5.0</Version>
<ExcludeAssets>All</ExcludeAssets>
<IncludeAssets>none</IncludeAssets>
</PackageReference>

If nothing else, some clear instructions to do this would have been helpful. Took two weeks to troubleshoot via the internet, MS docs, and Stack Overflow. But I expect that it should have worked without doing this.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Mar 4, 2023
@Sergio0694
Copy link
Contributor

This is by design. For instance, that error about not supporting a parameterless struct constructor is because those were added in C# 10, but .NET Native only officially supports up to C# 7.3. Anything beyond that might or might not work, but parameterless struct constructors are an example of something that does not. Same for that other error you got, that's also something that's just not supported and will not be.

The question is, why do you want to add Microsoft.CodeAnalysis.Analyzers as a runtime dependency in the first place? Doesn't that package just contain analyzers for you to consume at compile time?

@Calphalon
Copy link
Author

To be clear, it was not my goal to include the analyzers. The issue was that Visual Studio, by default, attempts to include them, and then they fail to compile in .NET Native. As I noted, if the requirement is that they be excluded from release mode (and I agree they should be), then either Visual Studio should not include them in release mode, or clear instructions on the need, and how, to exclude them should be clearly documented. I spent several days scouring the internet and much trial and error on how to handle before I figured it out. Perhaps this is really a VS issue, but I contacted the VS team and they declined to address and pointed to you folks.

@jcouv jcouv added Question and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Mar 9, 2023
@jcouv jcouv added this to the Compiler.Next milestone Mar 9, 2023
@svick
Copy link
Contributor

svick commented Mar 16, 2023

Your project snippet shows that you're referencing the Microsoft.CodeAnalysis.VisualBasic package, not Microsoft.CodeAnalysis.Analyzers. I think that's where the difference lies. You shouldn't reference Microsoft.CodeAnalysis.VisualBasic unless you want to analyze or compile VB code at runtime in your application.

@Calphalon
Copy link
Author

A couple of things:

  1. I went back and looked at my exchange with the VS team and according to those notes, I did indeed try swapping out Microsoft.CodeAnalysis.VisualBasic with Microsoft.CodeAnalysis (the top-level item) in my project, and the results were exactly the same. (I just double checked that by swapping out, and indeed the result are the same, if fails to compile, but do note that I did not attempt to rectify by changing the .vbproj file for Microsoft.CodeAnalysis as noted above.)

  2. In my exchange with the VS team, I create a minimal test UWP application, just a page, and only referenced Microsoft.CodeAnalysis, the results were the same.

  3. The NuGet Documation for Microsoft.CodeAnalysis says "You can install any of these sub-packages if you only want part of the functionality: ... Microsoft.CodeAnalysis.VisualBasic (only the VB compiler)"

  4. Even if wanted to analyze or compile VB code at runtime, which I don't, I am pretty sure that would fail for the reasons I noted. It just won't compile.

The point is, if you reference either package, (as far as I can tell) you cannot compile in .NET Native unless you add the exclude code to the project file. Again, I think that is OK, but someone should clearly document that. Took me days to figure out.

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

No branches or pull requests

5 participants