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

ToDo reference sample crashes when clicking the SettingsView button. Possibly related to localizer #676

Closed
wartron opened this issue May 5, 2024 · 4 comments
Assignees

Comments

@wartron
Copy link

wartron commented May 5, 2024

When clicking the top button the mock current user "Foo Bar" which opens the SettingsView

System.Runtime.InteropServices.COMException
  HResult=0x8001010E
  Message=
  Source=WinRT.Runtime
  StackTrace:
   at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|39_0(Int32 hr)
   at ABI.Microsoft.UI.Xaml.IWindowMethods.get_Content(IObjectReference _obj)
   at Microsoft.UI.Xaml.Window.get_Content()
   at ToDo.AppTheme.get_IsDark() in C:\Users\wartron\code\uno\Uno.Samples\reference\ToDo\src\ToDo.UI\AppTheme.cs:line 14
   at ToDo.Presentation.SettingsViewModel.<>c__DisplayClass15_0.<.ctor>b__0() in C:\Users\wartron\code\uno\Uno.Samples\reference\ToDo\src\ToDo\Presentation\SettingsViewModel.cs:line 42
   at Uno.Extensions.Reactive.State`1.<>c__5`1.<Value>b__5_0(TOwner o, Func`1 v)
   at Uno.Extensions.Reactive.Utils.AttachedProperty.GetOrCreate[TOwner,TKey,TValue](TOwner owner, TKey key, Factory`3 factory)
   at Uno.Extensions.Reactive.State`1.Value[TOwner](TOwner owner, Func`1 valueProvider)
   at Uno.Extensions.Reactive.State.Value[TOwner,TValue](TOwner owner, Func`1 valueProvider)
   at ToDo.Presentation.SettingsViewModel..ctor(NavigationRequest request, INavigator navigator, IAuthenticationService authService, IUserProfilePictureService userSvc, IOptions`1 localizationConfiguration, ILocalizationService localizationSettings, IStringLocalizer localizer, IAppTheme appTheme, IWritableOptions`1 appSettings) in C:\Users\wartron\code\uno\Uno.Samples\reference\ToDo\src\ToDo\Presentation\SettingsViewModel.cs:line 42
   at ToDo.Presentation.BindableSettingsViewModel..ctor(NavigationRequest request, INavigator navigator, IAuthenticationService authService, IUserProfilePictureService userSvc, IOptions`1 localizationConfiguration, ILocalizationService localizationSettings, IStringLocalizer localizer, IAppTheme appTheme, IWritableOptions`1 appSettings) in C:\Users\wartron\code\uno\Uno.Samples\reference\ToDo\src\ToDo\Uno.Extensions.Reactive.Generator\Uno.Extensions.Reactive.Generator.FeedsGenerator\ToDo.Presentation.SettingsViewModel.Bindable.g.cs:line 26
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithManyArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   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.VisitDisposeCache(ServiceCallSite transientCallSite, 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.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass2_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
   at Uno.Extensions.Navigation.Navigators.ControlNavigator.<>c__DisplayClass8_0.<<CreateViewModel>b__0>d.MoveNext()

So i figured i'd just default this line in SettingViewModel.cs to just 0

SelectedAppTheme = State.Value(this, () => AppThemes[appTheme.IsDark ? 1 : 0]);

to

SelectedAppTheme = State.Value(this, () => AppThemes[0]);

and then it breaks at the line


        Cultures = localizationConfiguration.Value!.Cultures!.Select(c => new DisplayCulture(localizer[$"SettingsFlyout_LanguageLabel_{c}"], c)).ToArray();

with this error

System.ArgumentNullException
  HResult=0x80004003
  Message=Value cannot be null. (Parameter 'source')
  Source=System.Linq
  StackTrace:
   at System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
   at System.Linq.Enumerable.Select[TSource,TResult](IEnumerable`1 source, Func`2 selector)
   at ToDo.Presentation.SettingsViewModel..ctor(NavigationRequest request, INavigator navigator, IAuthenticationService authService, IUserProfilePictureService userSvc, IOptions`1 localizationConfiguration, ILocalizationService localizationSettings, IStringLocalizer localizer, IAppTheme appTheme, IWritableOptions`1 appSettings) in C:\Users\wartron\code\uno\Uno.Samples\reference\ToDo\src\ToDo\Presentation\SettingsViewModel.cs:line 46
   at ToDo.Presentation.BindableSettingsViewModel..ctor(NavigationRequest request, INavigator navigator, IAuthenticationService authService, IUserProfilePictureService userSvc, IOptions`1 localizationConfiguration, ILocalizationService localizationSettings, IStringLocalizer localizer, IAppTheme appTheme, IWritableOptions`1 appSettings) in C:\Users\wartron\code\uno\Uno.Samples\reference\ToDo\src\ToDo\Uno.Extensions.Reactive.Generator\Uno.Extensions.Reactive.Generator.FeedsGenerator\ToDo.Presentation.SettingsViewModel.Bindable.g.cs:line 26
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithManyArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   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.VisitDisposeCache(ServiceCallSite transientCallSite, 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.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass2_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
   at Uno.Extensions.Navigation.Navigators.ControlNavigator.<>c__DisplayClass8_0.<<CreateViewModel>b__0>d.MoveNext()

Uno and Samples where downleded May 3rd, 2024

@agneszitte agneszitte self-assigned this May 8, 2024
@wartron
Copy link
Author

wartron commented May 12, 2024

Noticed this in the console also

Uno.Extensions.Storage.FileStorage: Warning: ReadPackageFileAsync - File 'appsettings.keyvaluestorageconfiguration.json' does not exist in package
Uno.Extensions.Storage.FileStorage: Warning: ReadPackageFileAsync - File 'appsettings.platform.development.json' does not exist in package
Uno.Extensions.Storage.FileStorage: Warning: ReadPackageFileAsync - File 'appsettings.auth.json' does not exist in package
Uno.Extensions.Storage.FileStorage: Warning: ReadPackageFileAsync - File 'appsettings.mock.json' does not exist in package
Uno.Extensions.Storage.FileStorage: Warning: ReadPackageFileAsync - File 'appsettings.todoapp.json' does not exist in package
Uno.Extensions.Storage.FileStorage: Warning: ReadPackageFileAsync - File 'appsettings.localizationconfiguration.json' does not exist in package
Uno.Extensions.Storage.FileStorage: Warning: ReadPackageFileAsync - File 'appsettings.localizationsettings.json' does not exist in package

@agneszitte
Copy link
Contributor

Thank you a lot for the feedback @wartron, we will investigate

@agneszitte
Copy link
Contributor

agneszitte commented Jun 5, 2024

@rajamatt this change with the .ToString() should fix that normally, if you can confirm while doing the migration for the sample please.

SelectedCulture = State.Value(this, () => Cultures.FirstOrDefault(c => c.Culture.Equals(LocalizationService.CurrentCulture.ToString())) ?? Cultures.First());

@agneszitte agneszitte assigned rajamatt and unassigned agneszitte Jun 10, 2024
@agneszitte
Copy link
Contributor

Related PR for coming changes for single project migration and fix for this issue: #745

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants