eXpandFramework / eXpand

DevExpress XAF (eXpressApp) extension framework. 𝗹𝗶𝗻𝗸𝗲𝗱𝗶𝗻.𝗲𝘅𝗽𝗮𝗻𝗱𝗳𝗿𝗮𝗺𝗲𝘄𝗼𝗿𝗸.𝗰𝗼𝗺, 𝘆𝗼𝘂𝘁𝘂𝗯𝗲.𝗲𝘅𝗽𝗮𝗻𝗱𝗳𝗿𝗮𝗺𝗲𝘄𝗼𝗿𝗸.𝗰𝗼𝗺 and 𝘁𝘄𝗶𝘁𝘁𝗲𝗿 @𝗲𝘅𝗽𝗮𝗻𝗱𝗳𝗿𝗮𝗺𝗲𝘄𝗼𝗿𝗸 and or simply 𝗦𝘁𝗮𝗿/𝘄𝗮𝘁𝗰𝗵 this repository and get notified from 𝗚𝗶𝘁𝗛𝘂𝗯
http://expand.expandframework.com
Microsoft Public License
220 stars 114 forks source link

ArgumentException if using MiddleTierServerObjectSpaceProvider and Reactive.XAF-Modules #934

Closed krombipils closed 2 years ago

krombipils commented 2 years ago

Hi,

if using the DevExpress.ExpressApp.Security.ClientServer.MiddleTierServerObjectSpaceProvider in combination with any Reactive.XAF module, an ArgumentException: "Bad label content in ILGenerator" is thrown (and shown to the user) before the login dialog is opened.

grafik

The error occurs in the ObjectSpaceProviderExtensions.PatchSchemaUpdated method.

I attached a simple project to demonstrate the problem. This solution was created by the DevExpress XAF 21.2.7 wizard. I just added the HideToolbarModule manually (but any other Reactive.XAF module will trigger the same error).

Unfortunately I have no clue what's going wrong.

DXApplication8.zip

apobekiaris commented 2 years ago

note these event are not used from any package they are there for convenience to external consumers, as so I will simply disable the MiddleTier support.

apobekiaris commented 2 years ago

Unfortunately I have no clue what's going wrong.

I also not have any clue cause Harmony is really robust when applied to non virtual method of any visibility, My guess is that it relates how compiler transaltes the provider UpdateScheme native implementation

public void UpdateSchema() => throw new NotSupportedException();
apobekiaris commented 2 years ago

The pre-release 4.212.9.0 in the Reactive.XAF lab branch includes commits that relate to this task:

To minimize version conflicts we recommend that you use the Xpand.XAF.Core.All, Xpand.XAF.Win.All, Xpand.XAF.Web.All packages. Doing so, all packages will be at your disposal and .NET will add a dependecy only to those packages that you actually use and not to all (see the Modules installation-registrations youtube video).

Released packages: Xpand.Extensions v.4.212.9
Xpand.Extensions.Blazor v.4.212.9
Xpand.Extensions.Mono.Cecil v.4.212.9
Xpand.Extensions.Office.Cloud v.4.212.9
Xpand.Extensions.Office.Cloud.Google.Blazor v.4.212.9
Xpand.Extensions.Reactive v.4.212.9
Xpand.Extensions.XAF v.4.212.9
Xpand.Extensions.XAF.Xpo v.4.212.9
Xpand.TestsLib v.4.212.9
Xpand.TestsLib.Blazor v.4.212.9
Xpand.TestsLib.Common v.4.212.9
Xpand.TestsLib.EasyTest v.4.212.9
Xpand.TestsLib.Net461 v.4.212.9
Xpand.VersionConverter v.4.212.9
Xpand.XAF.Core.All v.4.212.9
Xpand.XAF.Modules.AutoCommit v.4.212.9
Xpand.XAF.Modules.Blazor v.4.212.9
Xpand.XAF.Modules.BulkObjectUpdate v.4.212.9
Xpand.XAF.Modules.CloneMemberValue v.4.212.9
Xpand.XAF.Modules.CloneModelView v.4.212.9
Xpand.XAF.Modules.Email v.4.212.9
Xpand.XAF.Modules.GridListEditor v.4.212.9
Xpand.XAF.Modules.HideToolBar v.4.212.9
Xpand.XAF.Modules.JobScheduler.Hangfire v.4.212.9
Xpand.XAF.Modules.JobScheduler.Notification v.4.212.9
Xpand.XAF.Modules.MasterDetail v.4.212.9
Xpand.XAF.Modules.ModelMapper v.4.212.9
Xpand.XAF.Modules.ModelViewInheritance v.4.212.9
Xpand.XAF.Modules.Office.Cloud.Google v.4.212.9
Xpand.XAF.Modules.Office.Cloud.Google.Calendar v.4.212.9
Xpand.XAF.Modules.Office.Cloud.Google.Tasks v.4.212.9
Xpand.XAF.Modules.Office.Cloud.Microsoft v.4.212.9
Xpand.XAF.Modules.Office.Cloud.Microsoft.Calendar v.4.212.9
Xpand.XAF.Modules.Office.Cloud.Microsoft.Todo v.4.212.9
Xpand.XAF.Modules.Office.DocumentStyleManager v.4.212.9
Xpand.XAF.Modules.OneView v.4.212.9
Xpand.XAF.Modules.PositionInListView v.4.212.9
Xpand.XAF.Modules.ProgressBarViewItem v.4.212.9
Xpand.XAF.Modules.RazorView v.4.212.9
Xpand.XAF.Modules.Reactive v.4.212.9
Xpand.XAF.Modules.Reactive.Logger v.4.212.9
Xpand.XAF.Modules.Reactive.Logger.Client.Win v.4.212.9
Xpand.XAF.Modules.Reactive.Logger.Hub v.4.212.9
Xpand.XAF.Modules.Reactive.Rest v.4.212.9
Xpand.XAF.Modules.RefreshView v.4.212.9
Xpand.XAF.Modules.SequenceGenerator v.4.212.9
Xpand.XAF.Modules.SuppressConfirmation v.4.212.9
Xpand.XAF.Modules.TenantManager v.4.212.9
Xpand.XAF.Modules.ViewEditMode v.4.212.9
Xpand.XAF.Modules.ViewItemValue v.4.212.9
Xpand.XAF.Modules.ViewWizard v.4.212.9
Xpand.XAF.Modules.Windows v.4.212.9
Xpand.XAF.Web.All v.4.212.9
Xpand.XAF.Win.All v.4.212.9

Please update the related Nuget packages and test if issues is addressed. These are nightly nuget packages available only from our NugetServer.

If you do not use these packages directly but through a module of the main eXpandFramework project, please wait for the bot to notify you again when integration is finished or update the related packages manually.

Thanks a lot for your contribution.

krombipils commented 2 years ago

Problem is fixed in 4.212.9.7. Thank you!

apobekiaris commented 2 years ago

how about this version??

internal static IObservable<Unit> PatchAuthentication(this XafApplication application) 
            => application.WhenSetupComplete()
                .DoWhen(_ => application.Security.IsInstanceOf("DevExpress.ExpressApp.Security.SecurityStrategyBase"),
                    _ => application.Security.GetPropertyValue("Authentication").GetType().Methods("Authenticate")
                        .Last(info => info.DeclaringType is { IsAbstract: false })
                        .Patch(new HarmonyMethod(typeof(SecurityExtensions),nameof(Authenticate))))
                .ToUnit();

and the Patch extension which always avoid double attempts

        public static Harmony Patch(this MethodInfo method, HarmonyMethod prefix = null, HarmonyMethod postFix = null, HarmonyMethod transpiler = null)
            => AppDomain.CurrentDomain.Patch(harmony => {
                if (harmony.GetPatchedMethods().All(m => m!=method)) {
                    harmony.Patch(method, prefix, postFix, transpiler);
                }
            });

how hard it is to test it since u there already?

krombipils commented 2 years ago

Give me a few minutes

krombipils commented 2 years ago

Your code is working fine. Unfortunately I cannot say anything about the performance on Azure, but at least I don't see any exceptions. The new version always creates a new HarmonyMethod instance (even if not required, because patch was already applied). I don't know if this is a (performance) problem. I guess we could instead pass a methodName and a Func returning the HarmonyMethod(), but no idea if this is really a better solution:

    public static Harmony Patch(this MethodInfo method, string patchName, Func<HarmonyMethod>? prefix = null,
        Func<HarmonyMethod>? postFix = null,
        Func<HarmonyMethod>? transpiler = null)
        => AppDomain.CurrentDomain.Patch(harmony =>
        {
            if (harmony.GetPatchedMethods().All(m => m.Name != patchName))
            {
                harmony.Patch(method, prefix?.Invoke(), postFix?.Invoke(), transpiler?.Invoke());
            }
        });
apobekiaris commented 2 years ago

i was afraid it might fail although it shouldn't, cannot put more energy on this though I will check against the name, however name can be doubles that why I attempted the metadata check. In any case I think we are fine we not a patch factory

apobekiaris commented 2 years ago

The pre-release 4.212.9.0 in the Reactive.XAF lab branch includes commits that relate to this task:

To minimize version conflicts we recommend that you use the Xpand.XAF.Core.All, Xpand.XAF.Win.All, Xpand.XAF.Web.All packages. Doing so, all packages will be at your disposal and .NET will add a dependecy only to those packages that you actually use and not to all (see the Modules installation-registrations youtube video).

Released packages: Xpand.Extensions v.4.212.9
Xpand.Extensions.Blazor v.4.212.9
Xpand.Extensions.Mono.Cecil v.4.212.9
Xpand.Extensions.Office.Cloud v.4.212.9
Xpand.Extensions.Office.Cloud.Google.Blazor v.4.212.9
Xpand.Extensions.Reactive v.4.212.9
Xpand.Extensions.XAF v.4.212.9
Xpand.Extensions.XAF.Xpo v.4.212.9
Xpand.TestsLib v.4.212.9
Xpand.TestsLib.Blazor v.4.212.9
Xpand.TestsLib.Common v.4.212.9
Xpand.TestsLib.EasyTest v.4.212.9
Xpand.TestsLib.Net461 v.4.212.9
Xpand.VersionConverter v.4.212.9
Xpand.XAF.Core.All v.4.212.9
Xpand.XAF.Modules.AutoCommit v.4.212.9
Xpand.XAF.Modules.Blazor v.4.212.9
Xpand.XAF.Modules.BulkObjectUpdate v.4.212.9
Xpand.XAF.Modules.CloneMemberValue v.4.212.9
Xpand.XAF.Modules.CloneModelView v.4.212.9
Xpand.XAF.Modules.Email v.4.212.9
Xpand.XAF.Modules.GridListEditor v.4.212.9
Xpand.XAF.Modules.HideToolBar v.4.212.9
Xpand.XAF.Modules.JobScheduler.Hangfire v.4.212.9
Xpand.XAF.Modules.JobScheduler.Notification v.4.212.9
Xpand.XAF.Modules.MasterDetail v.4.212.9
Xpand.XAF.Modules.ModelMapper v.4.212.9
Xpand.XAF.Modules.ModelViewInheritance v.4.212.9
Xpand.XAF.Modules.Office.Cloud.Google v.4.212.9
Xpand.XAF.Modules.Office.Cloud.Google.Calendar v.4.212.9
Xpand.XAF.Modules.Office.Cloud.Google.Tasks v.4.212.9
Xpand.XAF.Modules.Office.Cloud.Microsoft v.4.212.9
Xpand.XAF.Modules.Office.Cloud.Microsoft.Calendar v.4.212.9
Xpand.XAF.Modules.Office.Cloud.Microsoft.Todo v.4.212.9
Xpand.XAF.Modules.Office.DocumentStyleManager v.4.212.9
Xpand.XAF.Modules.OneView v.4.212.9
Xpand.XAF.Modules.PositionInListView v.4.212.9
Xpand.XAF.Modules.ProgressBarViewItem v.4.212.9
Xpand.XAF.Modules.RazorView v.4.212.9
Xpand.XAF.Modules.Reactive v.4.212.9
Xpand.XAF.Modules.Reactive.Logger v.4.212.9
Xpand.XAF.Modules.Reactive.Logger.Client.Win v.4.212.9
Xpand.XAF.Modules.Reactive.Logger.Hub v.4.212.9
Xpand.XAF.Modules.Reactive.Rest v.4.212.9
Xpand.XAF.Modules.RefreshView v.4.212.9
Xpand.XAF.Modules.SequenceGenerator v.4.212.9
Xpand.XAF.Modules.SuppressConfirmation v.4.212.9
Xpand.XAF.Modules.TenantManager v.4.212.9
Xpand.XAF.Modules.ViewEditMode v.4.212.9
Xpand.XAF.Modules.ViewItemValue v.4.212.9
Xpand.XAF.Modules.ViewWizard v.4.212.9
Xpand.XAF.Modules.Windows v.4.212.9
Xpand.XAF.Web.All v.4.212.9
Xpand.XAF.Win.All v.4.212.9

Please update the related Nuget packages and test if issues is addressed. These are nightly nuget packages available only from our NugetServer.

If you do not use these packages directly but through a module of the main eXpandFramework project, please wait for the bot to notify you again when integration is finished or update the related packages manually.

Thanks a lot for your contribution.