In a project under development, it provides an API that converts dwg files into svg in real time.
For API’s performance test, converting certain files in parallel from the test code results in the error below.
error1
Upload Failed
System.AggregateException: One or more errors occurred. (Image export failed. An item with the same key has already been added. Key: 73E2E)
---> Aspose.CAD.CadExceptions.ImageSaveException: Image export failed. An item with the same key has already been added. Key: 73E2E
---> System.ArgumentException: An item with the same key has already been added. Key: 73E2E
error2
Upload Failed
System.AggregateException: One or more errors occurred. (Image export failed. Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.)
---> Aspose.CAD.CadExceptions.ImageSaveException: Image export failed. Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.
---> System.InvalidOperationException: Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.
part of my api code
using (MemoryStream svgFileStream = new MemoryStream())
using (CadImage image = (CadImage) Image.Load(dwgFileStream))
{
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions()
{
PageWidth = image.Width,
PageHeight = image.Height,
ExportAllLayoutContent = true,
AutomaticLayoutsScaling = false,
};
image.Save(svgFileStream, new SvgOptions()
{
VectorRasterizationOptions = rasterizationOptions
});
return svgFileStream.ToArray();
}
part of my test code
Parallel.For(0, repeat, i =>
{
Console.WriteLine(i);
HttpClient httpClient = new HttpClient();
httpClient.BaseAddress = new Uri("https://localhost:7113");
using var content = new MultipartFormDataContent();
var filePath =
Path.Join(Directory.GetCurrentDirectory(), "Sample", $"1.dwg");
var fileContent = new ByteArrayContent(File.ReadAllBytes(filePath));
fileContent.Headers.ContentType =
new System.Net.Http.Headers.MediaTypeHeaderValue("application/dwg");
content.Add(fileContent, "file", "test.dwg");
var response = httpClient.PostAsync("Documents", content).GetAwaiter().GetResult();
});