Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. FileNotFound Error when trying instantiate XMLSerializer with array

FileNotFound Error when trying instantiate XMLSerializer with array

Scheduled Pinned Locked Moved C#
helpcsharpdata-structuresxmltutorial
9 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Florian Storck
    wrote on last edited by
    #1

    Hi, I'm currently stuck with the following problem: XmlSerializer tSer = new XmlSerializer(typeof(Int16[]); This generates an FileNotFound error. It's obviously an problem whith the OnTheFly generation of the serializer dlls and happens with each Array declaration at the moment. I found some stuff on the net dealing with this, but no real solution for my problem. I tried to track it down with the XMLPreCompiler, but until now with no success. The funny thing is, that this error seems only to happen on the first stage, as the array occurs in the written XML file. Does anybody have a clue, how to deal with Arrays and the .Net 2.0 XMLSerializer ? Thanks in advance, Florian

    M 1 Reply Last reply
    0
    • F Florian Storck

      Hi, I'm currently stuck with the following problem: XmlSerializer tSer = new XmlSerializer(typeof(Int16[]); This generates an FileNotFound error. It's obviously an problem whith the OnTheFly generation of the serializer dlls and happens with each Array declaration at the moment. I found some stuff on the net dealing with this, but no real solution for my problem. I tried to track it down with the XMLPreCompiler, but until now with no success. The funny thing is, that this error seems only to happen on the first stage, as the array occurs in the written XML file. Does anybody have a clue, how to deal with Arrays and the .Net 2.0 XMLSerializer ? Thanks in advance, Florian

      M Offline
      M Offline
      Marc Clifton
      wrote on last edited by
      #2

      Florian Storck wrote:

      I'm currently stuck with the following problem:

      I don't get that problem at all with that instantiation. It just returns an XmlSerializer object. Marc

      Thyme In The Country

      People are just notoriously impossible. --DavidCrow
      There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer
      People who say that they will refactor their code later to make it "good" don't understand refactoring, nor the art and craft of programming. -- Josh Smith

      F 2 Replies Last reply
      0
      • M Marc Clifton

        Florian Storck wrote:

        I'm currently stuck with the following problem:

        I don't get that problem at all with that instantiation. It just returns an XmlSerializer object. Marc

        Thyme In The Country

        People are just notoriously impossible. --DavidCrow
        There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer
        People who say that they will refactor their code later to make it "good" don't understand refactoring, nor the art and craft of programming. -- Josh Smith

        F Offline
        F Offline
        Florian Storck
        wrote on last edited by
        #3

        Hi Marc, do you use .Net 2.0 ? Can you post a code example ? Maybe there are some prerequisites in my project causing this error. Thanks, Florian

        M 1 Reply Last reply
        0
        • F Florian Storck

          Hi Marc, do you use .Net 2.0 ? Can you post a code example ? Maybe there are some prerequisites in my project causing this error. Thanks, Florian

          M Offline
          M Offline
          Marc Clifton
          wrote on last edited by
          #4

          Yes. .NET 2.0 Here's the little test app I wrote:

          using System;
          using System.IO;
          using System.Text;
          using System.Xml;
          using System.Xml.Serialization;

          namespace XmlSerializerTest
          {
          class Program
          {
          static void Main(string[] args)
          {
          XmlSerializer ser = new XmlSerializer(typeof(Int16[]));
          TextWriter writer = new StreamWriter("foo.xml");
          Int16[] iArray = new Int16[] { 1, 2, 3, 4 };

          		// Serialize the object, and close the TextWriter.
          		ser.Serialize(writer, iArray);
          		writer.Close();
          
          	}
          }
          

          }

          and it generates:

          <?xml version="1.0" encoding="utf-8"?>
          <ArrayOfShort xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
          <short>1</short>
          <short>2</short>
          <short>3</short>
          <short>4</short>
          </ArrayOfShort>

          Marc

          Thyme In The Country

          People are just notoriously impossible. --DavidCrow
          There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer
          People who say that they will refactor their code later to make it "good" don't understand refactoring, nor the art and craft of programming. -- Josh Smith

          1 Reply Last reply
          0
          • M Marc Clifton

            Florian Storck wrote:

            I'm currently stuck with the following problem:

            I don't get that problem at all with that instantiation. It just returns an XmlSerializer object. Marc

            Thyme In The Country

            People are just notoriously impossible. --DavidCrow
            There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer
            People who say that they will refactor their code later to make it "good" don't understand refactoring, nor the art and craft of programming. -- Josh Smith

            F Offline
            F Offline
            Florian Storck
            wrote on last edited by
            #5

            Hi, I tried it in an completely empty project, and it doesn't happen there. So there seem to be some project dependencies...looks like I have to track it down there.. Florian

            M 1 Reply Last reply
            0
            • F Florian Storck

              Hi, I tried it in an completely empty project, and it doesn't happen there. So there seem to be some project dependencies...looks like I have to track it down there.. Florian

              M Offline
              M Offline
              Marc Clifton
              wrote on last edited by
              #6

              Florian Storck wrote:

              looks like I have to track it down there..

              Walk through the inner exceptions. That often reveals the real reason for the serializer to die. Marc

              Thyme In The Country

              People are just notoriously impossible. --DavidCrow
              There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer
              People who say that they will refactor their code later to make it "good" don't understand refactoring, nor the art and craft of programming. -- Josh Smith

              F 1 Reply Last reply
              0
              • M Marc Clifton

                Florian Storck wrote:

                looks like I have to track it down there..

                Walk through the inner exceptions. That often reveals the real reason for the serializer to die. Marc

                Thyme In The Country

                People are just notoriously impossible. --DavidCrow
                There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer
                People who say that they will refactor their code later to make it "good" don't understand refactoring, nor the art and craft of programming. -- Josh Smith

                F Offline
                F Offline
                Florian Storck
                wrote on last edited by
                #7

                Hello Marc, some other strange thing is, that the VisualStudio catches the Exception, but I don't get the Exception in my own exception handler. Even if I switch off all Exception in Debug->Exceptions in VS, the Exception handler isn't called. if (m_dicXmlSerCache.ContainsKey(TObj)) { // m_Log.DebugFormat(" Serializer Cache Hit: Type {0}", TObj) m_dicCacheHits[TObj]++; // for statistic purposes return m_dicXmlSerCache[TObj]; } else { XmlSerializer tSer = new XmlSerializer(TObj); m_dicXmlSerCache.Add(TObj, tSer); // just for keeping track of some statistics m_dicCacheHits.Add(TObj, 1); tSer.UnknownAttribute += new XmlAttributeEventHandler(XML_UnknownAttribute); tSer.UnknownElement += new XmlElementEventHandler(XML_UnknownElement); tSer.UnknownNode += new XmlNodeEventHandler(XML_UnknownNode); tSer.UnreferencedObject += new UnreferencedObjectEventHandler(XML_UnreferencedObject); return tSer; } } catch (Exception e) { m_Log.ErrorFormat("Error in SerializerCache: {0}", e.Message); } For explanation: This Code acts as a cache for various serializer objects, to avoid unnecessary instantiations. I've no real idea, why also my exception handler doesn't work here... Bye, Florian

                M 1 Reply Last reply
                0
                • F Florian Storck

                  Hello Marc, some other strange thing is, that the VisualStudio catches the Exception, but I don't get the Exception in my own exception handler. Even if I switch off all Exception in Debug->Exceptions in VS, the Exception handler isn't called. if (m_dicXmlSerCache.ContainsKey(TObj)) { // m_Log.DebugFormat(" Serializer Cache Hit: Type {0}", TObj) m_dicCacheHits[TObj]++; // for statistic purposes return m_dicXmlSerCache[TObj]; } else { XmlSerializer tSer = new XmlSerializer(TObj); m_dicXmlSerCache.Add(TObj, tSer); // just for keeping track of some statistics m_dicCacheHits.Add(TObj, 1); tSer.UnknownAttribute += new XmlAttributeEventHandler(XML_UnknownAttribute); tSer.UnknownElement += new XmlElementEventHandler(XML_UnknownElement); tSer.UnknownNode += new XmlNodeEventHandler(XML_UnknownNode); tSer.UnreferencedObject += new UnreferencedObjectEventHandler(XML_UnreferencedObject); return tSer; } } catch (Exception e) { m_Log.ErrorFormat("Error in SerializerCache: {0}", e.Message); } For explanation: This Code acts as a cache for various serializer objects, to avoid unnecessary instantiations. I've no real idea, why also my exception handler doesn't work here... Bye, Florian

                  M Offline
                  M Offline
                  Marc Clifton
                  wrote on last edited by
                  #8

                  Where's the try? Anyways, I get the impression that the exception is happening in one of your tSer event handlers. Do you have try-catch blocks in the handlers? Marc

                  Thyme In The Country

                  People are just notoriously impossible. --DavidCrow
                  There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer
                  People who say that they will refactor their code later to make it "good" don't understand refactoring, nor the art and craft of programming. -- Josh Smith

                  F 1 Reply Last reply
                  0
                  • M Marc Clifton

                    Where's the try? Anyways, I get the impression that the exception is happening in one of your tSer event handlers. Do you have try-catch blocks in the handlers? Marc

                    Thyme In The Country

                    People are just notoriously impossible. --DavidCrow
                    There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer
                    People who say that they will refactor their code later to make it "good" don't understand refactoring, nor the art and craft of programming. -- Josh Smith

                    F Offline
                    F Offline
                    Florian Storck
                    wrote on last edited by
                    #9

                    Oops, try { if (m_dicXmlSerCache.ContainsKey(TObj)) { // m_Log.DebugFormat(" Serializer Cache Hit: Type {0}", TObj) m_dicCacheHits[TObj]++; // for statistic purposes return m_dicXmlSerCache[TObj]; } else { XmlSerializer tSer = new XmlSerializer(TObj); m_dicXmlSerCache.Add(TObj, tSer); // just for keeping track of some statistics m_dicCacheHits.Add(TObj, 1); tSer.UnknownAttribute += new XmlAttributeEventHandler(XML_UnknownAttribute); tSer.UnknownElement += new XmlElementEventHandler(XML_UnknownElement); tSer.UnknownNode += new XmlNodeEventHandler(XML_UnknownNode); tSer.UnreferencedObject += new UnreferencedObjectEventHandler(XML_UnreferencedObject); return tSer; } } catch (Exception e) { m_Log.ErrorFormat("Error in SerializerCache: {0}", e.Message); } I didn't post the whole block. I think the handler are not the problem, this also happened before i wrote this cache object, which attached no handler at all. I also had the problem, that the try-catch didn't worked, only the VS handler shows up. But I have to access to the exception object there, so I can't check the inner exceptions. Something weird seems to happen here... Bye, Florian

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups