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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Batch task failed: Object reference not set to an instance of an object

(1) ShareShare
ReportReport
Posted on by 49
I am trying to make batch job but every time I run it I get this error log
any batch give the same error even as sample as this batch: 
 DialogField dialogMyParameter;

    str myParameter = "Default value";

    #define.CurrentVersion(1)
    #localmacro.CurrentList
        myParameter
    #endmacro

    public container pack()
    {
        // This method is used by batch platform to serialize batch parameters in a container
        return [#CurrentVersion, #CurrentList];
    }

    public boolean unpack(container _packedClass)
    {
        // This method is used by batch platform to deserialize batch parameters from stored 
        // batch parameter container

        Integer version = RunBase::getVersion(_packedClass);
        container packedData;

        switch (version)
        {
            case #CurrentVersion:
                [version, #CurrentList] = _packedClass;
                break;
            default:
                return false;
        }

        return true;
    }

    public Object dialog()
    {
        // This method is invoked when user opens batch parameter dialog
        // It helps to add parameters to batch class and set their default value

        DialogRunbase dialog = super();

        dialogMyParameter = dialog.addField(enum2Str(Types::Integer), "My Parameter");

        // Set a default value of parameter
        dialogMyParameter.value(myParameter);

        return dialog;
    }

    public boolean getFromDialog()
    {
        // This method is invoked by batch platform to read the values of parameters from batch 
        // parameter dialog method
        myParameter = dialogMyParameter.value(); 

        return super();
    }

    public void run()
    {
        // This method is the entry point for the batch class

        info("Batch job started!");
        // Access the parameter value entered by the user
        info("My Parameter: " + this.myParameter);
        // Your main batch logic goes here
        info("Batch job completed!");
    }

    public static void main(Args _args)
    {
        // This method is used to create an instance of the batch class, prompt the user 
        // for input using dialog, and then execute the batch job using run().

        MyBatchClass batch = new MyBatchClass();
        if (batch.prompt())
        {
            batch.run();
        }
    }
 
Categories:
I have the same question (0)
  • Kareem Profile Picture
    49 on at
    note:
    this error only show up when I tick this
  • Martin Dráb Profile Picture
    239,063 Most Valuable Professional on at
    You can use the debugger to find out where the error comes from. Note that you'll likely need to attach the debugger to batch.exe.
     
    Of course, make sure that your application is fully compiled. Also, you should think about what changed at (before) the moment when the error start occurring.
  • Anton Venter Profile Picture
    20,657 Super User 2026 Season 1 on at
    In addition to what Martin has said. Is the code complete? Looking at the code, I don't see any reason why this code would throw an "Object reference not set to an instance of an object" error. Is it extending from RunbaseBatch?
  • Layan Jwei Profile Picture
    8,165 Super User 2026 Season 1 on at
    Hi,

    Please debug as Martin said and let us know where it fails exactly.
  • Verified answer
    Kareem Profile Picture
    49 on at
    The main problem was because I was extending RunbaseBatch when I changed to sysoperation it got solved thanks guys

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 710

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 465 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 317 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans