LinqPadless icon indicating copy to clipboard operation
LinqPadless copied to clipboard

LINQPad program queries with args don't compile

Open atifaziz opened this issue 7 years ago • 5 comments

Suppose the following LINQPad program query:

<Query Kind="Program">
</Query>

void Main(string[] args)
{
}

// Define other methods and classes here

When run through lpless, the compiled program fails to build due to the following error:

error CS0111: Type 'UserQuery' already defines a member called 'Main' with the same parameter types

atifaziz avatar Mar 28 '18 17:03 atifaziz

Thank you for this helpful program. Given some assumptions, I was able to workaround this issue for my needs. Starting from line 567 in Program.cs, I commented out the following lines:

"class UserQuery {",
//"    static int Main(string[] args) {",
//"        new UserQuery().Main()" + (IsMainAsync(source) ? ".Wait()" : null) + "; return 0;",
//"    }",
    source,
"}")

Now, the original Main() is not wrapped. This does not account for an async Main. When I declare Main() in the linq script, I make it return an int and give it the standard (string[] args) parameter set. Given the limitations introduced by commenting out the above lines, I can now use lpless to compile a linq script, and the target EXE will accept arguments.

fresh2dev avatar Dec 13 '18 18:12 fresh2dev

@dm3ll3n Thanks for dropping a note with a workaround that worked for you. I'm sure it'll help others encountering the same bug.

atifaziz avatar Dec 13 '18 22:12 atifaziz

This feels like a pretty big limitation. Is there a plan to fix this? Would you accept a PR?

madelson avatar Mar 23 '19 13:03 madelson

Is there a plan to fix this?

It's been fixed in the branch that will become version 2.

Would you accept a PR?

If you need this fixed more immediately for v1 then I'd be happy to accept a PR and make a release.

atifaziz avatar Mar 23 '19 16:03 atifaziz

Is there a plan to fix this?

It's been fixed in the branch that will become version 2.

You can see here that all signatures of Main, of which there are quite a few when you line them all up, are supported:

https://github.com/linqpadless/LinqPadless/blob/97f373fe96e769be1fda7359e531a52ce49aa815/src/Program.cs#L778-L799

atifaziz avatar Mar 23 '19 16:03 atifaziz