adamralph / scriptcs-nancy

Nancy Script Pack for scriptcs
MIT License
35 stars 5 forks source link

Not seeing Response extensions #113

Closed jchannon closed 9 years ago

jchannon commented 9 years ago

I am unable to use pack.Get("/redirect", _ => Response.AsRedirect("http://google.com")); as it errors with error CS0117:Nancy.Response' does not contain a definition for AsRedirect'

adamralph commented 9 years ago

missing using statement?

jchannon commented 9 years ago

Nope, thats under the Nancy namespace

adamralph commented 9 years ago

OK, something weird going on there. We may have an oddity in how the usings work with script packs.

adamralph commented 9 years ago

I see the problem. In the code above, Response is a reference to the static class Response. When you write that same code in a module, Response is a reference to the instance property NancyModule.Response.

The ambiguity of not enforcing this. strikes again (/cc @damianh :wink:).

adamralph commented 9 years ago

Try this instead:

pack.Module(m => m.Get["/redirect"] = _ => m.Response.AsRedirect("http://google.com"));
adamralph commented 9 years ago

See https://github.com/adamralph/scriptcs-nancy#in-line-routes

jchannon commented 9 years ago

I get `ERROR: Script execution failed: (1,14):

.m__0(ScriptCs.Nancy.DefaultModule).` On 24 March 2015 at 11:34, Adam Ralph notifications@github.com wrote: > See https://github.com/adamralph/scriptcs-nancy#in-line-routes > > ## > > Reply to this email directly or view it on GitHub > https://github.com/adamralph/scriptcs-nancy/issues/113#issuecomment-85458111 > .
adamralph commented 9 years ago

Works for me. Is this mono?

jchannon commented 9 years ago

Yup! Happy days :)

On 24 March 2015 at 11:38, Adam Ralph notifications@github.com wrote:

Works for me. Is this mono?

Reply to this email directly or view it on GitHub https://github.com/adamralph/scriptcs-nancy/issues/113#issuecomment-85459135 .

adamralph commented 9 years ago

Works for me under mono. But on Windows.

adamralph commented 9 years ago

Actually no it doesn't. I have exactly the same error.

jchannon commented 9 years ago

adamralph commented 9 years ago

The mono engine is blowing up on the nested lambda. You can work around it like this

Action<NancyModule> addRoute = m =>
    m.Get["/redirect"] = _ => m.Response.AsRedirect("http://google.com");
pack.Module(m => addRoute(m));

In all honesty, there's little appetite fix things like this in the mono engine at the moment, given that the focus is now to move to the new x-plat Roslyn (https://github.com/scriptcs/scriptcs-engines) so we can dump the Mono engine.

jchannon commented 9 years ago

Fair enough.

This also errors for me but not sure why?

pack.Get("/test", _ => new {Key = "bob"});

If I put this in my script and new it up that its fine so I assume maybe its the scriptcs mono engine not liking anonymous types

public class MyTest
{
    public string Key {get;set;}
}
adamralph commented 9 years ago

:ok_hand: your diagnosis is spot on. It doesn't like anonymous types and they don't like it.

It only has a small circle of friends.

jchannon commented 9 years ago

So how far is the scriptcs roslyn stuff in terms of readiness (if that makes any sense at all)?

On 24 March 2015 at 15:15, Adam Ralph notifications@github.com wrote:

[image: :ok_hand:] your diagnosis is spot on. It doesn't like anonymous types and they don't like it.

It only has a small circle of friends.

Reply to this email directly or view it on GitHub https://github.com/adamralph/scriptcs-nancy/issues/113#issuecomment-85546754 .

adamralph commented 9 years ago

It's close. We're working with @dotnet to close the gaps. You can try it out yourself now, but we don't have it on NuGet yet.

@filipw do you mind chiming in and giving @jchannon instructions for how to try out the new C# engine?

adamralph commented 9 years ago

image

adamralph commented 9 years ago

Good luck with the mono compiler... :stuck_out_tongue_winking_eye:

jchannon commented 9 years ago

WTF, even MS is X-Plat these days, you guys are so enterprise!

filipw commented 9 years ago

Roslyn is not x-plat

adamralph commented 9 years ago

Our code is x-plat. But our upstream dep (built by MS) is not..

jchannon commented 9 years ago

Bloody MS :smile:

adamralph commented 9 years ago

@jchannon I guess I can close this since there's nothing that can be done in the script pack?

You could raise an issue for the mono engine deficiencies over at https://github.com/scriptcs/scriptcs but as I say, it's doubtful they'll get fixed.