Hello,
I am having problems implementing my chat application to my website. The application loads fine as long as I don't set a value of init params when I do it does not load and I don't recieve any exceptions/errors of any kind. The code is as follows:
Default.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Kawanoikioi.Community.Chat.Default" %><asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server"><style type="text/css"> #silverlight-host { width:800px; height:500px; }</style></asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"><object id="silverlight-host" data="data:application/x-silverlight-2," type="application/x-silverlight-2"><param name="source" value="../../ClientBin/Kawanoikioi.Chat.xap" /><param name="minRuntimeVersion" value="5.1.30214.0" /><param name="initParams" id="InitParams" runat="server" onprerender="InitParams_PreRender" /></object></asp:Content>
Default.aspx.cs
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace Kawanoikioi.Community.Chat { public partial class Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void InitParams_PreRender(object sender, EventArgs e) { InitParams.Attributes.Add("value", string.Format("username={0}", HttpContext.Current.User.Identity.Name)); } } }
App.xaml.cs
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Markup; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; namespace Kawanoikioi.Chat { public partial class App : Application { public static string Username { get; private set; } public App() { this.Startup += this.Application_Startup; this.Exit += this.Application_Exit; this.UnhandledException += this.Application_UnhandledException; InitializeComponent(); } private void Application_Startup(object sender, StartupEventArgs e) { if(!Application.Current.IsRunningOutOfBrowser) { Username = e.InitParams["username"]; } this.RootVisual = new MainPage(); } private void Application_Exit(object sender, EventArgs e) { } private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) { // If the app is running outside of the debugger then report the exception using // the browser's exception mechanism. On IE this will display it a yellow alert // icon in the status bar and Firefox will display a script error. if (!System.Diagnostics.Debugger.IsAttached) { // NOTE: This will allow the application to continue running after an exception has been thrown // but not handled. // For production applications this error handling should be replaced with something that will // report the error to the website and stop the application. e.Handled = true; Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); }); } } private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e) { try { string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace; errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n"); System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");"); } catch (Exception) { } } } }Thank you in advance. Please do not link me to http://msdn.microsoft.com/en-us/library/cc189004(v=vs.95).aspx or http://msdn.microsoft.com/en-us/library/cc838255(v=vs.95).aspx since I have already read these and from what I can tell I am doing it correctly based on these resources.