-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
XamlC XC0022 error : Binding could be compiled if x:DataType is specified. #20568
Comments
We are facing the same issue, and it is breaking our previously successful builds, since we also treat warnings as errors to keep our code base clean. Lots of warnings with this error message. We have no way to fix or ignore this warning via project file or editorconfig. We can not fix all instances, as we often bind to ViewModels which use generics like Very bold decision to just unleash hundreds of warnings without an error code that makes it configurable. |
If you search the string it comes up here: maui/src/Controls/src/Build.Tasks/BuildException.cs Lines 58 to 59 in d749dc7
Which is related to: Going by it, it does have an error code that should appear, maui/src/Compatibility/ControlGallery/src/Core/Compatibility.ControlGallery.Core.csproj Lines 6 to 8 in 35bbb34
@StephaneDelcroix What do you think? |
We use Could you please try and see if it helps ? Reading the doc again, it seems CSC allows both as separators. Fixing this... |
I was going by the documentation and didn't think this could be the problem. |
@Hottemax we recommend that you don't ignore the warnings, but you can do it by setting |
I did that - already after your first link to the Maui.Compatibility repo sample in your initial reply. |
@StephaneDelcroix, I agree that this is a useful finding and would be better not to ignore, but is there a way in Maui xaml to specify a datatype for a generic type? |
Yes we have same issue of using generic types or interfaces to ensure specific properties exist on an object that is bound via XAML. Not sure how to handle this situation with this new warning. |
Yeah, it would be really nice if we could gain some insight on how to achieve this from this issue. I really felt bad not having compiled bindings in these cases, but found no easy way to do it. All the examples we found were always just something along the lines of how to specify the generic type on CollectionView bindings or something similar. |
generics in XAML are expressed like this |
@StephaneDelcroix Thanks for your reply! I have read https://learn.microsoft.com/en-us/dotnet/maui/xaml/generics?view=net-maui-8.0, and I don't exactly understand what you want me to try out/test. What would be the XAML syntax if I want to bind to lets say a ViewModel of type Currently what we do is have a file where we define dozens of "dummy" classes like this: public class ArticleViewModel : BoViewModel<BoArticle> { }
public class ArticleListViewModel : CardListViewModel<BoArticle> { }
public class PebSampleListViewModel : SamplesListViewModel<BoPebSample> { }
public class EmployeeListPageViewModel : CardListViewModel<BoEmployee> { } and then we can do
But is there any way to avoid this "dummy class", and just bind to Because this kind of syntax is not working. Or can you illuminate what you want us to try? Thanks for your patience! |
@Hottemax the syntax (again, I can guarantee it works) would be |
@StephaneDelcroix - based on example provided by @Hottemax ... wouldn't the syntax be: |
Unfortunately this does not work for me.
if anyone has a link into some sample repo where I can observe this kind of syntax working, it would be greatly appreciated. |
I'm hitting this issue too. In my case I couldn't easily tell what
In 8.0.6 I'd had the DataType set to So, it seems there's a bug here in that if the binding compile then I expect they should work at run time... But also a possible improvement to be made, if xamlc knows that a binding could be compiled, then doesn't it already know what the type should be? It could maybe give us a hint to save us some time in fixing the warnings. Or is this just a blanket warning for all bindings that aren't compiled? |
@StephaneDelcroix, according to your offer, should I create an issue for this now, and tag-mention you? Just want to make sure before doing so that this is a real issue and I am not doing something obvious wrong with
|
@Hottemax please do |
@StephaneDelcroix Could you point to a piece of documentation or issue/thread describing why XC0022/XC0023 should be avoided? (Or explain here). The warning itself "Binding could be compiled if x:DataType is specified" does not say much. |
(Also, not confirmed yet, but I get a LOT of warnings although i defined x:DataType almost everywhere and I suspect the XAML code inside toolkit:StateContainer.StateViews (xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit") gets flagged with the warning even though x:DataType is declared on the outside) |
Confirmed the reason why I get many of these warnings is that I am using CommunityToolkit's StateContainer. Not sure if it is an issue to report here or on the CommunityToolkit's repo, or even if it is an issue. Repro at: https://github.com/durandt/maui-issue6-xaml-datatype-warnings Example:
I can get rid of the warning if I specify the x:DataType again at the top of the state view:
|
Such issue began to appear again in latest Visual Studio preview with DOTNET 9 preview. |
I can confirm it works in the current MAUI release (I get a compile-time error if the property is not found when x:DataType is specified. However, it would be nice if the support in the XAML editor can be improved |
Description
MAUI 8.0.7 reports the Errors XC0022 and XC0023 as errors, not as warnings.
I have treat warnings as error active, but
<WarningsNotAsErrors>XC0022,XC0023</WarningsNotAsErrors>
does not help.Steps to Reproduce
Create a Binding, leave out x:DataType or set x:DataType to {x:Null}
Link to public reproduction project repository
No response
Version with bug
8.0.7 SR2
Is this a regression from previous behavior?
Yes, this used to work in .NET MAUI
Last version that worked well
8.0.6 SR1
Affected platforms
Android, I was not able test on other platforms
Affected platform versions
No response
Did you find any workaround?
Stay with 8.0.6 for the moment
Relevant log output
No response
The text was updated successfully, but these errors were encountered: