Add extended attribute on sheet with atrribute already existing

The following code will allow us to create the extended resource attribute and added the values the first time through. If we try to process the same file again it fails with “key already exists” with version 9.3.0 of Aspose.Tasks


SetParentTaskCost(Project.RootTask);
bool aliasExist = false;
ExtendedAttributeDefinition resourceTextAttr = new ExtendedAttributeDefinition();
            resourceTextAttr.Alias = <span style="color:#2aa198;">"StandardName"</span><span style="color:#657b83;">;</span>
            resourceTextAttr.FieldName = <span style="color:#2aa198;">"Text30"</span><span style="color:#657b83;">;</span>
            resourceTextAttr.ElementType = <span style="color:#cb4b16;">ElementType</span>.Resource<span style="color:#657b83;">;</span>
            resourceTextAttr.CfType = <span style="color:#cb4b16;">CustomFieldType</span>.Text<span style="color:#657b83;">;</span>
            resourceTextAttr.FieldId = <span style="color:#cb4b16;">Convert</span>.ToInt32<span style="color:#657b83;">(</span><span style="color:#cb4b16;">ExtendedAttributeResource</span>.Text30<span style="color:#657b83;">)</span>.ToString<span style="color:#657b83;">(</span><span style="color:#cb4b16;">CultureInfo</span>.InvariantCulture<span style="color:#657b83;">);</span>
            <span style="color:#477786;">//resourceTextAttr.LookupUid = Guid.NewGuid().ToString();</span>
            Project.ExtendedAttributes.Add<span style="color:#657b83;">(</span>resourceTextAttr<span style="color:#657b83;">);</span>



            <span style="color:#719a07;">foreach</span> <span style="color:#657b83;">(</span>Aspose.Tasks.<span style="color:#cb4b16;">Resource</span> res <span style="color:#719a07;">in</span> Project.Resources<span style="color:#657b83;">)</span>
            <span style="color:#657b83;">{</span>
                
                <span style="color:#719a07;">string</span> codeString = res.Get<span style="color:#657b83;">(</span><span style="color:#cb4b16;">Rsc</span>.Code<span style="color:#657b83;">);</span>
                <span style="color:#cb4b16;">ProjectRateType</span> projectRateType = <span style="color:#719a07;">null</span><span style="color:#657b83;">;</span>
                <span style="color:#cb4b16;">Guid</span> ID = <span style="color:#cb4b16;">Guid</span>.Empty<span style="color:#657b83;">;</span>
                <span style="color:#cb4b16;">Guid</span>.TryParse<span style="color:#657b83;">(</span>codeString<span style="color:#657b83;">,</span> <span style="color:#719a07;">out</span> ID<span style="color:#657b83;">);</span>
                   
                projectRates.TryGetValue<span style="color:#657b83;">(</span>ID<span style="color:#657b83;">,</span> <span style="color:#719a07;">out</span> projectRateType<span style="color:#657b83;">);</span>
                <span style="color:#719a07;">if</span> <span style="color:#657b83;">(</span>projectRateType!=<span style="color:#719a07;">null</span><span style="color:#657b83;">)</span>
                <span style="color:#657b83;">{</span>
                    <span style="color:#cb4b16;">ExtendedAttribute</span> thisItem = <span style="color:#719a07;">new</span> <span style="color:#cb4b16;">ExtendedAttribute</span><span style="color:#657b83;">();</span>
                    thisItem.FieldId = resourceTextAttr.FieldId<span style="color:#657b83;">;</span>
                    thisItem.Value = projectRateType.RateStandardName<span style="color:#657b83;">;</span>
                    res.ExtendedAttributes.Add<span style="color:#657b83;">(</span>thisItem<span style="color:#657b83;">);</span>
                <span style="color:#657b83;">}</span>
                <span style="color:#719a07;">else</span>
                <span style="color:#657b83;">{</span>
                    <span style="color:#cb4b16;">ExtendedAttribute</span> thisItem = <span style="color:#719a07;">new</span> <span style="color:#cb4b16;">ExtendedAttribute</span><span style="color:#657b83;">();</span>
                    thisItem.FieldId = resourceTextAttr.FieldId<span style="color:#657b83;">;</span>
                    thisItem.Value = res.Get<span style="color:#657b83;">(</span><span style="color:#cb4b16;">Rsc</span>.Name<span style="color:#657b83;">);</span> <span style="color:#657b83;">;</span>
                    res.ExtendedAttributes.Add<span style="color:#657b83;">(</span>thisItem<span style="color:#657b83;">);</span>
                <span style="color:#657b83;">}</span>

            <span style="color:#657b83;">}</span></pre></div>

Hi Sherri,

Thank you for writing to Aspose Support team.

Can you please share a working code sample that we can use to investigate the issue further? The above code is incomplete and does not compile at our end due to errors. I would also request you to please share the exact nature of problem if you want to add a new extended attribute or the same? We need these details for assisting you further.