XmlSerializer, System.IO.FileNotFoundException

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris Aitchison

    #1

    XmlSerializer, System.IO.FileNotFoundException

    Hello,

    I am attempting to have a class that I have written serialize so that it can
    be both passed as a parameter or return value for a webservice, and also be
    serialized to disk using the XmlSerializer.

    When this class is decalred as a return value for a WebMethod in an XML
    WebService I receive the following exception:

    System.IO.FileN otFoundExceptio n: File or assembly name rexz5r1o.dll, or one
    of its dependencies, was not found.
    File name: "rexz5r1o.dll". ...

    I searched the newgroups for other people that experienced this problem and
    found there to be many - with most of the fixes pointing towards permission
    problems on the temporary folder that the framework writes temporary
    assemblies to. I followed the advice given in these posts and gave the user
    account my web service is running under full permission to the folder that
    was shown in the error log. This did not solve the issue, and I was still
    receiving the same error message as before.

    This got me thinking, so I attempted to serialize this same class in a
    simple console application that I can be 100% sure has basically full local
    administrator permissions. I wrote a small application that utilized the
    XmlSerializer class and got it successfully to serialize a basic class that
    I wrote (not the class mentioned above) that only has a single string
    property. I then changed the code to use the class that I wanted to
    serialize in the first place thinking it would work - but with no luck. I
    received the same error message.

    I then decided to mimic my temporary class to look like the real class that
    I wanted to have serialized and through trial and error have found the
    exception is being caused by an explicit operator on my class that accepts a
    strongly-typed DataRow as a parameter (it also occurs on a basic
    System.Data.Dat aRow class). The exact class that causes this error can be
    seen below:

    [Serializable]
    public class TestClass
    {
    private string testvalue;

    public string TestValue
    {
    get { return testvalue; }
    set { testvalue = value; }
    }

    public void SetTestValue(st ring newtestvalue)
    {
    testvalue = newtestvalue;
    }

    public static explicit operator TestClass(Syste m.Data.DataRow row)
    {
    TestClass newclass = new TestClass();
    newclass.name = row[0].ToString();

    return newclass;
    }
    }

    If you change the parameter type of the explicit operator to a normal string
    type then the exception dissapears.

    Just for some background, the class that this is happening on is an 'entity'
    that maps a row from a table in a database, which is the reason why I have
    written an explicit operator to 'map' a DataRow into a corresponding entity.

    Has anyone else come across this issue before? I have searched high and low
    and not yet found anyone that is experiencing this exact problem.

    Any insight or help would be greatly appreciated.

    Kind regards,

    Chris Aitchison
    senior developer
    Protelligent, Inc.

    PS. The source code that I am using to actually perform the serialization is
    as follows:

    FileStream fs = new FileStream("Dat aFile.dat", FileMode.Create );

    try

    {

    // Construct a BinaryFormatter and use it

    // to serialize the data to the stream.

    XmlSerializer formatter = new XmlSerializer(t ypeof(TestBase[]));

    //BinaryFormatter formatter = new BinaryFormatter ();

    // Create an array with multiple elements

    TestBase[] a1 = { new TestBase(), new TestBase() };

    a1[0].Name = "Hello";

    a1[1].Name = "There";

    //a1[0].City = "Hello";

    //a1[1].City = "There";

    // Serialize the array elements.

    formatter.Seria lize(fs, a1);

    // Deserialize the array elements.

    fs.Position = 0;

    TestBase[] a2 = (TestBase[]) formatter.Deser ialize(fs);

    }

    catch (SerializationE xception e)

    {

    Console.WriteLi ne("Failed to serialize. Reason: " + e.Message);

    throw;

    }

    finally

    {

    fs.Close();

    }


Working...