Daniel15 / RouteJs

JavaScript URL routing for ASP.NET MVC and WebForms
84 stars 19 forks source link

Defaults and optional parameters are sometimes serialised as null #31

Closed stijnherreman closed 10 years ago

stijnherreman commented 10 years ago

I don't like the sometimes part of this bug. I can randomly reproduce it by setting and removing debug="true" to force it to regenerate. So far I've seen it multiple times in the minified version and one time on the regular version, so I don't think it's related to minification.

Most of the times this is generated:

window.Router = new RouteJs.RouteManager({
    "routes": [{
        "url": "",
        "defaults": {
            "language": "nl",
            "controller": "Dashboard",
            "action": "Index"
        },
        "constraints": {},
        "optional": []
    }, {
        "url": "logging/exceptions/{resource}/{subResource}",
        "defaults": {
            "controller": "Logging",
            "action": "Exceptions"
        },
        "constraints": {},
        "optional": ["resource", "subResource"]
    }, {
        "url": "{language}/{controller}/{action}/{id}",
        "defaults": {},
        "constraints": {},
        "optional": ["id"]
    }, {
        "url": "{language}/{controller}",
        "defaults": {},
        "constraints": {},
        "optional": []
    }],
    "baseUrl": "/"
});

Sometimes this is generated:

window.Router = new RouteJs.RouteManager({
    "routes": [{
        "url": "",
        "defaults": null,
        "constraints": {},
        "optional": null
    }, {
        "url": "logging/exceptions/{resource}/{subResource}",
        "defaults": null,
        "constraints": {},
        "optional": null
    }, {
        "url": "{language}/{controller}/{action}/{id}",
        "defaults": null,
        "constraints": {},
        "optional": null
    }, {
        "url": "{language}/{controller}",
        "defaults": null,
        "constraints": {},
        "optional": null
    }],
    "baseUrl": "/"
});

Any idea what could cause this?

Daniel15 commented 10 years ago

Hm that's really weird. Do you see any errors at all when this occurs?

stijnherreman commented 10 years ago

No errors at all. I'll probably have some time this week to build from source and see if I can find more info.

yuji1982 commented 10 years ago

I have identified what is causing this problem.

This problem is reproducible when you restart IIS and access routejs.axd before accessing an MVC application.

Since you haven't loaded RouteJS.Mvc.dll at this point in routejs.axd, IDefaultsProcessor is not registered in ComponentRegistration, and routeInfo.Defaults and other settings are blank.

I'm sorry but I haven't figured out what is the appropriate solution for this problem, so this is only a report of the cause.

As a temporary measure, I'm accessing the Type of RouteJS.Mvc.dll in Application_Start to load the DLL.

Daniel15 commented 10 years ago

Nice find, thanks for reporting. I've got some ideas, I'll work on a fix soon.

Sent from my mobile. On Apr 3, 2014 3:24 AM, "yuji1982" notifications@github.com wrote:

I have identified what is causing this problem.

This problem is reproducible when you restart IIS and access routejs.axd before accessing an MVC application.

Since you haven't loaded RouteJS.Mvc.dll at this point in routejs.axd, IDefaultsProcessor is not registered in ComponentRegistration, and routeInfo.Defaults and other settings are blank.

I'm sorry but I haven't figured out what is the appropriate solution for this problem, so this is only a report of the cause.

As a temporary measure, I'm accessing the Type of RouteJS.Mvc.dll in Application_Start to load the DLL.

Reply to this email directly or view it on GitHubhttps://github.com/Daniel15/RouteJs/issues/31#issuecomment-39435777 .

Daniel15 commented 10 years ago

This should be fixed in 1.1.6 as I've switched to using WebActivator for initialising the IoC container. Thanks for reporting!

mbiasetti commented 10 years ago

Hi, just wanted to let you know that this was happening to me as well on 1.1.4. It also occurred if I left my PC for a while and came back and just refreshed the page. I'm going to install 1.1.7 now and see if it continues to occur.

Daniel15 commented 10 years ago

Thanks, let me know if you still see the issue.