eXpandFramework / eXpand

DevExpress XAF (eXpressApp) extension framework. ๐—น๐—ถ๐—ป๐—ธ๐—ฒ๐—ฑ๐—ถ๐—ป.๐—ฒ๐˜…๐—ฝ๐—ฎ๐—ป๐—ฑ๐—ณ๐—ฟ๐—ฎ๐—บ๐—ฒ๐˜„๐—ผ๐—ฟ๐—ธ.๐—ฐ๐—ผ๐—บ, ๐˜†๐—ผ๐˜‚๐˜๐˜‚๐—ฏ๐—ฒ.๐—ฒ๐˜…๐—ฝ๐—ฎ๐—ป๐—ฑ๐—ณ๐—ฟ๐—ฎ๐—บ๐—ฒ๐˜„๐—ผ๐—ฟ๐—ธ.๐—ฐ๐—ผ๐—บ and ๐˜๐˜„๐—ถ๐˜๐˜๐—ฒ๐—ฟ @๐—ฒ๐˜…๐—ฝ๐—ฎ๐—ป๐—ฑ๐—ณ๐—ฟ๐—ฎ๐—บ๐—ฒ๐˜„๐—ผ๐—ฟ๐—ธ and or simply ๐—ฆ๐˜๐—ฎ๐—ฟ/๐˜„๐—ฎ๐˜๐—ฐ๐—ต this repository and get notified from ๐—š๐—ถ๐˜๐—›๐˜‚๐—ฏ
http://expand.expandframework.com
Microsoft Public License
222 stars 115 forks source link

After installation Reactive.rest i am start getting such error: Unable to cast object of type 'Castle.Proxies.ApplicationUserProxy' to type 'Xpand.XAF.Modules.Reactive.Rest.ICredentialBearer'. #1027

Closed beneton2003 closed 8 months ago

beneton2003 commented 1 year ago

๐—ค๐˜‚๐—ฒ๐˜€๐˜๐—ถ๐—ผ๐—ป Hi! Maybe somebody can help me with some strange issue. This is the full log

Log:

info: DevExpress.AspNetCore.Reporting.Logger[0]
      AspNetCoreThreadingTimerStoragesCleaner.StartCore

info: Microsoft.Hosting.Lifetime[14]
      Now listening on: https://localhost:57602
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:57603
info: Hangfire.BackgroundJobServer[0]
      Starting Hangfire Server using job storage: 'SQL Server: 88.99.226.170@HRStation'
info: Hangfire.BackgroundJobServer[0]
      Using the following options for SQL Server job storage: Queue poll interval: 00:00:00.
info: Hangfire.BackgroundJobServer[0]
      Using the following options for Hangfire Server:
          Worker count: 20
          Listening queues: 'default'
          Shutdown timeout: 00:00:15
          Schedule polling interval: 00:00:15
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: D:\apps_sharp\HRStationXaf\HRStation\HRStation.Blazor.Server
info: Hangfire.Server.BackgroundServerProcess[0]
      Server nurubkov:16404:a29c975d successfully announced in 1117,2346 ms
info: Hangfire.Server.BackgroundServerProcess[0]
      Server nurubkov:16404:a29c975d is starting the registered dispatchers: ServerWatchdog, ServerJobCancellationWatcher, ExpirationManager, CountersAggregator, SqlServerHeartbeatProcess, Worker, DelayedJobScheduler, RecurringJobScheduler...
info: Hangfire.Server.BackgroundServerProcess[0]
      Server nurubkov:16404:a29c975d all the dispatchers started
warn: Microsoft.EntityFrameworkCore.Query[20504]
      Compiling a query which loads related collections for more than one collection navigation, either via 'Include' or through projection, but no 'QuerySplittingBehavior' has been configured. By default, Entity Framework will use 'QuerySplittingBehavior.SingleQuery', which can potentially result in slow query performance. See https://go.microsoft.com/fwlink/?linkid=2134277 for more information. To identify the query that's triggering this warning call 'ConfigureWarnings(w => w.Throw(RelationalEventId.MultipleCollectionIncludeWarning))'.
fail: DevExpress.ExpressApp.Blazor.Services.ExceptionService[0]
      Handled exception occurs
      System.InvalidCastException: Unable to cast object of type 'Castle.Proxies.ApplicationUserProxy' to type 'Xpand.XAF.Modules.Reactive.Rest.ICredentialBearer'.
         at Xpand.XAF.Modules.Reactive.Rest.RestService.<>c__DisplayClass12_0.<WhenNonPersistentObjectSpace>b__1(ValueTuple`2 t)
         at System.Reactive.Linq.ObservableImpl.SelectMany`2.ObservableSelector._.OnNext(TSource value) in /_/Rx.NET/Source/src/System.Reactive/Linq/Observable/SelectMany.cs:line 869

================================================================================ The error occurred:


    Type:       InvalidCastException
    Message:    Unable to cast object of type 'Castle.Proxies.ApplicationUserProxy' to type 'Xpand.XAF.Modules.Reactive.Rest.ICredentialBearer'.
    Data:       0 entries
    Stack trace:

   at Xpand.XAF.Modules.Reactive.Rest.RestService.<>c__DisplayClass12_0.<WhenNonPersistentObjectSpace>b__1(ValueTuple`2 t)
   at System.Reactive.Linq.ObservableImpl.SelectMany`2.ObservableSelector._.OnNext(TSource value) in /_/Rx.NET/Source/src/System.Reactive/Linq/Observable/SelectMany.cs:line 869
    InnerException is null
beneton2003 commented 1 year ago

I have custom implemented ApplicationUser class, maybe this is the problem?:


namespace HRStation.Module.BusinessObjects.Security;

using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Net.Mail;
using System.Reactive.Linq;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.DC;
using DevExpress.ExpressApp.Security;
using DevExpress.Persistent.BaseImpl.EF.PermissionPolicy;

[DefaultProperty(nameof(UserName))]
public class ApplicationUser : PermissionPolicyUser, ISecurityUserWithLoginInfo
{
    public ApplicationUser() : base()
    {
        UserLogins = new ObservableCollection<ApplicationUserLoginInfo>();
    }

    [Browsable(false)]
    [Aggregated]
    public virtual IList<ApplicationUserLoginInfo> UserLogins { get; set; }

    IEnumerable<ISecurityUserLoginInfo> IOAuthSecurityUser.UserLogins => UserLogins.OfType<ISecurityUserLoginInfo>();

    ISecurityUserLoginInfo ISecurityUserWithLoginInfo.CreateUserLoginInfo(string loginProviderName, string providerUserKey)
    {
        ApplicationUserLoginInfo result = ((IObjectSpaceLink)this).ObjectSpace.CreateObject<ApplicationUserLoginInfo>();
        result.LoginProviderName = loginProviderName;
        result.ProviderUserKey = providerUserKey;
        result.User = this;
        return result;
    }

}
beneton2003 commented 1 year ago

I have also nonpersistent object in my project:

namespace HRStation.Module.BusinessObjects.Worklogs;

using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.DC;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.Validation;
using HRStation.Module.BusinessObjects.Issues;
using HRStation.Module.BusinessObjects.Persons;
using HRStation.Module.BusinessObjects.Security;
using HRStation.Module.BusinessObjects.Sprints;

[DomainComponent]
[RuleCriteria("WorklogNPO_EndOn", DefaultContexts.Save, "EndOn > StartOn", "End On shoulde greater than Start On")]
public class WorklogActionNPO : NonPersistentObjectImpl, IObjectSpaceLink, INotifyPropertyChanged
{
    #region Private fields
    private Person person;
    private Project project;
    private ProjectAction projectAction;
    private Issue issue;
    private Sprint sprint;
    private DateTime startOn;
    private int durationHours;
    private int durationMinutes;
    private string description;
    //private IObjectSpace objectSpace;
    #endregion

    public override void OnCreated()
    {
        ApplicationUser currentUser = ObjectSpace.GetObjectByKey<ApplicationUser>(SecuritySystem.CurrentUserId);
        Person = ObjectSpace.FirstOrDefault<Person>(p => p.ApplicationUser == currentUser);
        Sprint = ObjectSpace.FirstOrDefault<SprintIssue>(s => s.Person == Person)?.Sprint;
        base.OnCreated();
    }

    [RuleRequiredField]
    public Person Person
    {
        get { return person; }
        set { SetPropertyValue(ref person, value); }

    }

    [RuleRequiredField]
    public Project Project
    {
        get { return project; }
        set 
        {
            ProjectAction = null;
            Issue = null;
            SetPropertyValue(ref project, value); 
        }

    }

    [RuleRequiredField]
    [DataSourceProperty("Project.ProjectActions")]
    public ProjectAction ProjectAction {
        get
        {
            return projectAction;
        }
        set
        {
            Issue = value?.Issue;
            SetPropertyValue(ref projectAction, value);
        }

    }

    public Issue Issue
    {
        get { return issue; }
        set { SetPropertyValue(ref issue, value); }

    }

    [RuleRequiredField]
    public Sprint Sprint
    {
        get { return sprint; }
        set { SetPropertyValue(ref sprint, value); }

    }
    public DateTime StartOn
    {
        get { return startOn; }
        set { SetPropertyValue(ref startOn, value); }

    }
    public DateTime EndOn { get { return StartOn.AddHours(DurationHours).AddMinutes(DurationMinutes); } }

    [RuleValueComparison("WorklogNPO_DurationHoursMax", DefaultContexts.Save, ValueComparisonType.LessThanOrEqual, 24)]
    [RuleValueComparison("WorklogNPO_DurationHoursMin", DefaultContexts.Save, ValueComparisonType.GreaterThanOrEqual, 0)]
    public int DurationHours
    {
        get { return durationHours; }
        set { SetPropertyValue(ref durationHours, value); }

    }

    [RuleValueComparison("WorklogNPO_DurationMinutesMax", DefaultContexts.Save, ValueComparisonType.LessThanOrEqual, 59)]
    [RuleValueComparison("WorklogNPO_DurationMinutesMin", DefaultContexts.Save, ValueComparisonType.GreaterThanOrEqual, 0)]
    public int DurationMinutes
    {
        get { return durationMinutes; }
        set { SetPropertyValue(ref durationMinutes, value); }

    }

    public string Description
    {
        get { return description; }
        set { SetPropertyValue(ref description, value); }

    }

}
apobekiaris commented 1 year ago

Can you please post a sample.

beneton2003 commented 1 year ago

Reference i

https://github.com/beneton2003/HRStationXaf - i added you to my project, so you can see the whole solution.

apobekiaris commented 1 year ago

thnks I will test the case, I also interested to know if you plan to work with the REST module or you face problems cause you install it together with the all the packages

beneton2003 commented 1 year ago

I want to use REST feature, maybe i installed something wrong. Sorry i am not very experienced. I will be very happy if you give me some advice how to fix it, i also have a question about authentification, how to use bearer token for the requests? Maybe you have some example of the working with some public api?

beneton2003 commented 1 year ago

I want to get recipient accounts from this api: https://docs.wise.com/api-docs/api-reference/recipient

apobekiaris commented 1 year ago

thnks for the clarification, now I see the problem without to explore your solution

Castle.Proxies.ApplicationUserProxy

meaning you are in EF and the package uses XPO. Note the package is tested for various cases in https://github.com/eXpandFramework/Reactive.XAF/tree/master/src/Tests/Reactive.Rest. Consider exploring them to get how the package works if you plan to use XPO instead

beneton2003 commented 1 year ago

thnks for the clarification, now I see the problem without to explore your solution

Castle.Proxies.ApplicationUserProxy

meaning you are in EF and the package uses XPO. Note the package is tested for various cases in https://github.com/eXpandFramework/Reactive.XAF/tree/master/src/Tests/Reactive.Rest. Consider exploring them to get how the package works if you plan to use XPO instead

I am using both xpo and EF. I have Hangfire module installed and used XPO, maybe i just can add this module to that part which using XPO?

But when i tried to include this module in the part which uses xpo, its still getting this error... i will explore more

beneton2003 commented 1 year ago

I realise that Reactive.rest somehow uses the Security system (like PermissionPolicyUser), but i am using my security system in EF and maybe this is the reason....

apobekiaris commented 1 year ago

Not exactly

Unable to cast object of type 'Castle.Proxies.ApplicationUserProxy' to type 'Xpand.XAF.Modules.Reactive.Rest.ICredentialBearer'.

it speaks out, meaning u imlpement ICredentialBearer in your ApplicationUser which is an EF Entity

apobekiaris commented 1 year ago

the package may be able to work even with EF (I never try it) given that ICrendentialBearer is not an EF entity, or they maybe other problems in regards to EF, I really not sure as this was designed with XPO

expand commented 8 months ago

Closing issue for age. Feel free to reopen it at any time.

.Thank you for your contribution.