How to fix: Exception thrown: 'System.Runtime.InteropServices.COMException' in WinRT.Runtime.dll The program has exited with code 3762504530 (0xe0434352).
I have a .NET MAUI app that I am completing on Visual Studio Professional 2022. I have cleaned, restored, and build the app with no errors. I configured the app to run on Windows. Just before launching, the app crashes with this error: Exception thrown: 'System.Runtime.InteropServices.COMException' in WinRT.Runtime.dll
The program has exited with code 3762504530 (0xe0434352). I made extensive search but have not found a way to solve this problem. Really need some help here.
I am not using Office with this application. I am building my app on Windows Server 2019 standard edition.
MauiProgram.cs as follows:
using Microsoft.Maui;
using Microsoft.Maui.Controls.Hosting;
using Microsoft.Maui.Hosting;
using XXXXXXXXXXX;
namespace XXXXXXXXXXXXXXXXXX
{
public class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureMauiHandlers(handlers =>
{
// Example: Adding a custom handler for an Entry control
handlers.AddHandler<Entry, CustomEntryHandler>();
});
return builder.Build();
}
}
}
MainPagexaml.cs as follows:
namespace XXXXXXXXXXXXXXXXX
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
// EventHandler for the button click
private void OnNavigateButtonClicked(object sender, EventArgs e)
{
// Code to handle navigation, for example:
Navigation.PushAsync(new IntroPage());
`}
}
}
CustomEntryHandler.cs:
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Graphics;
#if ANDROID
using Android.Graphics;
using Android.Widget;
#endif
#if WINDOWS
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI;
#endif
#if IOS || MACCATALYST
using UIKit;
#endif
public class CustomEntryHandler : EntryHandler
{
// The Customize method applies platform-specific customization
public static void Customize()
{
ruby
// Use AppendToMapping to apply custom behavior to the platform-specific controls
EntryHandler.Mapper.AppendToMapping(nameof(CustomEntryHandler), (handler, view) =>
{
#if ANDROID
// Android-specific customization
if (handler.PlatformView is EditText editText)
{
editText.SetBackgroundColor(Android.Graphics.Color.LightGray); // Set background color for Android
}
#elif IOS || MACCATALYST
// iOS/macOS-specific customization
if (handler.PlatformView is UITextField textField)
{
textField.BackgroundColor = UIColor.LightGray; // Set background color for iOS/macOS
}
#elif WINDOWS
// Windows-specific customization
if (handler.PlatformView is TextBox textBox)
{
textBox.Background = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.Colors.LightGray); // Set background color for Windows
}
#endif
});
}
}
1 answer
Sort by: Most helpful
-
Deleted
This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.
Comments have been turned off. Learn more