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

[BUG] 2 Projects in a solution gives Cannot resolve type "http://schemas.microsoft.com/dotnet/2022/maui/toolkit:SetFocusOnEntryCompletedBehavior". #991

Closed
2 tasks done
gabsamples6 opened this issue Feb 13, 2023 · 13 comments
Labels
wontfix This will not be worked on

Comments

@gabsamples6
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Did you read the "Reporting a bug" section on Contributing file?

Current Behavior

Hi I was really excited to start working with the maui toolkit, and I hope is something I have missed.

If you have a single project all works fine and you dont see the issue , but in a real world project where my main projects reference other Maui class libraries with views and models that are shared you get the error,

Expected Behavior

You should be able to use MCT with many projects and not just a single one. You would not be able to use with Prism Modules or any maui class library that has views in it

Steps To Reproduce

  1. Create a maui app
  2. Add .UseMauiCommunityToolkit() to maui project
  3. add a maui class library
  4. add a Page to a class library
  5. Add an entry with a behavior
  6. build the project and you will see

Error XFC0000 Cannot resolve type "http://schemas.microsoft.com/dotnet/2022/maui/toolkit:SetFocusOnEntryCompletedBehavior".

Link to public reproduction project repository

https://github.com/gabsamples6/MauiAppSampleMCT

Environment

- .NET MAUI CommunityToolkit: 4.0
- iOS: 16.3
- OS: Windows 11 22H2
- .NET MAUI: 7.0.52

Anything else?

I really appreciate the work you guys do for FREE.. If you could easily spot where its going wrong and issue a release that would be fantastic.

We cannot use this library till this is sorted

Many thanks
gab

@gabsamples6 gabsamples6 added bug Something isn't working unverified labels Feb 13, 2023
@gabsamples6 gabsamples6 changed the title [BUG] Error XFC0000 Cannot resolve type "http://schemas.microsoft.com/dotnet/2022/maui/toolkit:SetFocusOnEntryCompletedBehavior". [BUG] 2 Projects in a solution gives Cannot resolve type "http://schemas.microsoft.com/dotnet/2022/maui/toolkit:SetFocusOnEntryCompletedBehavior". Feb 13, 2023
@pictos pictos added wontfix This will not be worked on and removed bug Something isn't working unverified labels Feb 13, 2023
@pictos
Copy link
Member

pictos commented Feb 13, 2023

This isn't a bug... By design to use the custom schema you need to reference anything on CommunityToolkit using C#. Your lib project just use that on xaml, so that will fail. The workaround is to use the old way

xmlns:mct="clr-namespace:CommunityToolkit.Maui.Behaviors;assembly=CommunityToolkit.Maui"

or adding some reference using C#

public SamplePage()
{
	InitializeComponent();
	_ = new CommunityToolkit.Maui.Behaviors.AnimationBehavior();
}

You can read more about it here

@pictos pictos closed this as not planned Won't fix, can't repro, duplicate, stale Feb 13, 2023
@gabsamples6
Copy link
Author

gabsamples6 commented Feb 14, 2023

@pictos thank you very much for your time and reply your workaround works, but I have to say that this is a big MAUI xml definitions limitation!.

In the real world people used shared libraries and they have more than 1 project, this is not a problem in Xamarin.

Again thanks

Lastly
Their design is flawed big time!!! I am sure they did it for a reason but its a joke - what if you are a library vendor what do you do?

@bijington
Copy link
Contributor

Sadly the underlying issue is with the XAML compiler. There has been an ongoing issue for some time to look into it but I think it's considered too difficult or low priority to get fixed.

@gabsamples6
Copy link
Author

@bijington thanks for the extra info.. this maui is really turning into a nightmare ....

@bijington
Copy link
Contributor

It took a while to find but this was the issue I was referring to

dotnet/maui#7503

It hasn't been open for as long as I thought but I am not expecting too much to happen on it. It does look like some level of compiler or linker ripping out the reference when it doesn't believe any of it is actually used. This is why the workaround suggested by @pictos will tell the compiler that it is used. This is not a new issue to .NET MAUI as we have had to deal with this pain on the Xamarin Community Toolkit also

@gabsamples6
Copy link
Author

hmmm for some reasons I didnt notice in XF but we had most of the converters prior the community toolkit and the main thing we use/used in XF was shimmering and toucheffect

@pictos
Copy link
Member

pictos commented Feb 14, 2023

@gabsamples6 for XCT we used a SourceGenerator to create the C# code for you secretly, on MCT we rely on UseCommunityToolkit call on MauiProgram

@gabsamples6
Copy link
Author

@pictos oh that explains it then... and I guess UseCommunityToolkit might not be as clever... as XCT .. its annoying but your suggestions works..

@pictos
Copy link
Member

pictos commented Feb 14, 2023

Yeah, the reason is that this package is designed to be in the mobile app project and not in a lib project... So we didn't do anything to make it cleaver in that area. Not sure if will change at some point in the future

@brminnick
Copy link
Collaborator

brminnick commented Feb 14, 2023

@pictos What do you think about adding a public api like CommunityToolkit.Maui.LibrarySupport.Initialize()?

It could basically just be a dummy method that doesn't execute anything but ensures that the Linker doesn't remove CommunityToolkit.Maui when used in a library:

namespace CommunityToolkit.Maui;

public static class LibrarySupport
{
    public static void Initialize()
    {
        var date = DateTime.Now;
    }
}

@pictos
Copy link
Member

pictos commented Feb 14, 2023

@brminnick I suggest doing anything that can make people feel comfortable about using MCT on libs... Give me some time I'll open a discussion with some scenarios that could be dangerous, that way we can discuss that and see if makes sense to make MCT lib friendly or not

@gabsamples6
Copy link
Author

Hi just to say brilliant. This will be definitely needed as more people embrace maui , and as soon as framework like prism becomes RTM where there is a concept of modules (libs) than it will be very much needed as people will get errors as soon as they trying to use converters etc...

Remember lots of big projects are not embracing maui because its reputation and stability at the moment - as soon they do than they will need this workaround embedded.

@hosamyousof
Copy link

@pictos We appreciate if you give a work around to make MCT work on libs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

5 participants