C# Objektreferenz nicht auf eine Instanz festgelegt, Ausnahmefehler [Duplikat]
Posted: 13 May 2025, 04:50
Ich habe eine Klasse, hier Code, es gibt zwei Schaltflächen in diesem speziellen Form.
Lassen Sie es mich wissen, danke im Voraus
Code: Select all
public partial class Activation_Form : Form
{
public Activation_Form()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ProcessStartInfo Info = new ProcessStartInfo();
Info.Arguments = "/C ping 127.0.0.1 -n 2 && \"" + Application.ExecutablePath + "\"";
Info.WindowStyle = ProcessWindowStyle.Hidden;
Info.CreateNoWindow = true;
Info.FileName = "cmd.exe";
Process.Start(Info);
Application.Exit(); //restart program
}
private void OpenUrl(string url)
{
try
{
Process.Start(url);
}
catch
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
url = url.Replace("&", "^&");
Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
Process.Start("xdg-open", url);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
Process.Start("open", url);
}
else
{
throw;
}
}
}
private void button2_Click(object sender, EventArgs e)
{
OpenUrl("https://mywebsiteaddress.com/anotherpage.html");
**string current_url = HttpContext.Current.Request.Url.AbsoluteUri;**
MessageBox.Show(current_url, "After Istructions");
}
}
< /code>
Ich habe ein Fehlerbild angehängt: < /p>
Bildbeschreibung hier eingeben < /p>
Ich habe Referenzsystem hinzugefügt. // oben auch. Ich bin mir nicht sicher, ob diese Codezeile logisch korrekt ist: < /p>
Wenn ich ausführe, erhalte ich Ausnahmefehler in dieser Zeile: < /p>
**string current_url = HttpContext.Current.Request.Url.AbsoluteUri;** ???