Problem setting the Text property of a Characters object in Excel Interop using Visual C#
Published: 2023-03-20 04:53:17

I'm making ChartSheets in Excel using .NET 7 and the latest update of Office 365; this is the code that I use to change the style of the charts and give them a title:

```
GráficasFrecuenciaGanancia[i - 1].ChartType = XlChartType.xlLineMarkers; GráficasFrecuenciaGanancia[i-1].HasTitle = true;
Excel.Characters TítuloGráfica = null;
string dummyString = null;
dummyString = Convert.ToString(allTheCells.Item[1 + ((i - 1) * 54), 1].Value2); TítuloGráfica = GráficasFrecuenciaGanancia[i - 1].ChartTitle.Characters;                  try
{
    TítuloGráfica.Text = dummyString;
}
catch(Exception ex)
{
    MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK);
    Debug.Write(ex.ToString());
} 
```
               
In certain ChartSheets it gives the following exception (sorry, bits are in Spanish):

```
System.Runtime.InteropServices.COMException (0x800A03EC): No se puede asignar la propiedad Text de la clase Characters.
    at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
    at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Object[] aArgs, Boolean[] aArgsIsByRef, Int32[] aArgsWrapperTypes, Type[] aArgsTypes, Type retType)
    at Microsoft.Office.Interop.Excel.Characters.set_Text(String )
    at Graficador___v3.Form1.GraficadorFrecuenciaGanancia_Click(Object sender, EventArgs e) in C:\Users\user\OneDrive\Escritorio\Proyecto\Visual Studio\Graficadores\Graficador - v3\Form1.cs:line 247Excepción producida: 'System.Runtime.InteropServices.COMException' en System.Private.CoreLib.dll System.Runtime.InteropServices.COMException (0x800A03EC): No se puede asignar la propiedad Text de la clase Characters.
    at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
    at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Object[] aArgs, Boolean[] aArgsIsByRef, Int32[] aArgsWrapperTypes, Type[] aArgsTypes, Type retType)
    at Microsoft.Office.Interop.Excel.Characters.set_Text(String )
    at Graficador___v3.Form1.GraficadorFrecuenciaGanancia_Click(Object sender, EventArgs e) in C:\Users\user\OneDrive\Escritorio\Proyecto\Visual Studio\Graficadores\Graficador - v3\Form1.cs:line 247 El programa '[22776] Graficador - v3.exe' terminó con código 4294967295 (0xffffffff).  
```
This line:
`System.Runtime.InteropServices.COMException (0x800A03EC): No se puede asignar la propiedad Text de la clase Characters. ` 

Says that I cannot assign the Text property from a Characters instance. I tried many things, like repairing Visual Studio (I'm using the Community version, 2022), repairing Office, downloading the latest version of Microsoft Visual C++ Redistributable (2015-2022), updating Windows 11, and even downloading and installing all the redistribuitables, but I couldn't fix it; I looked up the HResult of the exception: 0x800A03EC, but most of the answers were for code written for servers (I'm not working on a server, I am working on an application to make graphs for a lot of data that I'm using at work).

This is my full and most recent code in [GitHub](https://github.com/ThreeNamesGrace/Graficador---v3).