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

No match for field with name objectSpaceProviders and flags Instance | NonPublic | Public | Static on type #940

Closed Siratigui closed 2 years ago

Siratigui commented 2 years ago

Hi,

objectSpaceProviders access has been changed by DevExpress.

application.GetFieldValue("objectSpaceProviders") is not longer working.

Now can not open the model because it can not find objectSpaceProviders.

You can access now access it from: application.GetFieldValue("_objectSpaceProviderContainer").GetFieldValue("_objectSpaceProviders")

I faced this error in WorldCreator and solved it by changing:

public WorldCreatorApplication(IObjectSpaceProvider objectSpaceProvider, IEnumerable<ModuleBase> moduleList)
        {
            ((IList<IObjectSpaceProvider>)GetOrCreateObjectSpaceProviderContainer().GetFieldValue("_objectSpaceProviders")).Add(objectSpaceProvider);
            var moduleBases = moduleList.Select(m => m.GetType().CreateInstance()).Cast<ModuleBase>().OrderBy(m => m.Name).Distinct().ToArray();
            foreach (var moduleBase in moduleBases)
            {
                if (Modules.FindModule(moduleBase.GetType()) == null)
                    Modules.Add(moduleBase);
            }
            ObjectSpaceCreated += Application_ObjectSpaceCreated;
        }

and

public static WorldCreatorObjectSpaceProvider Create(XafApplication application, bool threadSafe)
        {
            var worldCreatorObjectSpaceProvider = application.ObjectSpaceProviders.OfType<WorldCreatorObjectSpaceProvider>().SingleOrDefault();
            if (worldCreatorObjectSpaceProvider != null)
            {
                worldCreatorObjectSpaceProvider.threadSafe = threadSafe;
                return worldCreatorObjectSpaceProvider;
            }

            ((IList<IObjectSpaceProvider>)application.GetFieldValue("_objectSpaceProviderContainer")
                .GetFieldValue("_objectSpaceProviders")).Add(new WorldCreatorObjectSpaceProvider());
            return Create(application, threadSafe);
        }

and

private void AddDynamicModulesObjectSpaceProviders()
        {
            var providerBuilder = new DatastoreObjectSpaceProviderBuilder(DynamicModules);
            providerBuilder.CreateProviders().Each(provider => ((IList<IObjectSpaceProvider>)Application.GetFieldValue("_objectSpaceProviderContainer")
                .GetFieldValue("_objectSpaceProviders")).Add(provider));
        }
Siratigui commented 2 years ago

In 22.1.302 version

apobekiaris commented 2 years ago

please send a PR where u have tessted your suggestions and they work for you and happy to send a build.

thanks for the understanding and help

apobekiaris commented 2 years ago

@vimarx since you also affected after @Siratigui PR could you also update us if his changes work for u for #939

Siratigui commented 2 years ago

It will take so much time for me to create a sample because the project is very customized. I think that you can face this error in any WorldCreator project.

apobekiaris commented 2 years ago

I do not want a sample, as I understand you modified the source right? can u push a PR with those modifications?

apobekiaris commented 2 years ago

nevermind just wanted you to take the credits for the fix, easier to do it myself. anyways feel free to PR any futures changes.

thnks again pushin in lab now

apobekiaris commented 2 years ago

i do not see how it relates with #939 maybe I missunderstood?

Siratigui commented 2 years ago

when opening the ModelDifference DetailView the expression application.GetFieldValue("objectSpaceProviders") is executed somewhere. application.GetFieldValue("objectSpaceProviders") is not valid anymore. you may change it anywhere it is called in the codes i guess.

apobekiaris commented 2 years ago

can u test in your WC code that this method works

public static IEnumerable<IObjectSpaceProvider> AddObjectSpaceProvider(this XafApplication application, params IObjectSpaceProvider[] providers) 
            => ((IList<IObjectSpaceProvider>)application.CallMethod("GetOrCreateObjectSpaceProviderContainer").GetFieldValue("_objectSpaceProviders")).AddRange(providers);

AddRange can be used from the Xpand.Extensions.XAF.XafApplicationExtensions namespace therefore the Xpand.Extensions.XAF

I want to use that method instead

apobekiaris commented 2 years ago

eXpand.lab release 22.1.302.1 includes commit that relate to this task:

Please test if it addresses the problem. If you use nuget add our LAB NugetServer as a nuget package source in VS.

To minimize version conflicts we recommend that you switch to PackageReference format and use only the eXpandAgnostic, eXpandWin, eXpandWeb 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).

Thanks a lot for your contribution.

apobekiaris commented 2 years ago

AddRange can be used from the Xpand.Extensions.XAF.XafApplicationExtensions namespace therefore the Xpand.Extensions.XAF

or simply if u do not have dependecies is like this

           public static partial class LinqExtensions{
        public static T[] AddRange<T>(this IEnumerable<T> source,IEnumerable<T> enumerable,bool ignoreDuplicates=false) 
            => source is IList<T> list
                    ? enumerable.Where(arg => !ignoreDuplicates || !source.Contains(arg)).Execute(list.Add).ToArray()
                    : source.AddToArray(enumerable, ignoreDuplicates);

        public static void Add(this IList source, object item, bool ignoreDuplicates=false) {
            if (!ignoreDuplicates || !source.Contains(item)) {
                source.Add(item);
            }
        }

        public static T[] AddToArray<T>(this IEnumerable<T> source, T item, bool ignoreDuplicates = false) {
            var enumerable = source as T[] ?? source.ToArray();
            return !ignoreDuplicates && enumerable.Any(arg => arg.Equals(item))
                ? enumerable : enumerable.Concat(item.YieldItem()).ToArray();
        }

        public static T[] AddToArray<T>(this IEnumerable<T> source, IEnumerable<T> items, bool ignoreDuplicates = false) 
            => items.SelectMany(arg => source.AddToArray(arg, ignoreDuplicates)).ToArray();

        public static T Add<T>(this IList<T> source, T item, bool ignoreDuplicates = false) {
            if (!ignoreDuplicates || !source.Contains(item)) {
                source.Add(item);
                return item;
            }

            return default;
        }

    }
Siratigui commented 2 years ago

objectspaceproviders

I tried the release in lab. I still get the same error when trying to open the modeldifference detailview due the xafApplication.GetFieldValue("objectSpaceProviders") in the picture above.

can you please change it wherever it is used.

apobekiaris commented 2 years ago

this release was send before your suggestion to replace everything and apparently we need one method to rule them all and not search and replace the universe so that why i asked what I asked previoslt

Siratigui commented 2 years ago
public static IEnumerable<IObjectSpaceProvider> AddObjectSpaceProvider(this XafApplication application, params IObjectSpaceProvider[] providers) 
            => ((IList<IObjectSpaceProvider>)application.CallMethod("GetOrCreateObjectSpaceProviderContainer").GetFieldValue("_objectSpaceProviders")).AddRange(providers);

I tested the method it works.

apobekiaris commented 2 years ago

cool I need to push both repositories though as thi is going to live in Xpand.XAF.Extensions package of the RX repositories. So give me 1 day or 2 there are works in progress in the RX repo

apobekiaris commented 2 years ago

The pre-release 4.221.1.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.221.1
Xpand.Extensions.Blazor v.4.221.1
Xpand.Extensions.Mono.Cecil v.4.221.1
Xpand.Extensions.Office.Cloud v.4.221.1
Xpand.Extensions.Office.Cloud.Google.Blazor v.4.221.1
Xpand.Extensions.Reactive v.4.221.1
Xpand.Extensions.XAF v.4.221.1
Xpand.Extensions.XAF.Xpo v.4.221.1
Xpand.TestsLib v.4.221.1
Xpand.TestsLib.Blazor v.4.221.1
Xpand.TestsLib.Common v.4.221.1
Xpand.TestsLib.EasyTest v.4.221.1
Xpand.VersionConverter v.4.221.1
Xpand.XAF.Core.All v.4.221.1
Xpand.XAF.Modules.AutoCommit v.4.221.1
Xpand.XAF.Modules.Blazor v.4.221.1
Xpand.XAF.Modules.BulkObjectUpdate v.4.221.1
Xpand.XAF.Modules.CloneMemberValue v.4.221.1
Xpand.XAF.Modules.CloneModelView v.4.221.1
Xpand.XAF.Modules.Email v.4.221.1
Xpand.XAF.Modules.GridListEditor v.4.221.1
Xpand.XAF.Modules.HideToolBar v.4.221.1
Xpand.XAF.Modules.JobScheduler.Hangfire v.4.221.1
Xpand.XAF.Modules.JobScheduler.Notification v.4.221.1
Xpand.XAF.Modules.MasterDetail v.4.221.1
Xpand.XAF.Modules.ModelMapper v.4.221.1
Xpand.XAF.Modules.ModelViewInheritance v.4.221.1
Xpand.XAF.Modules.Office.Cloud.Google v.4.221.1
Xpand.XAF.Modules.Office.Cloud.Google.Calendar v.4.221.1
Xpand.XAF.Modules.Office.Cloud.Google.Tasks v.4.221.1
Xpand.XAF.Modules.Office.Cloud.Microsoft v.4.221.1
Xpand.XAF.Modules.Office.Cloud.Microsoft.Calendar v.4.221.1
Xpand.XAF.Modules.Office.Cloud.Microsoft.Todo v.4.221.1
Xpand.XAF.Modules.Office.DocumentStyleManager v.4.221.1
Xpand.XAF.Modules.OneView v.4.221.1
Xpand.XAF.Modules.PositionInListView v.4.221.1
Xpand.XAF.Modules.ProgressBarViewItem v.4.221.1
Xpand.XAF.Modules.RazorView v.4.221.1
Xpand.XAF.Modules.Reactive v.4.221.1
Xpand.XAF.Modules.Reactive.Logger v.4.221.1
Xpand.XAF.Modules.Reactive.Logger.Client.Win v.4.221.1
Xpand.XAF.Modules.Reactive.Logger.Hub v.4.221.1
Xpand.XAF.Modules.Reactive.Rest v.4.221.1
Xpand.XAF.Modules.RefreshView v.4.221.1
Xpand.XAF.Modules.SequenceGenerator v.4.221.1
Xpand.XAF.Modules.SuppressConfirmation v.4.221.1
Xpand.XAF.Modules.TenantManager v.4.221.1
Xpand.XAF.Modules.ViewEditMode v.4.221.1
Xpand.XAF.Modules.ViewItemValue v.4.221.1
Xpand.XAF.Modules.ViewWizard v.4.221.1
Xpand.XAF.Modules.Windows v.4.221.1
Xpand.XAF.Web.All v.4.221.1
Xpand.XAF.Win.All v.4.221.1

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.

apobekiaris commented 2 years ago

eXpand.lab release 22.1.302.2 includes commit that relate to this task:

Please test if it addresses the problem. If you use nuget add our LAB NugetServer as a nuget package source in VS.

To minimize version conflicts we recommend that you switch to PackageReference format and use only the eXpandAgnostic, eXpandWin, eXpandWeb 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).

Thanks a lot for your contribution.

apobekiaris commented 1 year ago

eXpand.lab release 22.2.400.0 includes commit that relate to this task:

Please test if it addresses the problem. If you use nuget add our LAB NugetServer as a nuget package source in VS.

To minimize version conflicts we recommend that you switch to PackageReference format and use only the eXpandAgnostic, eXpandWin, eXpandWeb 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).

Thanks a lot for your contribution.