Solved

Error when trying to create a copy o Cache

  • 15 August 2022
  • 2 replies
  • 74 views

Userlevel 7
Badge +9

Hello Everyone,

 

I have a method that I am calling them in different graphs. To make this happen I have used Reflection and dynamic parameters. a part of my method require creating a copy of cache. If I copy and paste my code to each grapf it works just fine but this copy part wen is in the generic class raises the below error:

“Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'Member 'PX.Data.PXCache<PX.Objects.EP.EPApproval>.CreateCopy(PX.Objects.EP.EPApproval)' cannot be accessed with an instance reference; qualify it with a type name instead”

I have tried all 4 methods of copy that I new but no luck. Here are the methods I have tried:

 

//Method 1
EPApproval _approvalNext1 = Base.Approval.Cache.CreateCopy(approvalLast) as EPApproval;

//Method 2
EPApproval _approvalNext2 = Base.Caches[typeof(EPApproval)].CreateCopy(approvalLast) as EPApproval;

//Method 3
EPApproval _approvalNext3 = CallByName(Base.Approval.Cache, "CreateCopy", CallType.Get, approvalLast) as EPApproval;

// Method 4
EPApproval _approvalNext4 = CallByName(Base.Caches[typeof(EPApproval)], "CreateCopy", CallType.Get, approvalLast) as EPApproval;

 

Any help is greatly appreciated.

icon

Best answer by markusray17 15 August 2022, 23:13

View original

2 replies

Userlevel 6
Badge +5

I would try

PXCache<EPApproval>.CreateCopy(approvalLast) as EPApproval;

 

Edit: to add some context to why you are probably getting this error. PXCache is an abstract class with a CreateCopy method that is implemented in the child class PXCache<Node>. In the child class it calls a static CreateCopy method to actually implement the copying. If you are getting that error I suspect for one reason or another that instead of accessing the CreateCopy method via the PXCache class you are somehow referencing the PXCache<Node> static version of the method(most likely due to reflection and such). 

Userlevel 7
Badge +9

@markusray17 much appreciated. It works perfectly now. yayyyy :)

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved