Skip to content

Unexpected System.Exception thrown by source generator; reported through telemetry #9018

@sharwell

Description

@sharwell

One or more of the following lines are throwing System.Exception at a location where exceptions are not expected:

_dependencyObjectSymbol = comp.GetTypeByMetadataName(XamlConstants.Types.DependencyObject)
?? throw new Exception("Unable to find " + XamlConstants.Types.DependencyObject);
_generatedDependencyPropertyAttributeSymbol = comp.GetTypeByMetadataName("Uno.UI.Xaml.GeneratedDependencyPropertyAttribute")
?? throw new Exception("Unable to find Uno.UI.Xaml.GeneratedDependencyPropertyAttribute");
_dependencyPropertyChangedEventArgsSymbol = comp.GetTypeByMetadataName("Windows.UI.Xaml.DependencyPropertyChangedEventArgs")
?? throw new Exception("Unable to find Windows.UI.Xaml.DependencyPropertyChangedEventArgs");

This was identified in error telemetry at Microsoft, and I'm happy to take the time to provide additional details here because you've chosen to make your project open source. 👍

I recommend resolving this issue in one of the following ways:

  1. If this issue only occurs when there are other compiler errors present in the user code, it would be acceptable to silently disable the source generator in this case. The source generator would become active again when the user corrects the code.
  2. If this issue can occur where users might not know how to resolve the issue, rather than throw an exception the generator can use the ReportDiagnostic API to report a user-visible error specific to the scenario.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/code-generationCategorizes an issue or PR as relevant to code generationdifficulty/medium 🤔Categorizes an issue for which the difficulty level is reachable with a good understanding of WinUIkind/enhancementNew feature or requeststaleThis item has been marked as stale and will be closed if there is no activity.triage/potentially-fixedCategorizes an issue as potentially fixed by some unlinked PR, fix needs to be verified

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions