'Compiler Problems on MAUI RC1

I have an app that I started using the out of the box MAUI project template. I have been running it on both a local Android emulator and a remote Mac emulator. It had been working on both, and then today after running it on Android for a while, I changed the debugger to use the Mac emulator. It immediately refused to compile, and listed every Android class reference as "type or namespace [blah] could not be found". After playing with several things, I found that if I commented out the "using Java.Net" on the default MainPage.xaml.cs, all of the compiler errors went away. If I uncomment it again, then all 20 something compiler errors show up again. This is the out of the box MainPage.xaml that came with the project template, plus one click event handler that I added - is there some known issue here?

As I said, it was working fine for nearly two weeks, and then just went bananas on me today. Haven't added any nuget packages or anything like that - just been writing code.

Thanks.



Solution 1:[1]

You've described the issue in your question:

using "Java.Net" on the default MainPage.xaml.cs.

That won't compile for any platform except Android.

It doesn't exist on the default MainPage.xaml.cs (which you could have verified by creating a new project).

My recommendation: Start over with a fresh project. Add again whatever you added, and see if that using appears again. If it does, you've added something Android specific. Which doesn't make sense, on a cross-platform page.

If using does appear again, and you don't understand why, then add to your question the exact code which, when added to page, causes using Java.net; to appear.

If you were following some example, also add a link to the example web page.


UPDATE

I have a theory about how that using got there:

I bet you added a reference to some class which exists in Java.net namespace.
So Visual Studio gave you an option to add a "using".

If that happens again, and a "using" mentions Android or Java, DON'T add the using, UNLESS you are in a file inside your project's Platforms/Android folder.

Some class names exist both in an Android or Java namespace, and in a .Net or Maui namespace. In cross-platform code, pick the cross-platform using, not the platform-specific one. If they are in different namespaces, they are different classes - even if the names are the same.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1