namespace Android.Widget not available for net7.0-maccatalyst

Tommy Rosberg 0 Reputation points
2023-11-15T09:46:06.06+00:00

I'm trying to use the ImageView class from Android.Widget.

For some reason I cannot build my code beacuse the namespec Android.Widget does not seem to be available for net7.0-maccatalyst.

User's image

Looking through my project Dependencies I can see that the framework where I would expect to find this, Mono.Android, is infact missing in net7.0-maccatalyst. It is available in net7.0-android.

User's image

Any suggestion how to solve, or workaround, this would be greatly appreciated.

Developer technologies | .NET | .NET MAUI
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,156 Reputation points Microsoft External Staff
    2023-11-16T03:03:48.17+00:00

    Hello,

    This error is expected.

    In MAUI, you need to add conditional judgment statements to the code and namespaces for a specific platform. See the code and documentation below.

    #if ANDROID
    using Android.Widget;
    #endif
    

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.