FileNotFound Error when trying instantiate XMLSerializer with array
-
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 -
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, FlorianFlorian 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
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 -
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
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 SmithHi 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
-
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
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
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 -
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
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 SmithHi, 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
-
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
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
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 -
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
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 SmithHello 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 -
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, FlorianWhere'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
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 -
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
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 SmithOops,
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