Sage 50c WebAPI

Estou a tentar criar uma WebAPI para o Sage50c. O problema é que me estou a deparar com o erro: 

Creating an instance of the COM component with CLSID {4C922A8D-A696-4EFF-A320-65BF6F413BAF} from the IClassFactory failed due to the following error: 800a005b 0x800A005B.

Na tentativa de criar um documento. Estou a usar Swagger como interface

aqui está a parte relevante do codigo:
50 transaction.TransactionTaxIncluded = documento.TaxIncluded;
51 transaction.Comments = documento.Comments ?? "Criado via Web API";
52
53 // 5. Preencher as linhas do documento
54 foreach (var detalheDto in documento.Details)
55 {
56 var detail = CreateTransactionDetail(detalheDto, transaction.TransactionTaxIncluded);
57 transaction.Details.Add(detail);
58 }
59
60 // Calcular totais antes de gravar
61 bsoItemTransaction.Calculate();
62
63 // 6. Gravar a transação
64 var success = bsoItemTransaction.SaveItemTransaction(false, false);
65 if (!success)
66 {
67 throw new Exception("Falha ao gravar o documento. A API não retornou um erro específico.");
68 }
69
70 // 7. Construir a resposta de sucesso
71 responseData = new DocumentoVendaResponseDto
72 {
73 TransSerial = transaction.TransSerial,
74 TransDocument = transaction.TransDocument,
75 TransDocNumber = transaction.TransDocNumber,
76 TransactionID = transaction.TransactionID?.ToString() ?? string.Empty,
77 PartyID = transaction.PartyID,
78 CreateDate = transaction.CreateDate,
79 CurrencyID = transaction.BaseCurrency?.CurrencyID ?? "EUR",
80 Comments = transaction.Comments,
81 TaxIncluded = transaction.TransactionTaxIncluded,
82 TotalAmount = transaction.TotalAmount,
83 TotalTax = transaction.TotalTaxAmount,
84 Details = transaction.Details.Cast<ItemTransactionDetail>().Select((d, i) => new DocumentoVendaDetailResponseDto
85 {
86 LineItemID = (int)d.LineItemID,
87 ItemID = d.ItemID,
88 Description = d.Description,
89 Quantity = d.Quantity,
90 UnitPrice = d.UnitPrice,
91 TaxIncludedPrice = d.TaxIncludedPrice,
92 LineTotal = d.TotalAmount,
93 UnitOfSaleID = d.UnitOfSaleID,
94 WarehouseID = d.WarehouseID,
95 ColorID = d.Color?.ColorID ?? 0,
96 SizeID = d.Size?.SizeID ?? 0,
97 }).ToList()
98 };
99 }
100 catch (Exception ex)
101 {
102 _logger.LogError(ex, "Erro dentro da thread STA ao criar documento.");
103 errorMessage = $"Erro COM na thread STA: {ex.Message}";
104 }
105 });
106
107 thread.SetApartmentState(ApartmentState.STA);
108 thread.Start();
109 thread.Join(); // Esperar a conclusão da thread
110
111 if (errorMessage != null)
112 {
113 return new ApiResponseDto<DocumentoVendaResponseDto> { Success = false, Message = errorMessage };
114 }
115
116 if (responseData != null)
117 {
118 return new ApiResponseDto<DocumentoVendaResponseDto>
119 {
120 Success = true,
121 Message = "Documento criado com sucesso.",
122 Data = responseData
123 };
124 }
125
126 return new ApiResponseDto<DocumentoVendaResponseDto> { Success = false, Message = "Ocorreu um erro desconhecido na criação do documento." };
127 });
128
129 if (response.Success)
130 {
131 return Ok(response);
132 }
133 else
134 {
135 // Retornar 500 se a criação falhou por um erro interno/COM
136 return StatusCode(500, response);
137 }
138 }
139 catch (Exception ex)
140 {
141 _logger.LogError(ex, "Erro geral ao criar documento de venda.");
142 return StatusCode(500, new ApiResponseDto<DocumentoVendaResponseDto>
143 {
144 Success = false,
145 Message = $"Erro fatal no processo de criação: {ex.Message}"
146 });
147 }
148 }