SBX - Search With Button

SBX - Forum Post Title

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

Microsoft Dynamics AX Forum

Jose Alonso Foubelo asked a question on 14 Sep 2018 4:48 AM
My Badges

Question Status

Unanswered

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. 

Reply
Boris Diroo responded on 14 Sep 2018 8:09 AM
My Badges

Hello Jose,

You might want to try a DataDictionary Sync, Restart AOS then do a Full CIL.

Hope this helps!

Reply
Jose Alonso Foubelo responded on 17 Sep 2018 5:33 AM
My Badges

Hi Boris,

First of all, thanks for your help. We forgot trying to Sync, and when we have tried it today we have got another error:

 

System.NullReferenceException: Object reference not set to an instance of an object  

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

at Dynamics.Ax.Application.NumberSequenceModuleSetup.Loaddata() in NumberSequenceModuleSetup.loadData.xpp:line 6  

at Dynamics.Ax.Application.SysSetupInstaller.Writealldata() in SysSetupInstaller.writeAllData.xpp:line 19  

at Dynamics.Ax.Application.SysSetupInstaller.Run() in SysSetupInstaller.run.xpp:line 7  

at Dynamics.Ax.Application.SysSetupInstaller.loadPartitionData(Object[] _c) in SysSetupInstaller.loadPartitionData.xpp:line 3  

at SysSetupInstaller::loadPartitionData(Object[] )  

at Microsoft.Dynamics.Ax.Xpp.ReflectionCallHelper.MakeStaticCall(Type type, String MethodName, Object[] parameters)  

at Microsoft.Dynamics.Ax.Xpp.PredefinedFunctions.runAsInvoke(String className, String staticMethodName, Object[] parms, Object[]& exportInfolog)

 


We have tried to execute the code in NumberSequenceModuleSetup.loadData in a job, but in the job there is no error (¿?)

We have tried to change the code in NumberSeqApplicationModule.loadAll to get the classid which fails in line 60, but the syncro doesn't take our changes into account.

We have look for this error, and we have seen this two topics:

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

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

The first one has the same error, the second not same, but similar one. They suggest to compiling the class and child classes, doing a full CIL compilation and restart AOS.

We have tried it, but when trying the full CIL we are having the same problem we had at the beggining with the CIL:

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

 

I think we have entered in a Infinite loop :-)

In the second link, Martin Dràb suggest to debug to find the problem, but we are not sure about how we can debug the syncro process. Any suggestion?

Regards,

Kala

Reply
Nikolaos Mäenpää responded on 17 Sep 2018 5:43 AM

Just put a breakpoint in the method where the error comes from and start synchronization.

Reply
Nikolaos Mäenpää responded on 17 Sep 2018 5:45 AM

Did you perhaps copy a database from another AX environment into this environment? That could explain the issues. Basically if you do copy a database, you need to copy both business and model databases, unless the id values between the environments are already in sync.

Reply
Jose Alonso Foubelo responded on 17 Sep 2018 5:51 AM
My Badges

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

Reply
Nikolaos Mäenpää responded on 17 Sep 2018 5:59 AM

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.

Reply
Jose Alonso Foubelo responded on 17 Sep 2018 6:07 AM
My Badges

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

Reply
Jose Alonso Foubelo responded on 17 Sep 2018 6:43 AM
My Badges

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

Reply
Jose Alonso Foubelo responded on 17 Sep 2018 10:14 AM
My Badges

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

Reply
Nikolaos Mäenpää responded on 17 Sep 2018 11:41 AM

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.

Reply
Jose Alonso Foubelo responded on 19 Sep 2018 4:33 AM
My Badges

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? :-)

Reply
Nikolaos Mäenpää responded on 19 Sep 2018 4:36 AM

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.

Reply
Jose Alonso Foubelo responded on 19 Sep 2018 6:21 AM
My Badges

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.

Reply

SBX - Two Col Forum

SBX - Migrated JS