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

Lucene.Net.Util.SystemConsole throws not supported exception in .NET MAUI app running on android/iOS #936

Open
1 task done
JayOfemi opened this issue May 1, 2024 · 0 comments
Labels

Comments

@JayOfemi
Copy link

JayOfemi commented May 1, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I am simply trying to create a StandardQueryParser. I get the below exception only on Android and iOS. This makes sense as System.Console.In is not supported on these platforms, but I have no need for it in the context of our application. So, I think a way to ignore this would be very useful to prevent our app from crashing on these platforms.

Note that I am testing on Android and iOS in Android Studio and XCode respectively, not on physical devices. Though, I don't think this will make a difference.

It seems the issue is the way these properties are setup in Lucene.Net.Util.SystemConsole.

public static TextWriter Out { get; set; } = Console.Out;
public static TextWriter Error { get; set; } = Console.Error;
public static TextReader In { get; set; } = Console.In;

My application would work fine to simply return null here when Console.In is not supported.

I can't seem to find anything online about this regarding Lucene, so I think it is just specific to Lucene.NET and .NET MAUI. In any case, I believe it can possibly be addressed simply by doing the above.

From what I can tell, SystemConsole is only used in StandardSyntaxParserTokenManager to create the private debugStream property, which is then never used in this class. I believe this whole thing is the same when using the default QueryParser as well.

Expected Behavior

Perhaps instead of defaulting to Console.In, the property can be set in a way that if a non-supported or any other exceptions that can be ignored is caught, this property returns null or a bogus TextReader by default.

Steps To Reproduce

  • In a .NET MAUI sample app, create a Lucene.Net.QueryParsers.Flexible.Standard.StandardQueryParser using the constructor.
    • Specifically we created our MAUI app using the default template in Rider.
  • Run the app.
    on Windows and macOS, this will run fine. On Android and iOS, the app will crash with a System.PlatformNotSupportedException when it attempts to construct the StandardQueryParser.

Exceptions (if any)

Exception: System.TypeInitializationException: The type initializer for 'Lucene.Net.Util.SystemConsole' threw an exception.
 ---> System.PlatformNotSupportedException: Operation is not supported on this platform.
   at System.ConsolePal.GetOrCreateReader()
   at System.Console.<get_In>g__EnsureInitialized|14_0()
   at System.Console.get_In()
2024-04-29 15:55:32.051142-0700  at Lucene.Net.Util.SystemConsole..cctor()
   --- End of inner exception stack trace ---
   at Lucene.Net.QueryParsers.Flexible.Standard.Parser.StandardSyntaxParserTokenManager..ctor(ICharStream stream)
2024-04-29 15:55:32.051200-0700  at Lucene.Net.QueryParsers.Flexible.Standard.Parser.StandardSyntaxParser..ctor(ICharStream stream)
   at Lucene.Net.QueryParsers.Flexible.Standard.Parser.StandardSyntaxParser..ctor()
   at Lucene.Net.QueryParsers.Flexible.Standard.StandardQueryParser..ctor()
2024-04-29 15:55:32.051439-0700 at Lucene.Net.QueryParsers.Flexible.Standard.StandardQueryParser..ctor(Analyzer analyzer)

Lucene.NET Version

4.8

.NET Version

8.0.203

Operating System

Windows 11

Anything else?

No response

@JayOfemi JayOfemi added the is:bug label May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant