Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

An Application object of type 'Codeunit' with name XXX is already declared

(1) ShareShare
ReportReport
Posted on by 71

Hello Everyone !

Right now i'm moving my company's code from Dynamics nav 2018 to Business Central 16.

I'm working with VS Code, so that means a brand new environment to discover.
Right now, i'm having troubles with one of our most used Codeunits.

pastedimage1596699436234v1.png

VS Code is telling me that "An application object of type Codeunit with name Toolbox is already declared'. Except it's not.

I've checked, neither the name nor the id are used anywhere in my code.

In some other codeunits, i still can declare my Toolbox codeunit but in some others i simply can't. It causes a lot of problems in my code, since i'm getting everywhere errors about procedures being non existant in my toolbox codeunit (except they are).

I've searched for similar issues, learned it could be due to UNC paths but what my coworker and i tried didn't seem to do the trick.

Has anyone else experienced this and would be willing to share their solution ? 

Thanks in advance

  • Suggested answer
    JP-10061045-0 Profile Picture
    10 on at
    An Application object of type 'Codeunit' with name XXX is already declared
    For me none of the suggested solutions worked. What helped me was the answer in this blog https://www.365cycle.nl/dynamics/an-application-object-of-type-x-is-already-declared/
     
    Solution was to map the network path that the project resides on to a drive letter.
  • Suggested answer
    Yuri Mishin Profile Picture
    20 on at
    RE: An Application object of type 'Codeunit' with name XXX is already declared

    I have got the same problem today.

    That's obviously not a problem of the compiler, the app can be compiled and published without an error.

    Solution (worked for me):

    - disable Visual Studio Code extension "AL Language".

    - enable Visual Studio Code extension "AL Language".

    - wait till it loads and parses the source code.

  • Valentine Motin Profile Picture
    71 on at
    RE: An Application object of type 'Codeunit' with name XXX is already declared

    I don't see anything that could look like a second declaration. However, there is something i think is weird : whenever i go to any object that uses my Toolbox codeunit at some point and click on "Go to definition", sometimes it will send me on my Toolbox codeunit - as expected - but sometimes it will send me in the local variables of a procedure from a codeunit that has absolutely nothing to do with the first object nor with the Toolbox codeunit. It's not random because it's always the same procedure in the same codeunit, but i don't see anything wrong with my codeunit declaration.

  • Suggested answer
    Dan Kinsella Profile Picture
    466 on at
    RE: An Application object of type 'Codeunit' with name XXX is already declared

    Try using the search tool from the activity pane on the left on that object name, perhaps you have it declared in another file somewhere in your project workspace.

    When you choose a pre/post fix, I'd recommend the CRS extension (available from the VS Code marketplace) for automatically updating the prefix and renaming al files to MS standards. Really helps to keep everyone working constantly.

  • Valentine Motin Profile Picture
    71 on at
    RE: An Application object of type 'Codeunit' with name XXX is already declared

    Hi Dan,

    I've already tried to restart VS Code but unfortunately this didn't change anything.

    Primus Wine is the extendion i'm developping, it's a really large project that has existed since before Nav 2013, and moved from version to version but my codeunit doesnt seem to be conflicting with another extension. When i try to rename my object, it seems to solve the issue so i dont know where the issue can come from.

    I'll talk to my team about the prefixing, thanks for the insight !

  • Dan Kinsella Profile Picture
    466 on at
    RE: An Application object of type 'Codeunit' with name XXX is already declared

    Hi Valentine,

    Is Primus-wine the extension you're developing?

    It might just be the AL extension getting in a mess.. this does happen often on larger projects and can usually be resolved by shutting down VS Code and reopening it.

    You'll want to look into name prefixing of your objects to stop name conflicts with other extensions in either case: docs.microsoft.com/.../apptest-prefix-suffix

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,145 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,923 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans