Casting exception While purchFormLetter runs in Batch(Server)

Hi ,

System.InvalidCastException: Unable to cast an object of type ‘Dynamics.Ax.Application.PurchFormLetter_PurchOrder’ to type 'Dynamics.Ax.Application.PurchFormLetter_PackingSlip.

to Dynamics.Ax.Application.Rep_SkmrImportProcess.Postshippingforrecpurchids () in Rep_SkmrImportProcess.postShippingForRecPurchIds.xpp: line 45

to Dynamics.Ax.Application.Rep_SkmrImportProcess.Processmvttype20 () in Rep_SkmrImportProcess.processMVTType20.xpp: line 38

to Dynamics.Ax.Application.Rep_SkmrImportProcess.Doprocess () in Rep_SkmrImportProcess.doProcess.xpp: line 29

to Dynamics.Ax.Application.Rep_ImportProcessor.Run () in Rep_ImportProcessor.run.xpp: line 82

to Dynamics.Ax.Application.Rep_ImpManager.Dorun () in Rep_ImpManager.doRun.xpp: line 87

to Dynamics.Ax.Application.Rep_ImpExpManager.Run () in Rep_ImpExpManager.run.xpp: line 38

to Dynamics.Ax.Application.BatchRun.runJobStaticCode (Int64 BatchID) in BatchRun.runJobStaticCode.xpp: line 54

to Dynamics.Ax.Application.BatchRun.runJobStatic (Int64 BatchID) in BatchRun.runJobStatic.xpp: line 13

to Batchrun :: runJobStatic (Object [])

to Microsoft.Dynamics.Ax.Xpp.ReflectionCallHelper.MakeStaticCall (Type Type, String MethodName, Object [] parameters)

to BatchIL.taskThreadEntry (Object threadArg)

Hi all ,

I m getting this exception while i run my batch in server ,but when i run the same batch in client it runs smoothly,

can anyone can suggest any solution,

You have a bug in code (assigning incompatible types) that X++ allows, but the CIL runtime doesn’t allow. Unfortunately you can’t trust X++ type control, as I demonstrated in (In)valid conversion.

Hi Martin,

Thank you for your guidance, as you said it was my code bug in obj casting ,purchFormLetter_PurchOrder class called by PurchFormLetter_PackingSlip object.

but i feels strange, why these things are ignored while running in client !!!

thank you

X++ and CIL are two different languages running in two completely different runtime environments.