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

Fix Dependency Injection Issue #3275

Closed

Conversation

Jack251970
Copy link
Contributor

@Jack251970 Jack251970 commented Feb 25, 2025

@Jack251970 Jack251970 requested a review from taooceros February 25, 2025 03:50
@prlabeler prlabeler bot added the bug Something isn't working label Feb 25, 2025

This comment has been minimized.

Copy link

gitstream-cm bot commented Feb 25, 2025

Be a legend 🏆 by adding a before and after screenshot of the changes you made, especially if they are around UI/UX.

Copy link
Contributor

coderabbitai bot commented Feb 25, 2025

📝 Walkthrough

Walkthrough

The pull request introduces enhanced error handling in the App constructor and the OnStartupAsync method, wrapping the initialization of settings, dependency injection, and the public API in try-catch blocks. It modifies the PublicAPIInstance class by removing the MainViewModel parameter from its constructor and adding an Initialize method to set the MainViewModel after construction. Additionally, it updates namespaces and package references, ensuring a more organized structure and removing unnecessary dependencies.

Changes

File(s) Change Summary
Flow.Launcher/App.xaml.cs
Flow.Launcher/PublicAPIInstance.cs
- Added error handling in App.xaml.cs for settings loading and dependency injection initialization.
- Updated PublicAPIInstance constructor to remove MainViewModel parameter and added Initialize(MainViewModel) method for deferred assignment of the MainViewModel.
Flow.Launcher/Flow.Launcher.csproj - Removed package reference for TaskScheduler version 2.11.0.
- Added package reference for TaskScheduler version 2.11.0 in Flow.Launcher.Infrastructure.csproj.
Flow.Launcher.Infrastructure/AutoStartup.cs - Updated namespace from Flow.Launcher.Helper to Flow.Launcher.Infrastructure and clarified exception handling.
- Specified System.Exception in catch blocks.
Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs - Updated namespace import from Flow.Launcher.Helper to Flow.Launcher.Infrastructure.

Possibly related PRs

  • Support Logon Task for Faster Startup Experience #3218: The changes in the main PR, which enhance error handling in the App class and the initialization of the PublicAPIInstance, are related to the modifications in the retrieved PR that involve the AutoStartup method in the App class, as both PRs affect the startup behavior and initialization logic of the application.

Suggested labels

enhancement

Suggested reviewers

  • jjw24
  • taooceros

Poem

I'm a rabbit with hops so keen,
Coding changes in a vibrant scene.
MainViewModel finds its rightful place,
With API now set with grace.
Hoppin' forward, our code's in bloom 🥕!

Happy coding, from my burrow to your room!

Tip

CodeRabbit's docstrings feature is now available as part of our Pro Plan! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d48b4df and 1434257.

📒 Files selected for processing (5)
  • Flow.Launcher.Infrastructure/AutoStartup.cs (7 hunks)
  • Flow.Launcher.Infrastructure/Flow.Launcher.Infrastructure.csproj (2 hunks)
  • Flow.Launcher/App.xaml.cs (3 hunks)
  • Flow.Launcher/Flow.Launcher.csproj (0 hunks)
  • Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs (1 hunks)
💤 Files with no reviewable changes (1)
  • Flow.Launcher/Flow.Launcher.csproj
✅ Files skipped from review due to trivial changes (2)
  • Flow.Launcher.Infrastructure/AutoStartup.cs
  • Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs
🔇 Additional comments (7)
Flow.Launcher.Infrastructure/Flow.Launcher.Infrastructure.csproj (1)

71-71: Dependency relocation for TaskScheduler package

The TaskScheduler package has been moved from Flow.Launcher.csproj to Infrastructure.csproj. This change properly aligns the dependency with its usage, which helps with the dependency injection issue mentioned in the PR description.

Flow.Launcher/App.xaml.cs (6)

38-49: Improved error handling for settings initialization

Good addition of error handling for the settings initialization process. Showing an error message to the user will help diagnose startup issues.


52-74: Enhanced error handling for DI container configuration

Adding error handling around the DI container configuration is a good improvement, as this was previously unprotected against exceptions.


77-86: Added error handling for API and settings initialization

This error handling completes the protection of the entire initialization process, ensuring users get meaningful error messages for any startup failures.


89-96: Implementation of FailFast mechanism after showing error

The ShowErrorMsgBoxAndFailFast method properly terminates the application using Environment.FailFast after showing the error message, which ensures the application doesn't continue in an inconsistent state.

This implementation addresses the previous review comment about ensuring graceful shutdown after errors in the initialization stage.


138-138: Fixed dependency injection issue with MainViewModel

This change is the core fix for the issue described in the PR. By moving the MainViewModel assignment from the constructor to an Initialize method, it prevents the dispatcher thread issue mentioned in the PR description.

This approach correctly separates the construction of the API instance from its initialization with UI-dependent components, which aligns with best practices for dependency injection.


168-179: Improved AutoStartup code readability

The autostart code is now better structured with explicit method calls to either enable via logon task or registry.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
Flow.Launcher/App.xaml.cs (1)

105-105: Good addition to fix the dispatcher thread issue.

This change correctly initializes the PublicAPIInstance with the MainViewModel after it's fully constructed, which resolves the dispatcher thread issue mentioned in the PR objectives.

However, the explicit cast to PublicAPIInstance bypasses the abstraction provided by the IPublicAPI interface. Consider extending the IPublicAPI interface to include the Initialize method for better design.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 022cad0 and c11d78c.

📒 Files selected for processing (2)
  • Flow.Launcher/App.xaml.cs (1 hunks)
  • Flow.Launcher/PublicAPIInstance.cs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
🔇 Additional comments (2)
Flow.Launcher/PublicAPIInstance.cs (2)

37-37: Field properly changed to support later initialization.

Changing from a readonly field to a regular field allows setting the MainViewModel after construction, which helps address the dispatcher thread issue.


41-46: Constructor simplified to remove MainViewModel dependency.

Removing the MainViewModel parameter from the constructor is the right approach to fix the dispatcher thread issue, as it allows the MainViewModel to be fully initialized before being assigned to the PublicAPIInstance.

@Jack251970 Jack251970 enabled auto-merge February 25, 2025 04:29
@Jack251970 Jack251970 requested a review from jjw24 February 25, 2025 09:21

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
Flow.Launcher/App.xaml.cs (3)

38-48: Good addition of error handling for settings initialization.

The addition of try-catch to handle exceptions during settings initialization improves robustness. Consider adding more specific error handling strategies based on exception types, and possibly logging the exception before displaying the message box for better diagnostics.

try
{
    var storage = new FlowLauncherJsonStorage<Settings>();
    _settings = storage.Load();
    _settings.SetStorage(storage);
    _settings.WMPInstalled = WindowsMediaPlayerHelper.IsWindowsMediaPlayerInstalled();
}
catch (Exception e)
{
+   Log.Error($"|App.ctor|Cannot load setting storage", e);
    MessageBox.Show($"Cannot load setting storage: {e}");
+   // Consider handling critical failures more gracefully
+   // e.g., attempting to load default settings or terminating the application
}

51-72: Enhanced error handling for dependency injection.

The try-catch block is a good addition to improve error handling. However, if DI configuration fails, the application is likely to encounter other issues. Consider defining a strategy for critical failures.

try
{
    // DI configuration
}
catch (Exception e)
{
+   Log.Error($"|App.ctor|Cannot configure dependency injection container", e);
    MessageBox.Show($"Cannot configure dependency injection container: {e}");
+   // Consider whether to continue or terminate the application after serious DI errors
+   // Environment.Exit(1);
}

75-83: Improved error handling for API initialization.

Adding error handling for API and settings initialization is important. Like the previous blocks, consider adding logging and a strategy for recovering or gracefully terminating.

try
{
    API = Ioc.Default.GetRequiredService<IPublicAPI>();
    _settings.Initialize();
}
catch (Exception e)
{
+   Log.Error($"|App.ctor|Cannot initialize public API and settings", e);
    MessageBox.Show($"Cannot initialize public API and settings: {e}");
+   // Consider a recovery strategy or graceful termination
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 18290b8 and d8b07f6.

📒 Files selected for processing (1)
  • Flow.Launcher/App.xaml.cs (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: gitStream.cm
🔇 Additional comments (1)
Flow.Launcher/App.xaml.cs (1)

126-126:

✅ Verification successful

Good fix for the dispatcher thread issue.

This change addresses the PR objective by deferring the initialization of MainViewModel in the PublicAPIInstance. This approach properly separates object construction from initialization, which is important for resolving dispatcher thread issues.

To ensure this is the best approach, please verify:


🏁 Script executed:

#!/bin/bash
# Check if PublicAPIInstance.cs has been updated to support this initialization pattern
rg -A 10 "class PublicAPIInstance" | grep -A 10 "Initialize"

# Look for other potential dispatcher thread issues with MainViewModel
rg "MainViewModel" --context=5

Length of output: 18907


Dispatcher Thread Fix Verified

The update in PublicAPIInstance.cs that introduces the Initialize(MainViewModel mainVM) method has been verified. The method correctly defers the initialization of the MainViewModel, ensuring that object construction and initialization are separated to avoid dispatcher thread issues. Additionally, a review of references to MainViewModel across the codebase did not reveal any further dispatcher-related concerns.

  • Confirmed that PublicAPIInstance.cs now contains a dedicated Initialize(MainViewModel mainVM) method.
  • Verified that App.xaml.cs properly retrieves the MainViewModel instance and initializes the PublicAPI accordingly.
  • No additional dispatcher thread issues were detected throughout the code.

This comment has been minimized.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d8b07f6 and 92df021.

📒 Files selected for processing (1)
  • Flow.Launcher/App.xaml.cs (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: gitStream.cm
🔇 Additional comments (5)
Flow.Launcher/App.xaml.cs (5)

38-49: Improved error handling for settings initialization.

Adding error handling around settings initialization is a good practice to prevent crashes due to file access issues or corrupted settings files. The specific error message provides useful guidance to users.


52-74: Enhanced robustness with DI container error handling.

The try-catch block around dependency injection configuration improves the application's error resilience. This change aligns with the PR objective to address initialization issues.


77-86: Proper API and settings initialization error handling.

This error handling ensures that any exceptions during API and settings initialization are properly caught and displayed to the user, preventing silent failures.


89-92: Good extraction of error display logic.

Extracting the error display logic into a separate method follows the DRY principle and ensures consistent error reporting across all initialization stages.


134-134: Fixed dispatcher thread issue in dependency injection.

This is the key change that addresses the PR objective. Moving the MainViewModel initialization from the constructor to a post-construction initialization method helps resolve dispatcher thread issues.

Previously, MainViewModel was likely being created on the wrong thread when passed directly to the PublicAPIInstance constructor. The new approach ensures proper thread affinity by explicitly initializing it at the right time in the startup sequence.

This comment has been minimized.

@Jack251970 Jack251970 changed the title Fix dispatcher thread issue in dependency injection Fix Dependency Injection Issue Feb 26, 2025
@taooceros
Copy link
Member

Why would mainviewmodel related to dispatcher? Only the UI code requires a dispatcher. On the other hand, the DI is created on a UI thread.

@Jack251970
Copy link
Contributor Author

Why would mainviewmodel related to dispatcher? Only the UI code requires a dispatcher. On the other hand, the DI is created on a UI thread.

Sorry for this confusion. I really do not know how can I name this issue. 😢

I do not know why, but we cannot create MainViewModel instance in PublicAPI constructor... It can cause all functions related to _mainVM cannot work.

This comment has been minimized.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
Flow.Launcher/Flow.Launcher.csproj (1)

94-96: Clarify the Rationale for Dependency Downgrade of DI and Hosting Packages.

The change downgrades Microsoft.Extensions.DependencyInjection and Microsoft.Extensions.Hosting from version 7.0.0 to 6.0.2 due to a TaskScheduler incompatibility with the 7.0.x versions. This modification appears appropriate given the issue; however, please ensure that all features requiring these packages are verified against the downgraded versions in your .NET 7 context. Additionally, consider refining the comment wording for clarity for future maintainers. For example:

-    <!-- Do not upgrade Microsoft.Extensions.DependencyInjection and Microsoft.Extensions.Hosting since we are .Net7.0 -->
+    <!-- Do not upgrade Microsoft.Extensions.DependencyInjection and Microsoft.Extensions.Hosting to 7.0.x versions; TaskScheduler incompatibility necessitates using 6.0.2 -->
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b61199a and d48b4df.

📒 Files selected for processing (1)
  • Flow.Launcher/Flow.Launcher.csproj (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
Flow.Launcher/Flow.Launcher.csproj (1)
Learnt from: taooceros
PR: Flow-Launcher/Flow.Launcher#2616
File: Flow.Launcher/Flow.Launcher.csproj:7-7
Timestamp: 2024-11-12T03:58:56.325Z
Learning: In the Flow Launcher project, the version number in the `Flow.Launcher.csproj` file is dynamically updated during the CI/CD process.
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: gitStream.cm

Copy link

@check-spelling-bot Report

🔴 Please review

See the 📂 files view, the 📜action log, or 📝 job summary for details.

❌ Errors Count
❌ forbidden-pattern 22
⚠️ ignored-expect-variant 1
⚠️ non-alpha-in-dictionary 19

See ❌ Event descriptions for more information.

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

@taooceros
Copy link
Member

The fix doesn't make sense to me. Mainviewmodel does not have anything related to UI (all viewmodel operation). Could you help me understand how do you think this is the problem? I build flow with debug/release on dev and run it with/without debugger. Both doesn't show problem.

I haven't tested the CI build, and will do that now.

@taooceros
Copy link
Member

The error shown in event viewer is this

Application: Flow.Launcher.exe
CoreCLR Version: 7.0.2024.26716
.NET Version: 7.0.20
Description: The process was terminated due to an unhandled exception.
Exception Info: System.PlatformNotSupportedException: EventLog access is not supported on this platform.
   at System.Diagnostics.EventLog..ctor(String logName, String machineName, String source)
   at Microsoft.Extensions.Logging.EventLog.WindowsEventLog..ctor(String logName, String machineName, String sourceName)
   at Microsoft.Extensions.Logging.EventLog.EventLogSettings.CreateDefaultEventLog()
   at Microsoft.Extensions.Logging.EventLog.EventLogSettings.get_EventLog()
   at Microsoft.Extensions.Logging.EventLog.EventLogLogger..ctor(String name, EventLogSettings settings, IExternalScopeProvider externalScopeProvider)
   at Microsoft.Extensions.Logging.EventLog.EventLogLoggerProvider.CreateLogger(String name)
   at Microsoft.Extensions.Logging.LoggerInformation..ctor(ILoggerProvider provider, String category)
   at Microsoft.Extensions.Logging.LoggerFactory.CreateLoggers(String categoryName)
   at Microsoft.Extensions.Logging.LoggerFactory.CreateLogger(String categoryName)
   at Microsoft.Extensions.Logging.Logger`1..ctor(ILoggerFactory factory)
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.ConstructorInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type serviceType)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at Microsoft.Extensions.Hosting.HostBuilder.<>c__DisplayClass35_0.<PopulateServiceCollection>b__2(IServiceProvider _)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type serviceType)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at Microsoft.Extensions.Hosting.HostBuilder.ResolveHost(IServiceProvider serviceProvider, DiagnosticListener diagnosticListener)
   at Microsoft.Extensions.Hosting.HostBuilder.Build()
   at Flow.Launcher.App..ctor() in C:\projects\flow-launcher\Flow.Launcher\App.xaml.cs:line 44
   at Flow.Launcher.App.Main() in C:\projects\flow-launcher\Flow.Launcher\App.xaml.cs:line 70

Even with this pr, the same error appears.

@Jack251970
Copy link
Contributor Author

The fix doesn't make sense to me. Mainviewmodel does not have anything related to UI (all viewmodel operation). Could you help me understand how do you think this is the problem? I build flow with debug/release on dev and run it with/without debugger. Both doesn't show problem.

I haven't tested the CI build, and will do that now.

Checkout this branch https://github.com/Jack251970/Flow.Launcher/tree/dependency_injection_installer and this is strange behaviour:

2025-02-26.15-12-48.mp4

I find the functions like ChangeQuery are called, but there is nothing happened to the main window.

@Jack251970
Copy link
Contributor Author

The error shown in event viewer is this

Application: Flow.Launcher.exe
CoreCLR Version: 7.0.2024.26716
.NET Version: 7.0.20
Description: The process was terminated due to an unhandled exception.
Exception Info: System.PlatformNotSupportedException: EventLog access is not supported on this platform.
   at System.Diagnostics.EventLog..ctor(String logName, String machineName, String source)
   at Microsoft.Extensions.Logging.EventLog.WindowsEventLog..ctor(String logName, String machineName, String sourceName)
   at Microsoft.Extensions.Logging.EventLog.EventLogSettings.CreateDefaultEventLog()
   at Microsoft.Extensions.Logging.EventLog.EventLogSettings.get_EventLog()
   at Microsoft.Extensions.Logging.EventLog.EventLogLogger..ctor(String name, EventLogSettings settings, IExternalScopeProvider externalScopeProvider)
   at Microsoft.Extensions.Logging.EventLog.EventLogLoggerProvider.CreateLogger(String name)
   at Microsoft.Extensions.Logging.LoggerInformation..ctor(ILoggerProvider provider, String category)
   at Microsoft.Extensions.Logging.LoggerFactory.CreateLoggers(String categoryName)
   at Microsoft.Extensions.Logging.LoggerFactory.CreateLogger(String categoryName)
   at Microsoft.Extensions.Logging.Logger`1..ctor(ILoggerFactory factory)
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.ConstructorInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type serviceType)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at Microsoft.Extensions.Hosting.HostBuilder.<>c__DisplayClass35_0.<PopulateServiceCollection>b__2(IServiceProvider _)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type serviceType)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at Microsoft.Extensions.Hosting.HostBuilder.ResolveHost(IServiceProvider serviceProvider, DiagnosticListener diagnosticListener)
   at Microsoft.Extensions.Hosting.HostBuilder.Build()
   at Flow.Launcher.App..ctor() in C:\projects\flow-launcher\Flow.Launcher\App.xaml.cs:line 44
   at Flow.Launcher.App.Main() in C:\projects\flow-launcher\Flow.Launcher\App.xaml.cs:line 70

Even with this pr, the same error appears.

This is the issue related with TaskSchedule and I have reported here: dahall/TaskScheduler#1001.

@taooceros
Copy link
Member

I tried the debug build on dev and cannot reproduce what you get?

@Jack251970
Copy link
Contributor Author

I tried the debug build on dev and cannot reproduce what you get?

Well, let us separate this PR.

@Jack251970 Jack251970 closed this Feb 26, 2025
auto-merge was automatically disabled February 26, 2025 07:29

Pull request was closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5 min review bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants