Hmm jeg har problemer med at få det til at virke. Jeg har lavet følgende: - Jeg har oprettet et nyt projekt + solution i Visual Studio som hedder WebApplication1 - Der er oprettet en fil der hedder TestClass.cs (Min klasse) - Der er oprettet en WebForm der hedder WebForm1.aspx
Mine filer ser ud som følgende:
** TestClass.cs ** using System;
namespace WebApplication1 { /// <summary> /// Summary description for TestClass. /// </summary> public class TestClass { public TestClass() { // // TODO: Add constructor logic here // }
public string getText() { return "Det virker da bare :o) "; }
public string getMyText(string myText) { return myText; } } }
** WebForm1.aspx.cs ** using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Reflection;
namespace WebApplication1 { /// <summary> /// Summary description for WebForm1. /// </summary> public class WebForm1 : System.Web.UI.Page { protected System.Web.UI.WebControls.Label Label1;
#region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load);
Den fejl der opstår er følgende: Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 24: Object o = Assembly.Load("WebApplication1").CreateInstance("TestClass"); Line 25: string myString = ""; Line 26: myString = (string) o.GetType().InvokeMember("getText", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, null, o, null); Line 27: Label1.Text = "Hello World"; Line 28: }
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.