Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Suggested answer

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

Posted on by 65

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

Categories:
  • Suggested answer
    JP-10061045-0 Profile Picture
    JP-10061045-0 8 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
    Yuri Mishin 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
    Valentine Motin 65 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
    Dan Kinsella 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
    Valentine Motin 65 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
    Dan Kinsella 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

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,696 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,490 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans