reactiveui / ReactiveUI

An advanced, composable, functional reactive model-view-viewmodel framework for all .NET platforms that is inspired by functional reactive programming. ReactiveUI allows you to abstract mutable state away from your user interfaces, express the idea around a feature in one readable place and improve the testability of your application.
https://www.reactiveui.net
MIT License
8.05k stars 1.12k forks source link

[BUG] [Critical] Continuous ReactiveCommand crash - TypeLoadException #3123

Closed ccornici closed 2 years ago

ccornici commented 2 years ago

Describe the bug

THIS IS FIXED BY DOWNGRADING PACKAGES TO 13.3.2

So...the bug:

I've got a Command

public ReactiveCommand<string, Unit> Cmd { get; }
......
            // In ctor
            Cmd = ReactiveCommand.CreateFromTask<string>((id) =>
            {
                return SomeAsyncMethod(id);
            });
System.TypeInitializationException: 'The type initializer for 'ReactiveUI.RxApp' threw an exception.'
TypeLoadException: Could not load type 'ReactiveUI.ComponentModelTypeConverter' from assembly 'ReactiveUI, Version=17.1.0.0, Culture=neutral, PublicKeyToken=null'.
   at ReactiveUI.RxApp.get_MainThreadScheduler() in /_/src/ReactiveUI/RxApp.cs:line 146
   at ReactiveUI.ReactiveCommand`2..ctor(Func`2 execute, IObservable`1 canExecute, IScheduler outputScheduler) in /_/src/ReactiveUI/ReactiveCommand/ReactiveCommand.cs:line 657
   at ReactiveUI.ReactiveCommand.CreateFromObservable[TParam,TResult](Func`2 execute, IObservable`1 canExecute, IScheduler outputScheduler) in /_/src/ReactiveUI/ReactiveCommand/ReactiveCommand.cs:line 340
   at ReactiveUI.ReactiveCommand.CreateFromTask[TParam](Func`2 execute, IObservable`1 canExecute, IScheduler outputScheduler) in /_/src/ReactiveUI/ReactiveCommand/ReactiveCommand.cs:line 566
   at MyApp.ViewModels.InventoryVM..ctor(IStorageService storageService) in C:\Projects\Win 10 apps\MyApp\MyApp\ViewModels\InventoryVM.cs:line 18
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   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.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 MyApp.Framework.ViewModelLocator.get_InventoryVM() in C:\Projects\Win 10 apps\MyApp\MyApp\Framework\ViewModelLocator.cs:line 12
   at MyApp.Views.InventoryPage..ctor() in C:\Projects\Win 10 apps\MyApp\MyApp\Views\InventoryPage.xaml.cs:line 14

Steps To Reproduce

See above, it's a command!

Expected behaviour

Not crash maybe? Idk

Screenshots

image

Environment

Additional context

THIS IS FIXED BY DOWNGRADING PACKAGES TO 13.3.2 Using .net core 3.1

ChrisPulman commented 2 years ago

Again please look at this https://github.com/ChrisPulman/reactive_ui_bug_1 it will help you understand the issue you are experiencing

GitHub
GitHub - ChrisPulman/reactive_ui_bug_1
Contribute to ChrisPulman/reactive_ui_bug_1 development by creating an account on GitHub.
ChrisPulman commented 2 years ago

For your information and as per the release notes and targets published with the nuget package V16.x.x was the last version that supports netcoreapp3.1 and net5.0, please migrate to net6.0 to use V17. As per the issue raised in one of the libraries you have attempted to include it only supports up to net48 - https://github.com/rafallopatka/ToastNotifications/issues/109

Correcting the coding method and excluding this library allows the application to operate as expected. Please read our documentation for guidance on the correct way to code your application https://www.reactiveui.net/docs/handbook/

Handbook
github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.