Hi.
I'm migrating an application from
- LLBLGenPro 1.0.2005.1 release
- .NET Framework 1.1
- SD.LLBLGen.Pro.ORMSupportClasses.NET11.dll release 1.0.20051.60112
to
- LLBLGenPro 2.6 release
- .NET Framework 2.0
- SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll release 2.6.8.1211
The following code raises an Exception:
IEntityCollection2 contenuti = GetCurrentElementiCapitolato();
EntityCollection contenutiToAdd = new EntityCollection(new ContenutoCapitolatoEntityFactory());
using(frmSelezionaElementiCapitolati frm = frmSelezionaElementiCapitolati.NewInstance(this))
{
frm.VisualizzaDialogForm(ref contenutiToAdd);
}
contenuti.AddRange(contenutiToAdd as IEntityCollection2);
When the last line of code is executed, an Exception is raised. The stack trace is the following:
SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase2`1.SD.LLBLGen.Pro.ORMSupportClasses.IEntityCollection2.AddRange(IEntityCollection2 c)
in Stain.ASO.STAINPlus.forms.capitolati.frmCapitolato.AggiungiElementiChimici() in C:\usr\AsoSiderurgica\STAIN+\winsup_dev\Stain.ASO.STAINPlus\forms\capitolati\frmCapitolato.cs:riga 1743
and the Exception message is the following:
"c isn't of the right type"
Just to explain the code:
- GetCurrentElementiCapitolato() is a private method that returns a reference to an EntityCollection<ContenutoCapitolatoEntity>
- _frmSelezionaElementiCapitolati _is a form that allows the user to select a list of ContenutoCapitolatoEntity entities
- if I inspect the content of _contenutiToAdd _jus before the last line of code is executed, I can see that it is correctly populated
In the 1.0.2005.1 code version, the variable contenuti was of EntityCollection type.
If I change the code like this
IEntityCollection2 contenuti = GetCurrentElementiCapitolato();
EntityCollection contenutiToAdd = new EntityCollection(new ContenutoCapitolatoEntityFactory());
using(frmSelezionaElementiCapitolati frm = frmSelezionaElementiCapitolati.NewInstance(this))
{
frm.VisualizzaDialogForm(ref contenutiToAdd);
}
foreach (ContenutoCapitolatoEntity contenuto in contenutiToAdd)
{
contenuti.Add(contenuto);
}
it works correctly.
I can't understand what I'm doing wrong.
Thanks a lot for any help.