Click here to Skip to main content
15,905,148 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I receive no errors when i compile the program, however as soon as I click the save button I receive 'InvalidOperationException was unhandled'. 
              XmlSerializer serializer = new XmlSerializer(obj.GetTYpe()); Is then highlighted,

Is my code is correct ?? and how to solve that Exception. Plzz anyone help me.

What I have tried:

<pre lang="c#">
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Serialization;

namespace Config_Tool
      public saveXML()
      public static void savedata(object obj, string filename)
              XmlSerializer serializer = new XmlSerializer(obj.GetTYpe());
              using(StreamWriter writer = new Streamwriter(filename)
                     serializer.Serialize(writer. obj);
Updated 1-Jun-20 0:59am

1 solution

C# is case-sensitive
GetTYpe should be GetType

Object.GetType Method (System) | Microsoft Docs[^]
Share this answer
Member 14672509 1-Jun-20 10:05am    
Same thing i did, but im getting same Exception.
MadMyche 1-Jun-20 10:16am    
Please post the Inner Exception

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900