Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Private static variables cause meaningless exception on mono #1073

Closed
tobiaszuercher opened this issue Jul 31, 2015 · 8 comments
Closed

Private static variables cause meaningless exception on mono #1073

tobiaszuercher opened this issue Jul 31, 2015 · 8 comments

Comments

@tobiaszuercher
Copy link

The following script:

using Octopus.Client;

private static string regexString = @"[\d\.]+[^-]+\.(?<number>\d+)-{0}";
private static string regexStringWithoutBranch = @"[\d\.]+[^-]+\.(?<number>\d+)$";

var octopusUrl = "https://demo.octopusdeploy.com";
var octopusApi = "api-key";

System.Net.ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, error) => true;

var endpoint = new OctopusServerEndpoint(octopusUrl, octopusApi);
var repository = new OctopusRepository(endpoint);

var releases = repository.Releases.FindAll().ToList();

foreach (var release in releases)
{
    Console.WriteLine(release.Version);
}

The scripts needs scriptcs -install Octopus.Client
Works perfectly on windows. On ubuntu with mono, i get the following error:

tobi@tobuntu-v:~/Desktop/scriptcs$ scriptcs issue.csx 
ERROR: Script execution failed: Argument is out of range.
Parameter name: index.

How can i get more info about the error? The -debug flag doesn't give me enough information to fix the issue.

Is it possible that this is a mono issue?

@adamralph
Copy link
Contributor

@tobiaszuercher it may well be a mono issue.

In the forthcoming 0.15 release (hopefully just days away) the full stack trace will be printed to the console when an error occurs (see #987).

In the meantime, you could try running your script using the nightly build https://www.myget.org/gallery/scriptcsnightly

@ztone
Copy link
Contributor

ztone commented Jul 31, 2015

Hi @tobiaszuercher.

This is a quirk, a small difference between the mono and the roslyn engine. Mono doesn't like their toplevel variables to have access modifiers nor being static ... probably because they make little sense in this context.

So this should work in mono

string regexString = @"[\d\.]+[^-]+\.(?<number>\d+)-{0}";
string regexStringWithoutBranch = @"[\d\.]+[^-]+\.(?<number>\d+)$";

We will probably not fix this as this is a mono issue, not scriptcs.
Hope this helps!

FYI @adamralph

p.s yeah, the error message you got sucked ... we're working on it

@adamralph
Copy link
Contributor

@ztone thanks for the info! I think even with the stack trace we would have had a hard time figuring that out 😄

btw

We will probably not fix this as this is a mono issue, not scriptcs.

I guess you mean

We will probably not fix this as this is a mono issue, not scriptcs.

@adamralph adamralph changed the title Script execution failed on mono Private static variables cause meaningless exception on mono Aug 1, 2015
@adamralph adamralph added the mono label Aug 1, 2015
@ztone
Copy link
Contributor

ztone commented Aug 1, 2015

Hi @adamralph

What I meant is that this "bug" (if it is a bug, might be by design) is in Mono.CSharp and therefore not maintained by us. Even if I would issue a PR to the mono project that fixes this I'm not sure that it will be accepted because why does a toplevel variable need to be private?

However what we might be able to do here, just to make our roslyn and mono engine a bit more compatible, is to use our pre-parser and remove any keywords from toplevel variables before passing it to the Mono.CSharp evaluator.

@adamralph adamralph removed the mono bug label Aug 2, 2015
@adamralph
Copy link
Contributor

@ztone ok, makes sense.

The whole top-level variable thing is weird. In Roslyn, these actually end up (counter-intuitively) as being fields in a class. A design I've challenged, but it seems to be sticking. I guess we could do what you suggest and strip away the access and static modifiers in pre-parsing.

@tobiaszuercher
Copy link
Author

wow, thank you all for the comments!

i just copied & pasted code from a console exe. and yes, the private static doesn't really make sense there! still happy to see more output if something goes wrong (even in that case a stacktrace wouldn't be that helpful).

looking forward to 0.15! thank you guys <3

@filipw
Copy link
Member

filipw commented Apr 6, 2017

fixed by #1216

@tobiaszuercher
Copy link
Author

thank you guys for all your effort!

@filipw filipw modified the milestone: v1.0 Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants