Error when loading data and using FluentValidation

Topics: Issues / bugs
Aug 10, 2013 at 4:30 PM
I am using fluentvalidation as validator in catel and my problem is when i want to load data and show in a gridview i get the following error:
The invoked member is not supported in a dynamic assembly.
and this is stacktrace:
   at System.Reflection.Emit.InternalAssemblyBuilder.GetExportedTypes()
   at Catel.FluentValidatorProvider.GetValidator(Type targetType)
   at Catel.Data.ValidatorProviderBase.<>c__DisplayClass1.<Catel.Data.IValidatorProvider.GetValidator>b__0()
   at Catel.Caching.CacheStorage`2.GetFromCacheOrFetch(TKey key, Func`1 code, ExpirationPolicy expirationPolicy, Boolean override)
   at Catel.Caching.CacheStorage`2.GetFromCacheOrFetch(TKey key, Func`1 code, Boolean override, TimeSpan expiration)
   at Catel.Data.ValidatorProviderBase.Catel.Data.IValidatorProvider.GetValidator(Type targetType)
   at Catel.Data.CompositeValidatorProvider.<>c__DisplayClass7.<GetValidator>b__3(IValidatorProvider validatorProvider)
   at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Catel.Data.CompositeValidatorProvider.GetValidator(Type targetType)
   at Catel.Data.ValidatorProviderBase.<>c__DisplayClass1.<Catel.Data.IValidatorProvider.GetValidator>b__0()
   at Catel.Caching.CacheStorage`2.GetFromCacheOrFetch(TKey key, Func`1 code, ExpirationPolicy expirationPolicy, Boolean override)
   at Catel.Caching.CacheStorage`2.GetFromCacheOrFetch(TKey key, Func`1 code, Boolean override, TimeSpan expiration)
   at Catel.Data.ValidatorProviderBase.Catel.Data.IValidatorProvider.GetValidator(Type targetType)
   at Catel.Data.ModelBase.get_Validator()
   at Catel.Data.ModelBase.Validate(Boolean force, Boolean validateDataAnnotations)
   at Catel.Data.ModelBase.Validate(Boolean force)
   at Catel.Data.ModelBase.SetDirtyAndAutomaticallyValidate(String propertyName, Boolean setDirtyAndAllowAutomaticValidation)
   at Catel.Data.ModelBase.RaisePropertyChanged(Object sender, PropertyChangedEventArgs e, Boolean setDirtyAndAllowAutomaticValidation, Boolean isRefreshCallOnly)
   at Catel.Data.ModelBase.RaisePropertyChanged(Object sender, AdvancedPropertyChangedEventArgs e)
   at Catel.Data.ObservableObject.RaisePropertyChanged(Object sender, String propertyName, Object oldValue, Object newValue)
   at Catel.Data.ObservableObject.RaisePropertyChanged(String propertyName, Object oldValue, Object newValue)
   at Catel.Data.ModelBase.SetValue(PropertyData property, Object value, Boolean notifyOnChange, Boolean validateAttributes)
   at Catel.Data.ModelBase.SetValue(PropertyData property, Object value)
   at Accounting.Domain.Entities.Customer.set_Id(Int32 value) in h:\Other Files\New folder\4\Accounting\Accounting.Domain\Entities\Customer.cs:line 13
   at lambda_method(Closure , Shaper )
   at System.Data.Common.Internal.Materialization.Shaper.HandleEntityAppendOnly[TEntity](Func`2 constructEntityDelegate, EntityKey entityKey, EntitySet entitySet)
   at lambda_method(Closure , Shaper )
   at System.Data.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper)
   at System.Data.Common.Internal.Materialization.Shaper`1.SimpleEnumerator.MoveNext()
   at System.Data.Entity.DbExtensions.Load(IQueryable source)
   at Accounting.ViewModels.Customer.AllCustomersViewModel.Initialize() in h:\Other Files\New folder\4\Accounting\Accounting\ViewModels\Customer\AllCustomersViewModel.cs:line 25
   at Catel.MVVM.ViewModelBase.InitializeViewModel()
   at Catel.Windows.Controls.MVVMProviders.Logic.LogicBase.<OnTargetControlLoadedInternal>b__3()
   at Catel.Windows.Threading.DispatcherExtensions.BeginInvoke(Dispatcher dispatcher, Action action, Boolean onlyBeginInvokeWhenNoAccess)
   at Catel.Windows.Threading.DispatcherExtensions.BeginInvokeIfRequired(Dispatcher dispatcher, Action action)
   at Catel.Windows.Controls.MVVMProviders.Logic.LogicBase.OnTargetControlLoadedInternal(Object sender, EventArgs e)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at MS.Internal.FrameworkObject.OnLoaded(RoutedEventArgs args)
   at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
   at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root)
   at System.Windows.Media.MediaContext.FireLoadedPendingCallbacks()
   at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
   at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
   at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run()
   at Accounting.App.Main() in h:\Other Files\New folder\4\Accounting\Accounting\obj\Debug\App.g.cs:line 0
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
I know my approach is not wrong because it worked with catel 3.4 but in new versions the problem appears.
Aug 11, 2013 at 5:26 PM
Can you please provide a repro? Are you sure this is a Catel problem (not a FluentValidation one)? If you create a ticket here, we can take a look.
Aug 11, 2013 at 7:37 PM
Edited Aug 11, 2013 at 7:38 PM
thanks for your replies.
I'm really confused with this issue. i removed all validator classes but error still exist! I think problem is in setting fluentvalidator in application startup. I use the below code:
private static void SetValidation()
{
       var serviceLocator = ServiceLocator.Default;
       var provider = new CompositeValidatorProvider();
       provider.Add(new FluentValidatorProvider());
       serviceLocator.RegisterInstance<IValidatorProvider>(provider);
}
is it wrong?
Aug 15, 2013 at 5:33 PM
Yeah, probably it happens as soon as you load the FluentValidation assembly. Which version of FluentValidation (nuget package version) are you using?
Aug 15, 2013 at 6:02 PM
yes i use nuget packages. latest FluentValidation version 4.0.0.1 and latest pre-release catel. i also try catel stable version 3.6 but no success.
when i get no success with it i switch my whole validation to using ValidatorBase instead and it works great.
thanks you so much.
Aug 16, 2013 at 2:25 PM
Hi Geert
do you fix this issue? now i use fody (simple properties that compiled to catel properies) then i cant use ValidatorBase anymore.
Aug 16, 2013 at 7:04 PM
Edited Aug 17, 2013 at 6:13 AM
Only automatic properties are merged into Catel properties. If you create a property with a backing field yourself, it won't
be handled by Fody. I don't see this fixed soon, other priorities.

** edit **

Sorry, ignore my response, had other issue in mind. I will look into this asap, but paying customers always go first.
Aug 17, 2013 at 7:36 PM
Please check out the examples repository (especially Examples.WPF.Validation). It contains a FluentValidation part and works great with the latest version.