I have been trying to upgrade to the latest version (25.12) of the CAD adapter but now have a problem that I cannot write to the CAD image class custom properties.
This appears to be because in Version 25.7, the CustomPropeties dictionary has been changed to a Read Only Type.
Is this intentional ?
namespace Aspose.CAD.FileFormats.Cad
{
//
// Summary:
// Cad image class
[ComVisible(false)]
public class CadImage : Image, IHasEntities, IHasLayouts<CadLayout,
Version 25.6
//
// Summary:
// Gets or sets the custom properties.
//
// Value:
// The custom data.
public override Dictionary<string, string> CustomProperties { get; }
Version 25.7
//
// Summary:
// Gets or sets the custom properties.
//
// Value:
// The custom data.
public override IReadOnlyDictionary<string, string> CustomProperties { get; }
We are then unable to set anything in CustomProperties as it is Read Only
Thanks
@TITUS_Engineering
The change was introduced in v25.7. Starting with that release CadImage.CustomProperties is exposed as an IReadOnlyDictionary<string,string> and is no longer writable. This is intentional – the property now reflects the custom data that exists in the source CAD file and is not meant to be modified through the API.
If you need to add your own key/value pairs you have to use a different mechanism (e.g., store the data in the CAD file’s metadata or in a separate structure in your code). The CAD adapter does not provide a “set” method for CustomProperties anymore.
To proceed:
- Verify you are using the latest Aspose.CAD for .NET (v25.12) and that the same read‑only signature appears in the IntelliSense.
- If you require mutable custom data, keep it in your own
Dictionary<string,string> and associate it with the CadImage instance in your application logic.
- If you believe you need to write these values back into the CAD file itself, let us know the exact file format (DWG, DXF, etc.) and a minimal reproducible sample; we can check whether the format supports writing custom properties and, if so, whether a dedicated API exists.
Please provide a short code snippet that demonstrates how you are trying to set a property and the exact exception (if any) you receive, so we can confirm the behavior and advise further.
OK Thank you, so sounds like what we are doing is no longer supported.
We are using at least STL, STP, DXF and DWG files.
A brief snippet of the code is below:
using Aspose.CAD.FileFormats.Cad;
namespace Titus.TMS.PlugIn.CAD
{
public class AsposeCadAdapter : AsposeAdapter
{
private readonly CadImage _image;
public AsposeCadAdapter(CadImage image)
{
_image = image;
}
public override bool AddUpdatePackageAndSave(string pluginName, Stream stream, string TMINamespace, string TMINamespacePrefix, string TMIValue, string metadataXml, out bool hasExistingMetadata)
{
var saved = false;
hasExistingMetadata = false;
if (_image != null)
{
if (_image.CustomProperties.TryGetValue(TMINamespace, out var existingMetadata))
{
hasExistingMetadata = true;
_image.CustomProperties[TMINamespace] = metadataXml; ← Error 1
}
else
{
_image.CustomProperties.Add(TMINamespace, metadataXml); ← Error 2
}
_image.Save(stream);
saved = true;
}
return saved;
}
Error 1:
Severity Code Description Project File Line Suppression State Details
Error (active) CS0200 Property or indexer ‘IReadOnlyDictionary<string, string>.this[string]’ cannot be assigned to – it is read only PlugIn.CAD AsposeCADAdapter.cs
Error 2:
Severity Code Description Project File Line Suppression State Details
Error (active) CS1061 ‘IReadOnlyDictionary<string, string>’ does not contain a definition for ‘Add’ and no accessible extension method ‘Add’ accepting a first argument of type ‘IReadOnlyDictionary<string, string>’ could be found (are you missing a using directive or an assembly reference?) PlugIn.CAD AsposeCADAdapter.cs
@TITUS_Engineering,
Hi,
could you please check if AddCustomProperty/ChangeCustomProperty/RemoveCustomProperty for CadImage object are helpful?
Thank you for the suggestion, that looks like it might be what I need.
I will try and test this tomorrow.