C
C#2y ago
Wizard

❔ Output error when user missing .NET runtime

I have an AvaloniaUI project targetting .NET Framework 4.6.2 AND .NET6. It builds two EXEs: one for NET6 and one for NET462. Works great, except there's an annoyance I'd like to fix: When the user opens my program and they're missing the required NET runtime for that specific EXE, my program will crash to desktop. No errors, warnings, popups, nothing. Happens before any of my stuff is initialized so I can't even log to a file. I realize this is a user issue but I'd like to at least be able to tell my user the problem. Does anyone by chance know a solution?
9 Replies
Wizard
WizardOP2y ago
Entry point:
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using Avalonia;

namespace KOTORModSync.GUI
{
internal static class Program
{
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main( string[] args ) => BuildAvaloniaApp()
.StartWithClassicDesktopLifetime( args );

// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToTrace();
}
}
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using Avalonia;

namespace KOTORModSync.GUI
{
internal static class Program
{
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main( string[] args ) => BuildAvaloniaApp()
.StartWithClassicDesktopLifetime( args );

// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToTrace();
}
}
Jimmacle
Jimmacle2y ago
you want to still run your .NET application without .NET to tell them they need to install .NET?
Sossenbinder
Sossenbinder2y ago
Would it be an option to distribute your binary in a self-contained way together with the framework? I'd also agree with Jimmacle here, not sure if I see this working without .Net
Jimmacle
Jimmacle2y ago
self contained or an installer that detects and installs .NET if needed seem like good ideas
Wizard
WizardOP2y ago
I just want some sort of diagnostic to inform the user the problem rather than crashing with no info. Currently the #1 question being asked on my issues board lol. I figure there might be some sort of early event that doesn't need a NET runtime? I don't think that's feasable as I target both linux and windows. If a user downloads the net462 version it definitely ain't going to run on linux. regardless of if i pack it I considered including a bat script that'd open my program and call dotnet --listsdks, until I found out that the end user NET version doesn't include the sdk.. so I'm stumped.
reflectronic
reflectronic2y ago
well, you could use --list-runtimes but, also, there is definitely an error that gets printed/shown by .NET when it isn't installed you should not need to do this yourslf but, also, i don't understand why you are building for net462
Wizard
WizardOP2y ago
because I need to support early windows operating systems. My program is written for a very old game that runs on windows xp. Realistically I can't target XP but targetting net462 at least lets me target vista --list-runtimes isn't really available to users with the runtime and not the sdk
Blaze987
Blaze9872y ago
I think you're looking for a setup.exe / MSI installer. There's a bunch of ways to build those alongside your project. As for crossplatform compatibility, there's a reason sites have multiple download links 1 for each OS. They all need the correct runtimes and dependencies to be installed. You'd need to create a separate setup project to create all of these if that's something you want to support.
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server