web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Error in extension class causes compiler to crash

(1) ShareShare
ReportReport
Posted on by 122
Hi. Here is a summary of what I am trying to achieve. 
 
  1. I want to display a real field Sales Price in the InventOnHandItem form. 
  2. The Sales Price = Cost price * 1.25
  3. The Cost Price field is displayed by a system default method called AverageCostPriceUnit from the Data source on the form - InventSum
  4. The actual table InventSum does not have this method. It only exists on the Data source to the form InventOnhandItem. 
  5. I am trying to write a class with a method that will extend the existing method so that I can use AverageCostPriceUnit * 1.25 and display the result in my real field Sales Price.
  6. The code I wrote is as follows: 
7. I bind it to the control field Sales Price with data method field as Invent_Extension::calculatedUnitSalesPrice
 
8. When building this class, the compilation fails and it says X++ compiler exited unexpectedly with failure code -1. 
 
9. This does not happen if I delete/remove the class and the compiler completes successfully in that case.
 
I Appreciate your support/advice to know where I am going wrong and what can be done to fix the issue. 
 
 
 
 
 
The entire build log is as follows: 
 
Build started 08/12/2024 18:24:41.
Build step: Metadata validation started. Time: 08/12/2024 18:24:41
Build step: Metadata validation completed (581 ms). Time: 08/12/2024 18:24:41
Build step: X++ compilation started. Time: 08/12/2024 18:24:42
  : Compilation failed.
C:\AOSService\PackagesLocalDirectory\ApplicationCommon\ApplicationCommon\AxReference\Microsoft.Commerce.Flighting.Common.xml(0,0):  AssemblyFileNotFound: Assembly 'Microsoft.Xbox.Experimentation.Contracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d91bba2b903dc20f' failed to load because it was not found.
C:\AOSService\PackagesLocalDirectory\ApplicationSuite\Foundation\AxReference\Microsoft.Dynamics___vices.PricingEngine.xml(0,0):  AssemblyFileNotFound: Assembly 'Microsoft.Dynamics.Commerce.Runtime.Entities.AttributeBasedPricing, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' failed to load because it was not found.
C:\AOSService\PackagesLocalDirectory\ApplicationSuite\Foundation\AxReference\Azure.Core.xml(0,0):  AssemblyFileNotFound: Assembly 'System.Memory.Data, Version=1.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' failed to load because it was not found.
C:\AOSService\PackagesLocalDirectory\FleetManagement\FleetManagement\AxClass\Invent_Extension.xml(0,0):  UnhandledException: Abnormal termination with unhandled exception. Exception key: 79899e16-0eef-4884-b4b9-24e0227aadee. System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
   at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
   at System.Collections.Generic.List`1.get_Item(Int32 index)
   at Microsoft.Dynamics.AX.Framework.Xlnt.XppParser.Pass2.TypeResolver.ValidateFormNestedElementsExtensionOf(SemanticFormType semanticFormType, IEnumerable`1 extesionOfParamters)
   at Microsoft.Dynamics.AX.Framework.Xlnt.XppParser.Pass2.TypeResolver.CheckForExtensionClassConstraints(SymbolTable payload, ClassOrInterface classOrInterface)
   at Microsoft.Dynamics.AX.Framework.Xlnt.XppParser.Pass2.TypeResolver.VisitClassOrInterface(SymbolTable payload, ClassOrInterface classOrInterface)
   at Microsoft.Dynamics.AX.Metadata.XppCompiler.AstVisitor`2.VisitModelElement(TPayload payload, ModelElement modelElement)
   at Microsoft.Dynamics.AX.Framework.Xlnt.XppParser.Pass2.TypeResolver.VisitModelElement(SymbolTable payload, ModelElement modelElement)
   at Microsoft.Dynamics.AX.Metadata.XppCompiler.AstVisitor`2.VisitCompilationUnit(TPayload payload, CompilationUnit compilationUnit)
   at Microsoft.Dynamics.AX.Metadata.XppCompiler.AstVisitorWithDiagnostics`2.VisitCompilationUnit(TPayload payload, CompilationUnit compilationUnit)
   at Microsoft.Dynamics.AX.Framework.Xlnt.XppParser.Pass2.TypeResolverPipelineEntry.Execute(CompilationUnit compilationUnit, TypeResolver resolver)
   at Microsoft.Dynamics.AX.Framework.Xlnt.XppParser.Pass2.Pipeline.ExecutePipeline(CompilationUnit compilationUnit, IDiagnosticSink diagnostics, IXppcMetadataProvider metadataProvider, Stack`1 context)
   at Microsoft.Dynamics.AX.Framework.Xlnt.XppParser.Pass2.MultipassAdministrator.RunPipeline(CompilationUnit compilationUnit, Pipeline pipeline)
   at Microsoft.Dynamics.AX.Framework.Xlnt.ILGenerator.ClassTypeGenerator.<>c__DisplayClass6_0.<RunPipeline>b__0(String name)
   at Microsoft.Dynamics.AX.Metadata.XppCompiler.ParallelCrashDumpUtil.<>c__DisplayClass1_0`1.<ForEach>b__2(T t)
   at System.Threading.Tasks.Parallel.<>c__DisplayClass42_0`2.<PartitionerForEachWorker>b__1()
   at System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask)
   at System.Threading.Tasks.Task.<>c__DisplayClass176_0.<ExecuteSelfReplicating>b__0(Object ).
 X++ compiler exited unexpectedly with failure code -1.
Build step: X++ compilation completed (1702 ms). Time: 08/12/2024 18:24:43
Build step: Best practice check started. Time: 08/12/2024 18:24:43
Build step: Best practice check completed (481 ms). Time: 08/12/2024 18:24:44
Build completed (2862 ms). Time: 08/12/2024 18:24:44
 
 
I have the same question (0)
  • Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at
    Unfortunately, I don't see your code. Please post it once more.
     
    Do I understand correctly that the point 7 isn't relevant to the problem because you get an error when you try to compile your Invent_Extension class?
     
    (Moved from Dynamics AX forum.)
  • VJ VM Profile Picture
    122 on at
    Hi Martin. Thanks for getting back to me. 
     
    The code is as follows: 

    [ExtensionOf(formDataSourceStr(InventOnHandItem))]
    final class Invent_Extension
    {
        public display real calculatedUnitSalesPrice()
        {
            real AvgCost = InventSum.averageCostPriceUnit(); // calling the averageCostPriceUnit method in InventSum Data Source
            real UnitSalesPrice = AvgCost * 1.25;
            return UnitSalesPrice;
        }
    }
     
    Yes, point 7 is just mentioning the form control and how I called the above method from that control. 
     
    Appreciate your support and thanks again!
  • Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at
    I see a bug already on the first line. formDataSourceStr() method requires two parameters: the form name and the data source name.
  • VJ VM Profile Picture
    122 on at
    Thanks Martin. I tried this earlier and I am getting the following error when adding the two parameters. 
     
    Table 'InventSum' does not contain a definition for method 'averageCostPriceUnit' and no extension method 'averageCostPriceUnit' accepting a first argument of type 'InventSum' is found on any extension class. 
     
    I am not able to open the method in DataSource InventSum to see the code in AverageCostPriceUnit either.
  • Suggested answer
    Waed Ayyad Profile Picture
    9,039 Super User 2025 Season 2 on at
    Hi,
     
    The syntax to create an extension of form DataSource should be:
    [ExtensionOf(formDataSourceStr(YourForm, YourDataSourceName))]
    Where you define inventSum? Is it data source on the same form? What do you mean by you can't open the code? Is it a standard method?

    Thanks,
    Waed Ayyad
    If this helped, please mark it as "Verified" for others facing the same issue
     
  • Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at
    It's good to hear that we've resolved the problem that this thread was about ("Error in extension class causes compiler to crash"). Please don't forget to verify the answer.
     
    Feel free to create new threads for other questions; give them descriptive title and give us enough details about your problem.

    By the way, inventSum variable holds a record of InventSum table; the data source is in InventSum_ds (element.InventSum_ds) variable instead.
  • VJ VM Profile Picture
    122 on at
    Dear Waed Ayyad, 
     
    Thanks for your reply. As I mentioned in my original post, InventSum is the data source on the form InventOnHandItem. The method AverageCostPriceUnit exists only in the InventSum data source on the form and not on the actual InventSum Table. Yes, AverageCostPriceUnit is a standard method on the Data source and I cannot see its code. 
     
    Dear Martin, 
     
    I believe I tried to be as descriptive & provide as many details as I could in my post. I am still facing the same compile errors as the original post, despite correcting the bug. Is the compile error being caused by the class or could there be something else that's going wrong?
     
    Thanks!
  • Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at
    Something what you said must be wrong. The previous information you gave us was that compiler is not crashing with "Index was out of range" anymore; you said it worked and pointed out to a bug in your code ("Table 'InventSum' does not contain a definition for method...").
     
    But now you're claiming the error is still the same as on the beginning.
     
    It can't be all true at the same time.
  • VJ VM Profile Picture
    122 on at
    Dear Martin, Thanks for your response. I think there might have been a misunderstanding. I didn't say that the "compiler is no longer crashing with 'Index was out of range'" or that "it worked." I only mentioned the new error that appeared right after I fixed the first bug you found, even before running the build again. It was only after your last message, where you asked me to mark the answer, that I rebuilt it and discovered the original errors were also still present.
     
    I also realize now that the title of my post might have been misleading, as I needed help with the extension class & method itself, and the compiler crashing was just part of the issue. I appreciate your patience with me, as I am new to the scene and to community rules on creating/closing topics to the point. My intentions were not to mislead/confuse anyone or to waste anyone's time. Thanks!
     
  • Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at
    Okay, so you're saying that you're still unable to compile your code, because the compiler crashes with the following error on Invent_Extension class:
     
    Abnormal termination with unhandled exception. Exception key:
    79899e16-0eef-4884-b4b9-24e0227aadee.
    System.ArgumentOutOfRangeException: Index was out of range. Must be
    non-negative and less than the size of the collection.

    Parameter name: index
     
    Please confirm that it's exactly the same error.
     
    Now, please comment out the whole calculatedUnitSalesPrice() and try it again. Does the compiler succeeds? Even if you restart Visual Studio. If it doesn't, it'll be clear that your problem isn't related to your code in the method.
     
    If it works, uncomment the method but let the body just return zero, instead of calling any of your code. Does it compile now?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 449 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 422 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans