Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

CIL Generation Error: An item with the same key has already been added

Posted on by 40

Hi all,

I have a problem with a CIL compilation in a AX2012 R3 CU13. The error message is the next one:

System.ArgumentException: An item with the same key has already been added.

at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)

   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)

   at Microsoft.Dynamics.Ax.Xpp.ILGenerator.TraverseTable(XmlNode classNode, TypeBuilder typeBuilder)

   at Microsoft.Dynamics.Ax.Xpp.ILGenerator.DefineType(XmlNode classNode)

   at Microsoft.Dynamics.Ax.Xpp.ILGenerator.GenerateXppModule()

The CIL generator found errors and could not save the new assembly.

Errors: 1

Warnings: 0

 

After doing some test, I have tried twice the complete usual solution for this kind of CIL errors:

1. Stop AOS

2. Backup and delete XppIL folder

3. Truncate SYSXPPASSEMBLY table in SQL.

4. Start AOS

5. Full Application Compile (No errors)

6. Run FULL CIL

The error message persists. I have read some topics with a similar problem:

https://community.dynamics.com/ax/f/33/t/220041

https://community.dynamics.com/ax/f/33/t/225050

In this two topics, they finally found a duplicate field, but in their error stack they had "at Microsoft.Dynamics.Ax.Xpp.XppTableInfo.AddField(Int32 id, String propertyName, XppPropertyInfo field)", in mine I have "at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)". Does it help to know about what type of element i being duplicate?

Trying to search the duplicate element, we have tried the script proposed in this thread:

https://community.dynamics.com/ax/f/33/t/120387

SELECT count(Name) AS ElementCount, Name FROM ModelElement

where ElementType <> 12 AND ElementType <> 13 AND ElementType <> 14 AND ElementType <> 15 AND ElementType <> 22

AND ElementType <> 23 AND ElementType <> 24 AND ElementType <> 35 AND ElementType <> 36 AND ElementType <> 42

AND ElementType <> 43 AND ElementType <> 66 AND ElementType <> 113 AND AxId <> 0

 group by Name having count(Name)  > 1

There is no result for this select. We have tried to modify it, but it didn't work for us.

Now, we are empty of ideas. Is there any way to search the duplicated element? How can we know what kind of element is being duplicated or its name?

Thanks all for your help. 

*This post is locked for comments

  • RE: CIL Generation Error: An item with the same key has already been added

    Finally, we didn't find a way to resolve the problem with the environment and the customer agreed with the proposal of refresing business and data model from production environment.

    In any case, thanks all for your help :-)

  • RE: CIL Generation Error: An item with the same key has already been added

    Hi Nikolaos,

    It's an environment created by a previous partner and I am not sure if it has problems at the begining, but we have not a useful backup to try to revert the situation. We are trying to repair the environment because the customer asked to do this if posible, it seems they have same useful data or code modifications they want to keep safe.

    Our proposal if we are not able to repair this environment, goes in the same way yor propose:

    1 - Export useful data or code of this environment

    2 - Refresh the environment with business and data model from production environment

    3 - Only when we are sure that the environment works fine again, try to import the exported data/code in step one and try to compile again.

  • nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: CIL Generation Error: An item with the same key has already been added

    Maybe the sync process is executed in CIL. In which case you can't change the code because that would require succesful generation of CIL.

    Anyway it might be that there is no useful information to be found there.

    Has this environment worked in the past? Maybe you can revert to backups that were taken when it was working?

    If it never worked, you might need to refresh it with databases (business data and model) from an environment that works.

  • RE: CIL Generation Error: An item with the same key has already been added

    Hi!

    We have tried putting code in the class, but we don't get any information… it seeems like the syncronize proccess doesn't saw the changes. The breakpoint added was ignored, and the added code was ignored too.

    The syncronization says that the error is on:

    at Dynamics.Ax.Application.NumberSeqApplicationModule.loadAll() in NumberSeqApplicationModule.loadAll.xpp:line 60

    We are adding new lines in the code before that line (breakpoint sentence in code, some info sentences to get more information about the error...) but the syncronization still says that the error is in line 60, that's why I think that the added code is being ignored.

    Anyone has any new idea to atack this problema, please? :-)

  • nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: CIL Generation Error: An item with the same key has already been added

    Hi Jose,

    unfortunately I don't have experience in debugging the db sync.

    Maybe you could try to put some code that writes the interesting details into infolog in the method that fails. Then you would at least know what exactly causes this null reference error.

  • RE: CIL Generation Error: An item with the same key has already been added

    Hi again Nikolaos,

    No luck, we have restart the AOS to ensure that the value of the debugging of code that runs on AOS parameter was enable, but we are still not able to debug it, the debugger doesn´t stop in the breakpoint. We have found two sources where they speak about executing the syncro from X++ and we are trying to do this, maybe in that way we can debug it… but I'm not sure.

    Any suggestion?

    Regards,

    Kala

  • RE: CIL Generation Error: An item with the same key has already been added

    Hi again Nikolaos,

    I have checked the AX Server Configuration Utility and theoretically the debugging of code that runs in AOS is enabled (and there is only one AOS)

    Just in case, I will check/uncheck the option again and try once more.

    Do you know if there is any way to call the Syncronicación from the x++ code if I don't get it from the normal syncro proccess?

    Regards,

    Kala

  • RE: CIL Generation Error: An item with the same key has already been added

    Hi Nikolaos,

    Thanks for this second answer too. It's an environment created by a previous partner and I don't know how it was created. It is used some time ago, so I hope it was created copying model and data :-S

    Regards,

    Kala

  • nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: CIL Generation Error: An item with the same key has already been added

    Have you enabled debugging of code that runs on AOS? This is managed in AX Server Configuration Utility.

    Also, did you copy db from another environment? If yes, I think debugging is not needed but you must copy both model db and business db.

  • RE: CIL Generation Error: An item with the same key has already been added

    Hi Nikolaos,

    Thanks for you reply. We have put the breakpoint in NumberSeqApplicationModule.loadAll.xpp: line 60, but the debugger doesn't stop.

    Regards,

    Kala

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans