All posts by Emil

Migrating to MAUI from Xamarin.Forms

This is what I had to do to get my app converted to MAUI

TLDR; It was a less than optimal experience.

0. All old projects where updated

For this the Visual Studio Upgrade Assistant was used. It helped a lot with the upgrade, but missed a few referenced NuGet packages for Xamarin.Forms and did not sort the usings in any of the files (the added usings are not even sorted).

1. First try was to keep the current structure with separate project

But after fixing a few of the issues below and it did still not work satisfactory, I started over with a new project. Since the MAUI project template in Visual Studio uses one project for all platforms, that will probably be more used and have higher priority for Microsoft.

2. A referenced .NET Standard project had a space in the <PackageId>

That was a misstake from my side, but that space had been there for seven years, when the project was first created in 2017. At that time it was using .NET Standard 1.4 and none of the project upgrades since then has had any problem with that space.

And the error in Visual Studio for this issue was:

Error CS0006 Metadata file ‘D:[path to .NET Standard project]\obj\Debug\net8.0-android\ref\[project-name].dll’ could not be found

When comparing with other MAUI projects that did compile with proper PackageId (or no PackageId), that net8.0-android folder does not exist in the referenced project. Also when trouble shooting by removing and re-adding the invalid PackageId is somewhat inconsistent since the project has to be cleaned before the changes had any effect.

3. Upgraded old NuGet packages

Some NuGet packages in the project was targeting Xamarin.Froms and had to be updated or removed.

4. Created a new MAUI project

Since the new MAUI template is a single project and the old Xamarin project is four separate projects I started from scratch with a new project and copied the code manually to the new project.

5. Fixed compiler errors

Because of the new folder structure in the new MAUI project there was a few namespace collisions, which had to be fixed manually.

6. The app shows first page on Android

To check that the app starts properly on Android I changed the startup to only show the About page and that worked. After the previous issues this was a big relief.

7. The Windows app does not start

Now the app starts fine on Android, but on Windows it just starts and then crashes with a strange hex-code error.

The program ‘[4780] app.exe’ has exited with code 3762504530 (0xe0434352).

This was because the .gitignore was not updated for several years and the “launchSettings.json” was still ignored, so during the trouble shooting for the issue with the PackageId that file was removed. But I could not find any information on the web about this error. I found the error code, but none of the issues had anything to do with MAUI.

8. Switch the menu from MasterDetailPage to FlyoutPage

Yes, this should have been done a long time ago, but from what I can remember there was some issues when trying to switch earlier. And I think well tested code (that has been in production for a long time) is better than new code.

9. NavigationPage Title does not update

Now when a new page is loaded from FlyoutPage, the Title is not updated in the NavigationPage when a new page is pushed. The first page title that is shown when the app starts, stays there.

10. Switching to AppShell

So to get the page titles to work I switched to AppShell. AppShell is what Microsoft recommends and therefore will it probably higher prioritized in functionality and bug fixes. Switching to AppShell was easier than expected and a new version with new navigation made.

11. AppShell does not support TabbedPage

Now when the app is started every thing looks fine. But the most important pages in the app are tabbed pages and they do not load as expected. Not until i debug the app in Windows I get a proper exception that says that TabbedPage is not supported in an AppShell app.

That important information can will not appear until the runtime exception is hit.

To use AppShell, the TabbedPages must be rewritten. That means new untested code that could cause problems with the current stable app.

12. Switching back to NavigationPage

Re-writing the tabbed page or a bad title bar? Bad title bar seems like a more stable way to go. Tried several workarounds without any success. Then I found that the ToolbarItems are not updated either when a new page is pushed. So the filtering in the app will not work either.

Then at last I found that it was a bug that was fixed. The Visual Studio template for MAUI Apps references the NuGet package Microsoft.Maui.Controls with version “$(MauiVersion)”. It took a long time before I found the blog post that explained what $(MauiVersion) is and how it is supposed to work.

For some reason the Microsoft.Maui.Controls should not be updated like other NuGet packages, it is updated by changing the “<MauiVersion>8.0.6</MauiVersion>” in the project file. And of course, that property is not in the MAUI App template in Visual Studio.

13. Acr.UserDialogs does not work with WinUI

This is not a big issue, the project Acr.UserDialogs is no longer maintained. And the CommunityToolkit.Maui seems to have good replacements for this, but then it is new untested code again.

But it is yet another bump in the road towards the new MAUI App.

14. FlyoutPage crashes in WinUI

When using FlyoutPage (and MasterDetailPage) the code examples show that IsPresented should be set to false when the page has been shown.

But in WinUI the FlyoutPage is always visible and “IsPresented = false” throws a runtime exception. It looks like there is no way to detect if the FlyoutPage is always visible or not, because that property is always set to “Default”.

15. App initialization changed from Xamarin.Forms

In Xamarin.Forms the app had all the Android specific initialization in MainActivity.OnCreate(), but switching to MAUI that initialization is done after the MAUI App constructor is called and some things was not set up when the generic code was initialized.

16. Layout is inconsistent with Xamarin.Forms

When all these issues where fixed the migrated app is still unusable because of the xaml changes that was made between Xamarin.Forms and MAUI. There are changes in the grid layout and stack layout. For some reason that I haven’t found yet, most of the colors are wrong. Lots of text in the layouts are missing or cut off. Other text is stacked ontop of each others. Also, the padding has been intentionally changed in some of the controls, making buttons and text to shrink and be unusable.

17. CollectionView loads all items from ItemSource

All CollectionViews in the app was placed in StackLayouts. This was mostly because before the CollectionView, that was an easy way to add a header and a footer to a ListView.

In MAUI those CollectionViews stopped working (didn’t really stop, but it took minutes to load and used 1 GB extra of memory). After some debugging it turned out that the collection view in MAUI loaded all 600 items in ItemSource into memory, when Xamarin.Forms only loaded the first 30.

After some more digging it shows that it was another design change and CollectionView shall not be placed in StackLayouts anymore. Changing the StackLayouts to Grid fixed this problem.

Remote reset VMware ESXi when vSphere Client cannot connect

I’ve had several issues when I could not connect to vmWare ESXi. The vSphere Client only reported connection failure. The server was running as it should and none of the virtual mashines was affected by this, only the login.

Since the server is hosted in a remote location there has been no other way of fixing it  than to do a hardware reboot. Not the nicest way of solving it.

But since it happen regulary, I’ve turned the SSH as default. So I had one way in to the server when this happen. And there was no problem to log in with a SSH client.

I’ve tried to find a way to reset the service that vSphere Client connected to, but could not find anything. Some posts at the VMware site suggested that some processes should be restarted, but that was no luck. One suggestion was even that there was a problem with the local network, didn’t even try that.

After a while I gave up and decided to reboot the whole vmWare host with shutdown -r now. But in the vmWare host I could not find the shutdown command. Instead there was a shutdown.sh in the bin  (sbin) folder.

Maybe there was some clues in the shutdown.sh script.? It sure was! One of the lines in shutdown.sh was /sbin/services.sh stop. I just had to try and do a restart instead of a stop on that script. My backup plan was that if anything went terribly wrong, I would have to call the off site and have them do a physical power down on the server.

And it turned out a success! After the script had finished there was no problem at all to log in with the vSphere Client. None of the virtual mashines was affected and none of the web site neither.

/sbin/services.sh restart

Connecting to Server with Hyper-V Manager without Domain

After installing Windows Server 2016 Hyper-V on a small office network without domain or AD, I had big troubles with managing the server from Hyper-V Manager.

Found a guide from Microsoft that looked that it would solve the problem. But after trying “all” the steps there was still no luck with connecting to the server.

https://msdn.microsoft.com/en-us/virtualization/hyperv_on_windows/user_guide/remote_host_management

These were the steps that most useful to me:

On the Hyper-V host to be managed, run the following as an administrator:

  1. Enable-PSRemoting
    • Enable-PSRemoting will create the necessary firewall rules for private network zones. To allow this access on public zones you will need to enable the rules for CredSSP and WinRM.
  2. Enable-WSManCredSSP -Role server

On the managing PC, run the following as an administrator:

  1. Set-Item WSMan:\localhost\Client\TrustedHosts -Value “fqdn-of-hyper-v-host”

  2. Enable-WSManCredSSP -Role client -DelegateComputer “fqdn-of-hyper-v-host”

  3. Additionally you may need to configure the following group policy: ** Computer Configuration | Administrative Templates | System | Credentials Delegation | Allow delegating fresh credentials with NTLM-only server authentication **

    • Click Enable and add wsman/fqdn-of-hyper-v-host

I did not do the last and optional step because I didn’t know how to do it. Of course that was the missing part!

To get to the Computer Configuration you have to start the “Local Group Policy Editor“. You can search for it in Windows or run the command “gpedit.msc“.

Also for those who don’t know, FQDN is “Fully Qualified Domain Name”.

Windows Mobile Device Center and Windows 10

Upgrading to Windows 10 did not give me any issues with the connection to Windows Mobile with Windows Mobile Device Center (WMDC) which I need for the software I develop for Windows Mobile and Compact Framework.

Windows Mobile Device Center Stops Connecting

But after having a break from developing for Windows Mobile for a few months, the WMDC just could not connect anymore. First I tried to uninstall WMDC for a re-installation. There was some problems with it but after forcing the uninstall (don’t remember how) it was gone. But then the installation did not work. “The update could not be installed because at least one Windows component required by Windows Device Center is missing.”

Windows Mobile device center #2

 

This is obsolete software that Microsoft does not care about at all, so the information online is rare. The few suggestions online did not work.

Reinstalling Windows

After trying all I could think of for several weeks I gave up and reinstalled Windows. I was thinking about doing a reset of Windows, but Windows warned me that I had to reinstall several “apps” manually — and that list was several screens long! So I installed a new instance on another disk with dual boot to be able to use all my old “apps”.

On that clean installation of Windows 10, I was back on square one. Once again I got “The update could not be installed because at least one Windows component required by Windows Device Center is missing.”

That’s when I realized that I installed the N-version of Windows 10. That does not include the Media Player (that I didn’t want). But for some reason the Windows Mobile Device Center wants that Media Player.

After downloading and installing the Media Feature Pack for Windows 10 from https://www.microsoft.com/en-us/download/details.aspx?id=48231, the installation of WMDC worked and my Windows Mobile Devices could connect again!

Now I thought that I had a solution for my original version of Windows, so I booted to that version and tried to install Media Feature Pack. But unluckily I got a message telling me that the Media Feature Pack was already installed. And I cannot find any way to uninstall.

The Fallback

Then during the night the new and working instance of Windows run an upgrade to version 1511.

And now the Windows Mobile Device Center refuses to connect agan! So that’s what happened with my original installation of Windows!

This could be helped with uninstalling the 1511 upgrade, but I don’t know when Windows installs that in the background next time.

The “Complete” Compilation

Before I reinstall Windows, or installs yet another instance on another drive, I want to know exactly what works and what doesn’t work. So I installed three different versions of Windows in VMware where I will try different approaches and see what works.

Windows 10 (RTM)

  1.  Installing Windows Mobile Device Center
 Working
  1. Installing Windows Mobile Device Center
  2. Running Windows Update (with 1511 upgrade)
 NOT Working
  1. Installing Windows Mobile Device Center
  2. Running Windows Update (with 1511 upgrade)
  3. Reverting the 1511 upgrade (Go back to an earlier build)
 Working
  1. Installing Windows Mobile Device Center
  2. Running Windows Update (with 1511 upgrade)
  3. Reverting the 1511 upgrade (Go back to an earlier build)
  4. Uninstalled WMDC
  5. Reinstalled the 1511 upgrade of Windows
  6. Reinstalled WMDC

Working
  1. Installing Windows Mobile Device Center
  2. Running Windows Update (with 1511 upgrade)
  3. Uninstalled WMDC
  4. Reinstalled WMDC

Working

Windows 10 N (RTM)

  1. Installing Windows Mobile Device Center
 NOT Working
  1. Installing Media Feature Pack
  2. Installing Windows Mobile Device Center
 Working

Windows 10 1511 (from Apr 2016)

  1.  Installing Windows Mobile Device Center
 Working
  1. Installing Windows Mobile Device Center
  2. Running Windows Update
 Working
  1. Installing Windows Mobile Device Center
  2. Running Windows Update with Insider Preview in the Fast Ring (OS Build 14352.1002)
 NOT Working
  1. Installing Windows Mobile Device Center
  2. Running Windows Update with Insider Preview in the Fast Ring (OS Build 14352.1002)
  3. Uninstalled WMDC
  4. Reinstalled WMDC
 Working

I will update the lists when I have more information.

The Solution

The solution to this problem is much easier than I first thought. After the 1511 upgrade just uninstall and reinstall Windows Mobile Device Center. THAT was EXACTLY what I tried, but the uninstall only gave me strange errors. I guess my problem was because there was several months between the 1511 upgrade and when I tried to uninstall WMDC and lots of other updates and development software had been installed after that.

Maybe, in my case,  I should have reverted the 1511 upgrade. Uninstalled Windows Mobile Device Center and then reinstalled upgrade 1511 and WMDC. Unfortunately, since it been several months since Windows installed the 1511 update, the option to revert to an earlier build is no longer available.

Conclusion

The best way to solve this for me is no longer available. The other options are:

  • Reset Windows and reinstall all programs.
  • Clear the disk and do a clean installation of Windows and all programs.
  • Keep using the second installation of Windows on the other disk and install all programs there.

It feel like that the best way would be to start all over with a clean installation of the Apr 2016 release of Windows 10. But I will think about that for a few days. If I knew there was a new upgrade coming soon I could wait for that, but that upgrade seems to be quite far away.

The Future

The question is what will happen with the next upgrade of windows? Will that also crash Windows Mobile Device Center, maybe next time uninstalling the upgrade will not help.

Microsoft is already not caring much for Windows Mobile. So one upgrade in the future will probably stop the WMDC completely.

Running ASP.NET 5 MVC on IIS 8.5

This is how I got my ASP.NET 5 MVC site to run on IIS 8.5. I had some initial problems and most information I found on internet was about earlier beta versions of the framework. All of these had lots of steps and and none of them helped me.

Software Setup

  • Windows Server 2012 R2 (fresh install)
  • IIS 8.5
  • DNX Version: dnx-clr-x64.1.0.0-rc1-update1
  • Visual Studio 2015 Update 1

Server Installation

  1. Added Server Role: Web Server (IIS).
    And also ASP.NET 4.5 (under Web Server (IIS) -> Web Server -> Application Development).
    This will also include the feature ASP.NET from .NET Framework and ISAPI Extensions, ISAPI Filters and also .NET Extensibility 4.5.
  2. Installed the HttpPlatformHandler 1.2 from:
    http://www.iis.net/downloads/microsoft/httpplatformhandler

Publishing Site

  1. Compiled and Published the Web project in Visual Studio to a local folder.
    Configuration: Release – x64 (will probably work with Any CPU also).
    Target DNX Version: dnx-clr-x64.1.0.0-rc1-update1
  2. Copied the published output to the Web Server.
  3. Added a new  Site pointing to the wwwroot in the published folder.

And that was all that was necessary. Obviously running an ASP.NET 5 site is much easier now when the release candidate is out.

Microsoft.CompactFramework.CSharp.targets not found after Update 10586 of Windows 10

After installing Update 10586.3 from Windows Update the Compact Framework projects could not be loaded in Visual Studio 2008. The error was something like “C:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.CompactFramework.CSharp.targets’ cannot be found.”

I haven’t found any explanation of why this file (and some other Compact Framework files was removed during the update.

But the simple solution was to do a Repair/Reinstall of Visual Studio 2008.

Update August 17, 2016

Now Windows updated to Version 1607 (Build 14393.51) and the same problem  is back again.  It looks like we will have to do a reinstall of Visual Studio 2008 after each update of Windows 10.

Update May 22, 2019

I case anyone else than me still does maintenance work in Compact Framework the commenters are absolutely right. The Power Toys for .NET Compact Framework 3.5 (https://www.microsoft.com/en-us/download/details.aspx?id=13442) is much easier to install than reinstalling Visual Studio.

But what I’ve done a few times is just copying the files named *CompactFramework* from another computer, that also has Visual Studio 2008 installed, into C:\Windows\Microsoft.NET\Framework\v3.5. Or just save the *CompactFramework* files in another folder or a network drive until the next Windows Update.