DotNetNuke error when module is added - dotnetnuke

I'm developing a dnn module. And i used codebehind C#. But DNN shows error when I add a the module. Other pages work just fine but the page I add the module to says DotNetNuke error. The error does not have any code and it only displays my logo. Even the admin strip disappears.
What did i do wrong?
using System;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Services.Localization;
using DotNetNuke.Security;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Web.UI;
using System.Configuration;
//imports
namespace DotNetNuke.Modules.Catagory
{
public partial class View : CatagoryModuleBase, IActionable
{
public bool inEdit = false;
private bool IsValid = true;
#region Event Handlers
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
private void Page_Load(object sender, System.EventArgs e)
{
try
{
if (IsPostBack)
{
if (Catagory_Table.SelectedRow != null)
{ //There is a selected item, hence edit mode Catagory_Table.SelectedIndex >= 0
this.inEdit = true;
to_edit_mode();
}
else
{
to_add_mode();
}
}
else
{
to_add_mode();
}
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
protected void Button1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
SqlDataSource1.Insert();
}
//the rest if the methods to handle the buttton events....
}

You will want to try to check the Admin/Event Viewer to see what the error is specifically, then you can be better informed on what it will take to fix.

Related

Awesomium.NET open links in default browser

I have problem with awesomium web control 1.7.4 in WPF , when the user click links in page , awesomium navigate to targetURL , but i want to open that links in system default browser.
also I want to determine mailto:jondue#example.com to open this links in default Email client.
Please help me.
Thanks
Update :
I've been doing some more searching to solve my problem, after few days I founded that when the link has a target=_blank the event ShowCreatedWebView is fired. The main problem was about links without target=_blank. After that I'm able to find links without that cause firing event RequestBringIntoView.
private void Browser_ShowCreatedWebView(object sender, Awesomium.Core.ShowCreatedWebViewEventArgs e)
{
System.Diagnostics.Process.Start(Browser.TargetURL.AbsoluteUri);
}
and
private void Browser_RequestBringIntoView(object sender, RequestBringIntoViewEventArgs e)
{
if (Browser.TargetURL != new Uri("about:blank"))
{
System.Diagnostics.Process.Start(Browser.TargetURL.AbsoluteUri);
e.Handled = true;
}
}
I've been doing some more searching to solve my problem, after few days I founded that when the link has a target=_blank the event ShowCreatedWebView is fired. The main problem was about links without target=_blank. After that I'm able to find links without that cause firing event RequestBringIntoView.
private void Browser_ShowCreatedWebView(object sender, Awesomium.Core.ShowCreatedWebViewEventArgs e)
{
System.Diagnostics.Process.Start(Browser.TargetURL.AbsoluteUri);
}
and
private void Browser_RequestBringIntoView(object sender, RequestBringIntoViewEventArgs e)
{
if (Browser.TargetURL != new Uri("about:blank"))
{
System.Diagnostics.Process.Start(Browser.TargetURL.AbsoluteUri);
e.Handled = true;
}
}
You could try using IResourceInterceptor to decide what you want to do when Awesomium loads a page.
public partial class MainWindow : Window
{
public MainWindow()
{
WebCore.Initialize(new WebConfig());
WebCore.Initialized += ((object sender, CoreStartEventArgs e) =>
{
WebCore.ResourceInterceptor = new ResourceInterceptor("http://google.com/");
});
InitializeComponent();
}
}
public class ResourceInterceptor : IResourceInterceptor
{
//Url of the first page to be loaded inside webcontrol without redirection.
protected string m_startupURL;
public ResourceInterceptor(string startupURL)
{
m_startupURL = startupURL;
}
public virtual bool OnFilterNavigation(NavigationRequest request)
{
if (request.Url.ToString() != m_startupURL)
{
System.Diagnostics.Process.Start(request.Url.ToString());
return true;
}
return false;
}
public ResourceResponse OnRequest(ResourceRequest request)
{
return ResourceResponse.Create(request.Url.OriginalString);
}
}
This is a very basic implementation. You should add some additional tests on the Url. Actually Process.Start(request.Url.ToString()) can do anything (launching an application or formatting your disk). So don't forget to test whether it is a valid Url or a mailto: link.

MessageBox not showing when "Unhandled Exception" triggers in winforms

so I was trying to add "AppDomain.CurrentDomain.UnhandledException" handler to my application and it worked OK if I log the error to a text file. but when I try to use a MessageBox it never pops. is it another bug in .Net? any ideas?
here is my code sample:
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
and here is my handler method:
static void CurrentDomain_UnhandledException (object sender, UnhandledExceptionEventArgs e)
{
try
{
Exception ex = (Exception)e.ExceptionObject;
MessageBox.Show("Whoops! Please contact the developers with "
+ "the following information:\r\n\r\n" + ex.Message + ex.StackTrace,
"Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
finally
{
Application.Exit();
}
}
EDIT: I've tried all of the possible options but I still can't see the MessageBox. Now the problem is when I run it from Visual C# (debug mode) it perfectly shows the box. but when I run the application directly from the debug/release folders it doesn't shows the MessageBox and the Application keeps running like there is no error is happening...
this example works for me in debug mode and release mode with vs2010 or not:
using System;
using System.Windows.Forms;
namespace WinFormsStackOverflowSpielWiese
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
private static void Main() {
System.Windows.Forms.Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
System.Windows.Forms.Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) {
try {
var exception = e.Exception != null ? e.Exception.Message + e.Exception.StackTrace : string.Empty;
MessageBox.Show("Whoops! Please contact the developers with the following information:\r\n\r\n" + exception,
"Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
finally {
Application.Exit();
}
}
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) {
try {
var exception = e.ExceptionObject is Exception ? ((Exception)e.ExceptionObject).Message + ((Exception)e.ExceptionObject).StackTrace : string.Empty;
MessageBox.Show("Whoops! Please contact the developers with the following information:\r\n\r\n" + exception,
"Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
finally {
Application.Exit();
}
}
}
}
code for the form
EDIT now with a timer, with the same result....
using System.Windows.Forms;
namespace WinFormsStackOverflowSpielWiese
{
public partial class Form1 : Form
{
private System.Threading.Timer myTimer;
public Form1() {
this.InitializeComponent();
this.myTimer = new System.Threading.Timer(state =>
{
var i = 0;
var s = 100 / i;
}
, null, 5000, 5000);
}
}
}
The case might be because Unhandled Exceptions cause the application to terminate silently and UnhandledExceptionEventHandler handles non-UI thread exceptions.
See Application.SetUnhandledExceptionMode Method, AppDomain.UnhandledException Event and Application.ThreadException Event
EDIT:
Try setting Application.SetUnhandledExceptionMode as per first link:
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); //add this line
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());

DispatcherTimer not firing in WPF Application

I am trying to understand why the DispatcherTimer contained within SingletonWithTimer is not firing in the following WPF application. I've been researching this for a couple of days and cannot seem to get to the bottom it. This application is the reduced essential parts of an existing application that I'm trying to fix. The Startup object of this project is WPFApplication5TimerTest.Program.
The output in the console lists as follows, the problem is evident because the word "TimerTick" is not shown in the output:
Timer is initialized
'WpfApplication5TimerTest.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework.Aero\v4.0_4.0.0.0__31bf3856ad364e35\PresentationFramework.Aero.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Sample thread
Sample thread
Sample thread
Sample thread
Sample thread
Sample thread
The thread '<No Name>' (0x10b0) has exited with code 0 (0x0).
Sample thread exiting!
This is Program.cs:
using System;
namespace WpfApplication5TimerTest
{
static class Program
{
[STAThread]
static void Main(string[] args)
{
AppObject = new App();
AppObject.Run();
}
public static App AppObject
{
get;
private set;
}
}
}
This is App.xaml.cs:
using System;
using System.Threading;
using System.Windows;
namespace WpfApplication5TimerTest
{
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
var sampleThread = new Thread(new ThreadStart(SampleThreadEntryPoint));
sampleThread.Start();
new MainWindow().Show();
}
private void SampleThreadEntryPoint()
{
SingletonWithTimer.Initialize();
while (!_shutdownEvent.WaitOne(1000))
Console.WriteLine("Sample thread");
Console.WriteLine("Sample thread exiting!");
}
protected override void OnExit(ExitEventArgs e)
{
_shutdownEvent.Set();
}
private ManualResetEvent _shutdownEvent = new ManualResetEvent(false);
}
}
This is MainWindow.xaml.cs:
using System;
using System.Windows;
namespace WpfApplication5TimerTest
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_Closed(object sender, EventArgs e)
{
Program.AppObject.Shutdown();
}
}
}
This is SingletonWithTimer.cs:
using System;
using System.Windows.Threading;
namespace WpfApplication5TimerTest
{
public class SingletonWithTimer
{
private static SingletonWithTimer Instance
{
get
{
if (_instance == null)
{
_instance = new SingletonWithTimer();
}
return _instance;
}
}
public static void Initialize()
{
SingletonWithTimer.Instance._timer = new DispatcherTimer();
SingletonWithTimer.Instance._timer.Interval = TimeSpan.FromSeconds(2);
SingletonWithTimer.Instance._timer.Tick += new EventHandler(SingletonWithTimer.Instance.OnTimerTick);
SingletonWithTimer.Instance._timer.Start();
Console.WriteLine("Timer is initialized");
}
private void OnTimerTick(object sender, EventArgs e)
{
Console.WriteLine("TimerTick");
}
private static SingletonWithTimer _instance;
private DispatcherTimer _timer = null;
}
}
It's because you've created the DispatcherTimer on another (non-UI) thread. Hence, it will be tied to the Dispatcher on that thread, not the one on the UI thread. Since nothing is running the Dispatcher on that thread, it will never fire.
Either create the DispatcherTimer on the UI thread, or use a constructor overload that allows you to pass in a specific Dispatcher to use.

Silverlight 4 RIA service issue

Hi I have created a sample database application in Silverlight by following a tutorial. I am trying to insert a record in DB but it throws an error Submit operation failed validation. Please inspect Entity.ValidationErrors for each entity in EntitiesInError for more information. I am using Entity framework for DAL. My code is given below. Exception occure when I insert a record. But Iam not sure at which stage exception occurs.
RecordInsertPage.cs file
public partial class BookRegistaeration : ChildWindow
{
public Book newBook { get; set; }
public BookRegistaeration()
{
InitializeComponent();
newBook = new Book();
AddBookForm.CurrentItem =AddBookForm;
AddBookForm.BeginEdit();
}
private void OKButton_Click(object sender, RoutedEventArgs e)
{
AddBookForm.CommitEdit();
this.DialogResult = true;
}
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
newBook = null;
AddBookForm.CancelEdit();
this.DialogResult = false;
}
}
Service.cs Page
public class OrganizationService : LinqToEntitiesDomainService<LibraryEntities1>
{
public IQueryable<Book> GetBooks()
{
return this.ObjectContext.Books.OrderBy(e => e.BookId);
}
public void InsertBook(Book book)
{
//book.Title = "Hello book";
//book.Author = "Ali";
//book.Category = "Humanity";
if ((book.EntityState != EntityState.Detached))
{
this.ObjectContext.ObjectStateManager.ChangeObjectState(book, EntityState.Added);
}
else
{
this.ObjectContext.Books.AddObject(book);
}
}
public void UpdateBook(Book currentBook)
{
this.ObjectContext.Books.AttachAsModified(currentBook, this.ChangeSet.GetOriginal(currentBook));
}
public void DeleteBook(Book book)
{
if ((book.EntityState != EntityState.Detached))
{
this.ObjectContext.ObjectStateManager.ChangeObjectState(book, EntityState.Deleted);
}
else
{
this.ObjectContext.Books.Attach(book);
this.ObjectContext.Books.DeleteObject(book);
}
}
}
private void LibraryDataSource_SubmittedChanges(object sender, SubmittedChangesEventArgs e)
{
if (e.HasError)
{
MessageBox.Show(string.Format("Changes were not saved: {0}", e.Error.Message));
e.MarkErrorAsHandled();
}
submitButton.IsEnabled = true;
}
void addBook_Closed(object sender, EventArgs e)
{
BookRegistaeration book = (BookRegistaeration)sender;
if (book.newBook != null)
{
OrganizationContext _OrganizationContext = (OrganizationContext)(LibraryDataSource.DomainContext);
_OrganizationContext.Books.Add(book.newBook);
LibraryDataSource.SubmitChanges();
}
}
Try doing as the exception message suggests, put a breakpoint on your SubmittedChanges event to inspect that exception object for which you should be able to see Entity.ValidationErrors for each entity in EntitiesInError.
This should tell you which of the fields in the object you are trying to add has failed the validation check, you may have null data in fields which cannot be null. You may find string properties are not allowed to be empty.
Try also to ensure your form is properly populating the object you will be adding, you could place a breakpoint before CommitEdit is called and inspect the object state.
i do not understand this line !
AddBookForm.CurrentItem =AddBookForm;
why did you write this?
it should be something like this
AddBookForm.CurrentItem = your class object !

Global handling exception in WPF app with Caliburn.Micro

Hi I try implement solution from this site im my WPF app for global exception handling.
http://www.codeproject.com/Articles/90866/Unhandled-Exception-Handler-For-WPF-Applications.aspx
I use Caliburn Micro as MVVM framework. Service I have in external assembly and it is injected in view model class with MEF.
Here is my implementation for global exception handling in WPF app.
App.xaml
DispatcherUnhandledException="Application_DispatcherUnhandledException"
Startup="Application_Startup"
App class:
public partial class App : Application
{
private IMessageBox _msgBox = new MessageBoxes.MessageBoxes();
public bool DoHandle { get; set; }
private void Application_Startup(object sender, StartupEventArgs e)
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
}
private void Application_DispatcherUnhandledException(object sender,
System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
if (DoHandle)
{
_msgBox.ShowException(e.Exception);
e.Handled = true;
}
else
{
_msgBox.ShowException(e.Exception);
e.Handled = false;
}
}
void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
var ex = e.ExceptionObject as Exception;
_msgBox.ShowException(ex);
}
}
Service method from external assembly:
public void ServiceLogOn()
{
try
{
}
catch (Exception ex)
{
throw ex;
}
}
This service method is call in view model class for example on button click event:
[Export(typeof(ILogOnViewModel))]
public class LogOnViewModel : Screen, ILogOnViewModel
{
public void LogOn()
{
_service.ServiceLogOn();
}
}
I run WPF app in Visual Studio and produce exception with message "Bad credentials" in ServiceLogOn method.
I expect that I see the message box with the exception.
But Visual Studio stop debuging app and show exception in service method in service project.
So I try run WPF from exe file and produce same exception in ServiceLogOn method.
I get this error:
Exception has been throw by target of an invocation.
Any exception from view model class is not handled in methods:
Application_DispatcherUnhandledException
or CurrentDomain_UnhandledException.
in App class.
What I do bad?
EDITED with Simon Fox’s answer.
I try implement in MEF bootstraper advice of Simon Fox’s, but I still something do wrong.
I move handle logic for exception to OnUnhandledException method in bootstraper class.
Here is my code from bootstraper class:
public class MefBootStrapper : Bootstrapper<IShellViewModel>
{
//...
private IMessageBox _msgBox = new MessageBoxes.MessageBoxes();
public bool DoHandle { get; set; }
protected override void OnUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
if (DoHandle)
{
_msgBox.ShowException(e.Exception);
e.Handled = true;
}
else
{
_msgBox.ShowException(e.Exception);
e.Handled = false;
}
}
//...
}
I bind some method from view model on button and throw new exception. Something like this:
public void LogOn()
{
throw new ArgumentException("Bad argument");
}
But result is sam, I test app out of Visual Studio and get this exception.
Exception has been throw by target of an invocation.
Caliburn.Micro has built in support for hooking unhandled exceptions. The Bootstrapper class (which every Caliburn project requires) sets this up for you and provides the virtual OnUnhandledException method.
In your custom BootStrapper you must override OnUnhandledException to perform any custom actions for unhandled exceptions in your app. Note that you will most likely have to marshal actions such as displaying a message box to the UI thread (Caliburn enables this easily via Execute.OnUIThread).
You may also have an issue in the way your service moves exceptions to the client, but without any details of how the service is implemented/hosted/etc I cannot help. Are you using WCF to do SOAP? Are you using FaultContracts?

Resources