canton7 / Stylet

A very lightweight but powerful ViewModel-First MVVM framework for WPF for .NET Framework and .NET Core, inspired by Caliburn.Micro.
MIT License
988 stars 143 forks source link

Exception happened when WindowManager.ShowWindow() #170

Closed FaustPipeDream closed 3 years ago

FaustPipeDream commented 3 years ago

I'm using WindowManager.ShowWindow to show a new window,It work fine at first,but today it not work with the Exception ArgumentException: Cannot bind to the target method because its signature or security transparency is not compatible with that of the delegate type and SystemWindows.Markup.XamlParseException: can't create "VerifyFunc" from text. Hrer is the code :

public class RootViewModel : Conductor<IScreen>.Collection.OneActive
    {
        private readonly IWindowManager WindowManager;
        private readonly ViewModelFactory ViewModelFactory;
        private TerminalViewModel TerminalViewModel { get; set; }
        public RootViewModel(ViewModelFactory viewModelFactory, IWindowManager windowManager){
            ViewModelFactory = viewModelFactory;
            TerminalViewModel = viewModelFactory.CreateTerminalViewModel();
            WindowManager = windowManager;
        }
      public void DoShowTerminalControl()
        {
             //Exception happened in here
             WindowManager.ShowWindow(ViewModelFactory.
                     CreateTerminalControlViewModel(TerminalViewModel.TerminalTreeNodes));
        }
}

It work fine at first and i'm sure I didn't modify it recently.

canton7 commented 3 years ago

Can you please provide enough information for me to reproduce the issue (at the very least, the XAML for your RootView), and the full stack trace of the two exceptions, please?

FaustPipeDream commented 3 years ago

In RootView XAML,I just define a Button and bind the DoShowTerminalControl() to it.

And here is the stack trace of SystemWindows.Markup.XamlParseException: can't create "VerifyFunc" from text

   At System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
   At System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
   At System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
   At System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
   At TerminalPlus.Views.Terminal.TerminalControlView.InitializeComponent() 
   At D:\WorkShop\Code\TerminalPlus\Views\Terminal\TerminalControlView.xaml : first line

Here is the stack trace of ArgumentException: Cannot bind to the target method because its signature or security transparency is not compatible with that of the delegate type``

   At System.Delegate.CreateDelegate(Type type, Object target, String method, Boolean ignoreCase, Boolean throwOnBindFailure)
   At System.Delegate.CreateDelegate(Type type, Object target, String method)
   At System.Xaml.Schema.SafeReflectionInvoker.CreateDelegateCritical(Type delegateType, Object target, String methodName)
   At System.Xaml.Schema.SafeReflectionInvoker.CreateDelegate(Type delegateType, Object target, String methodName)
   At System.Xaml.EventConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
   At MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateObjectWithTypeConverter(ServiceProviderContext serviceContext, XamlValueConverter`1 ts, Object value)
   At MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateFromValue(ServiceProviderContext serviceContext, XamlValueConverter`1 ts, Object value, XamlMember property)
   At MS.Internal.Xaml.Runtime.PartialTrustTolerantRuntime.CreateFromValue(ServiceProviderContext serviceContext, XamlValueConverter`1 ts, Object value, XamlMember property)
   At System.Xaml.XamlObjectWriter.Logic_CreateFromValue(ObjectWriterContext ctx, XamlValueConverter`1 typeConverter, Object value, XamlMember property, String targetName, IAddLineInfo lineInfo)

I create the TerminalControlViewModel in the factory and share the TreeNodes of the TerminalViewModel with TerminalControlViewModel.

canton7 commented 3 years ago

This looks like it's a problem in your XAML. I can't help unless you post your XAML. Notice how neither of the stack traces mention Stylet, just the XAML loader.

FaustPipeDream commented 3 years ago

Thank you,I just found I add some verify function in the XAML but forgot bind method to them. What a silly problem

canton7 commented 3 years ago

Glad you solved it!