C# Objektreferenz nicht auf eine Instanz festgelegt, Ausnahmefehler [Duplikat]C#

Ein Treffpunkt für C#-Programmierer
Anonymous
 C# Objektreferenz nicht auf eine Instanz festgelegt, Ausnahmefehler [Duplikat]

Post by Anonymous »

Ich habe eine Klasse, hier Code, es gibt zwei Schaltflächen in diesem speziellen Form.

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;** ???
Lassen Sie es mich wissen, danke im Voraus

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post