Explain this cast &*#($&#

So I normally use Erp.Tablesets.PartMtlRow in VisualStudio externally with no problems.

When trying to use it within E10 I get this error:
Unable to cast object of type ‘PartMtlRow’ to type ‘Erp.Tablesets.PartMtlRow’.

Ok, so where else is PartMtlRow defined?

	foreach (PartMtlRow row in adapterBOM.BomSearchData.PartMtl.Rows)
            {


                if(row.PartNum == PartNum)
                {
					PartInfo thePart = new PartInfo();
					thePart.PartNum = PartNum;
					thePart.MtlSeq = row.MtlSeq;
					thePart.UOM = row.UOMCode;
					
                }
            }
	
``

Erp.BO.BomSearchDataSet.PartMtlRow

2 Likes

Thanks, let me give that a shot!

I’ve run into this issue several times. I am curious to know the reason behind the different classes with the same name.

Nailed it, thanks sir!

Much prettier:

		var arow = (from Erp.BO.BomSearchDataSet.PartMtlRow r in adapterBOM.BomSearchData.PartMtl.Rows 
		where r.MtlPartNum == PartNum
		select r).FirstOrDefault();
		
		if(arow == null) throw new Exception("Couldn't find PartNum: "+PartNum+" in the BOM");
		
					PartInfo thePart = new PartInfo();
					thePart.PartNum = PartNum;
					thePart.MtlSeq = arow.MtlSeq;
					thePart.UOM = arow.UOMCode;
					return(thePart);