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

Not specifying output header file (-h) casues ArgumentException #78

Closed
FiniteReality opened this issue Aug 8, 2019 · 0 comments

Comments

@FiniteReality
Copy link
Contributor

commented Aug 8, 2019

In PInvokeGeneratorConfiguration, headerFile seems to be null-checked and passed to File.ReadAllText:

HeaderText = headerFile is object ? File.ReadAllText(headerFile) : string.Empty;

However, the headerFile option defaults to string.Empty, meaning this check always succeeds:

private static void AddHeaderOption(RootCommand rootCommand)
{
var argument = new Argument
{
ArgumentType = typeof(string),
Arity = ArgumentArity.ExactlyOne,
Name = "file"
};
argument.SetDefaultValue(string.Empty);

This causes the following exception if the parameter is not specified, when running the program:

System.ArgumentException: Empty path name is not legal.
Parameter name: path
   at System.IO.File.ReadAllText(String path)
   at ClangSharp.PInvokeGeneratorConfiguration..ctor(String libraryPath, String namespaceName, String outputLocation, PInvokeGeneratorConfigurationOptions options, String[] excludedNames, String headerFile, String methodClassName, String methodPrefixToStrip, IReadOnlyDictionary`2 remappedNames, String[] traversalNames) in /home/dev/Development/ClangSharp/sources/ClangSharp.PInvokeGenerator/PInvokeGeneratorConfiguration.cs:line 54
   at ClangSharp.Program.Run(InvocationContext context) in /home/dev/Development/ClangSharp/sources/ClangSharpPInvokeGenerator/Program.cs:line 173

FiniteReality added a commit to FiniteReality/ClangSharp that referenced this issue Aug 8, 2019

Always write headers and check against empty paths
This fixes microsoft#78 and fixes microsoft#79. Header files are written whenever a valid
header file is passed, and null/empty paths are now ignored.

tannergooding added a commit that referenced this issue Aug 10, 2019

Always write headers and check against empty paths (#80)
* Always write headers and check against empty paths

This fixes #78 and fixes #79. Header files are written whenever a valid
header file is passed, and null/empty paths are now ignored.

* Skip generating the header in the method class

It was already written earlier, so it is unnecessary.

* Make suggested changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.