Error 500

Topics: Troubleshooting
Oct 29, 2012 at 10:29 AM

I have created my own module, when I tested locally is working, when I packaged and install it on my pro server, I can browse the page /Subscribe (my module) but when I submit the form I am getting an error 500. I have checked the IIS logs and there is nothing related to this error, no stack trace. Can you please tell me how I can properly debug and resolve this issue?

Your feedback is highly appreciated.

Oct 29, 2012 at 4:49 PM
Edited Oct 29, 2012 at 4:54 PM

I uninstall my module, delete record from migrations table and my module table, re-installed again the module. Now on submit I can see the success page but in Logs I am getting that my object is not initialized.

So how its possible when running my module locally on my pc its working fine and submitted data are saved into the db but in production I am getting the below error message???

2012-10-29 17:22:47,230 [80] UserSubmissions.Controllers.UserSubmissionController - Failed to create a new subscriber!System.NullReferenceException: Object reference not set to an instance of an object.   at UserSubmissions.Controllers.UserSubmissionController.CreateSubmission(UserSubmissionViewModel model) in c:\inetpub\wwwroot\orchard\Modules\uSubmit\Controllers\UserSubmissionController.cs:line 153

Note: Line: 153 is submission.As<UserSubmissionPart>().SubmittedBy = model.SubmittedBy; so I assume that Model UserSubmissionPart is not initialized, how can I initialized that object?


public class UserSubmissionController : Controller {
        private readonly IContentManager _contentManager;
        private readonly IRepository _repository;
        private string _code;
        private string _systemId;

        public UserSubmissionController(IOrchardServices services, IContentManager contentManager, IShapeFactory shapeFactory, IRepository repository){
            _contentManager = contentManager;
            Services = services;
            Shape = shapeFactory;
            T = NullLocalizer.Instance;
            Logger = NullLogger.Instance;
            _repository = repository;
            _code = "";
            _systemId = "";

        public ILogger Logger { get; set; }
        private IOrchardServices Services { get; set; }
        public Localizer T { get; set; }
        public dynamic Shape { get; set; }

 	private bool CreateSubmission(UserSubmissionViewModel model) {                   
                _systemId = Guid.NewGuid().ToString();
                _code = _systemId.Substring(0, 30);                
                var submission = _contentManager.Create("UserSubmission", VersionOptions.Draft);
                submission.As<UserSubmissionPart>().SubmittedBy = model.SubmittedBy;
                submission.As<UserSubmissionPart>().SubmittedByEmail = model.SubmittedByEmail;
                submission.As<UserSubmissionPart>().Subscribed = 1;
                submission.As<UserSubmissionPart>().ToBeProcessed = 0;
                submission.As<UserSubmissionPart>().Code = _code;
                submission.As<UserSubmissionPart>().SystemId = _systemId;
                Logger.Information("Subscriber created with ID {0}", submission.Id);    
                return (submission != null);
            catch (Exception e)
                Logger.Error(e, "Failed to create a new subscriber!");          
            return false;
Oct 29, 2012 at 6:15 PM

The place to look for logs is not IIS logs, but app_data\logs.

If it works on your machine but not in prod, you may have a bug in your migration.

Oct 30, 2012 at 7:19 AM

Please see my last comment, were I have specified the error that I found in app_data\logs. Also I checked the database and my module table is created and a record in [Orchard_Framework_DataMigrationRecord] of version 1 as well, so it doesn't seems to be a migration unless there is something else that I need to check?

Oct 30, 2012 at 10:57 AM
Edited Oct 30, 2012 at 11:29 AM

Based on the below error message I assume that my module is not connected to database. Any ideas how to resolve this would be very helpful, as I have test it in my pc and its working fine but not on the pro server. 

2012-10-30 11:51:40,286 [22] UserSubmissions.Controllers.UserSubmissionController - Failed to create a new subscriber! By Name: andreas Email:
System.NullReferenceException: Object reference not set to an instance of an object.
   at UserSubmissions.Controllers.UserSubmissionController.CreateSubmission(UserSubmissionViewModel model) in c:\inetpub\wwwroot\orchard\Modules\uSubmit\Controllers\UserSubmissionController.cs:line 160

File: UserSubmissions.Controllers.UserSubmissionController.CreateSubmission(UserSubmissionViewModel model)
Line: 160
submission.As<UserSubmissionPart>().SubmittedBy = model.SubmittedBy;

Oct 30, 2012 at 5:27 PM

Hi bertrandleroy, can you please tell me how can I resolve this issue or even send to your email address my module for quick look if possible?

Oct 30, 2012 at 6:59 PM

Set a breakpoint in there. Is it submission or the result of the As that is null?

Oct 31, 2012 at 5:46 AM
Edited Oct 31, 2012 at 5:48 AM

I have set a breakpoint and I get the below exception:

StackTrace "   at UserSubmissions.Controllers.UserSubmissionController.CreateSubmission(UserSubmissionViewModel model) in f:\\inetpub\\orchard\\src\\Orchard.Web\\Modules\\uSubmit\\Controllers\\UserSubmissionController.cs:line 160" string

Line: 159 | var submission = _contentManager.Create("UserSubmission", VersionOptions.Draft);

Line: 160 | submission.As<UserSubmissionPart>().SubmittedBy = model.SubmittedBy;

Note: Table [uSubmit_UserSubmissionPartRecord] is created and record in [Orchard_Framework_DataMigrationRecord] is added

Below is a snapshot of the breakpoint set at var submission

see image

namespace UserSubmissions.Models {
    public class UserSubmissionPart : ContentPart<UserSubmissionPartRecord> {
        public string SubmittedBy {
            get { return Record.SubmittedBy; }
            set { Record.SubmittedBy = value; }
        public string SubmittedByEmail {
            get { return Record.SubmittedByEmail; }
            set { Record.SubmittedByEmail = value; }

        public int Subscribed
            get { return Record.Subscribed; }
            set { Record.Subscribed = value; }

        public int ToBeProcessed
            get { return Record.ToBeProcessed; }
            set { Record.ToBeProcessed = value; }

        public string Code
            get { return Record.Code; }
            set { Record.Code = value; }

        public string SystemId
            get { return Record.SystemId; }
            set { Record.SystemId = value; }

namespace UserSubmissions {
    public class Migrations : DataMigrationImpl {

        public int Create() {
            SchemaBuilder.CreateTable("UserSubmissionPartRecord", builder => builder
                .Column<string>("SubmittedBy", col => col.WithLength(100))
                .Column<string>("SubmittedByEmail", col => col.WithLength(100))
                .Column<int>("Subscribed", col => col.WithLength(1))
                .Column<int>("ToBeProcessed", col => col.WithLength(1))
                .Column<string>("Code", col => col.WithLength(50))
                .Column<string>("SystemId", col => col.WithLength(50))

            return 1;
Oct 31, 2012 at 6:48 PM

Where is your UserSubmission content type created? Seems like your content definition has no parts at all.

Nov 2, 2012 at 7:07 AM

When you area saying "UserSubmission content type" are you referring to the below class? Also I have attached Driver and Handler class below.

namespace UserSubmissions.Models {
    public class UserSubmissionPartRecord : ContentPartRecord {

        [DisplayName("Your Name")]        
        public virtual string SubmittedBy { get; set; }

        [DisplayName("Your Email")]
        public virtual string SubmittedByEmail { get; set; }

        public virtual int Subscribed { get; set; }

        public virtual int ToBeProcessed { get; set; }

        public virtual string Code { get; set; }

        public virtual string SystemId { get; set; }
namespace UserSubmissions.Drivers {
    public class UserSubmissionPartDriver : ContentPartDriver {
        private readonly IOrchardServices _services;

        public UserSubmissionPartDriver(IOrchardServices services) {
            _services = services;
            T = NullLocalizer.Instance;

        public Localizer T { get; set; }

namespace UserSubmissions.Handlers {
    public class UserSubmissionPartHandler : ContentHandler {

        public UserSubmissionPartHandler(IRepository repository) {

Nov 3, 2012 at 5:27 AM

No. In your code, you have this line:  _contentManager.Create("UserSubmission", VersionOptions.Draft);

"UserSubmission" is supposed to be a content type name. You must have defined it somewhere, presumably in your migration. If you haven't, well, that's the problem.

Nov 3, 2012 at 12:45 PM
Edited Nov 3, 2012 at 12:47 PM

Thank you, I find out that the below was missing. :) keep up the good work

public int UpdateFrom2()
	ContentDefinitionManager.AlterTypeDefinition("UserSubmission", builder => builder
		.DisplayedAs("User Submission")

	return 3;