Click here to Skip to main content
14,580,573 members
Rate this:
Please Sign up or sign in to vote.
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

Rate this:
Please Sign up or sign in to vote.

Solution 1

C# is case-sensitive
GetTYpe should be GetType

Object.GetType Method (System) | Microsoft Docs[^]
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100