By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,587 Members | 1,101 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,587 IT Pros & Developers. It's quick & easy.

XmlSerializer, System.IO.FileNotFoundException

P: n/a
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.FileNotFoundException: 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.DataRow 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(string newtestvalue)
{
testvalue = newtestvalue;
}

public static explicit operator TestClass(System.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("DataFile.dat", FileMode.Create);

try

{

// Construct a BinaryFormatter and use it

// to serialize the data to the stream.

XmlSerializer formatter = new XmlSerializer(typeof(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.Serialize(fs, a1);

// Deserialize the array elements.

fs.Position = 0;

TestBase[] a2 = (TestBase[]) formatter.Deserialize(fs);

}

catch (SerializationException e)

{

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

throw;

}

finally

{

fs.Close();

}
Nov 11 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Thankyou, that did tell me the exact exception that was happening behind the
scenes.

Perhaps someone might now be able to give me a hand in fixing the underlying
exception:

The type 'System.Data.DataRow' is defined in an assembly that is not
referenced.

I have a reference to this assembly, and the corresponding using statement -
but I guess the temporary assembly that the XmlSerializer creates is where
the assembly needs to be referenced. How do I reference it to stop this
error?

many thanks, and thankyou Daniel for you help in getting me this far!

Chris Aitchison
"Daniel Cazzulino" <ya****@nospam.siderar.com> wrote in message
news:u#**************@tk2msftngp13.phx.gbl...
There's a tiny useful utility to diagnose your problem, from Chris Sells:
http://sellsbrothers.com/tools/#XmlS...zerPreCompiler

--
../d:cazz
Daniel Cazzulino
DEVerest - Lagash
Tel +54 (0) 11 4247 7396
www.deverest.com.ar
www.lagash.com
dotnetopensrc.sourceforge.net

Coauthor of:
Beginning C# Web Applications with Visual Studio .NET
Beginning Web Programming using VB.NET and Visual Studio .NET
Professional ASP.NET Server Controls: Building Custom Controls with C#
ASP.NET Components Toolkit

"He who is good for making excuses, is seldom good for anything else."

"Chris Aitchison" <ch*************@hotmail.com> wrote in message
news:O9*************@TK2MSFTNGP11.phx.gbl...
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.FileNotFoundException: 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.DataRow 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(string newtestvalue)
{
testvalue = newtestvalue;
}

public static explicit operator TestClass(System.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("DataFile.dat", FileMode.Create);

try

{

// Construct a BinaryFormatter and use it

// to serialize the data to the stream.

XmlSerializer formatter = new XmlSerializer(typeof(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.Serialize(fs, a1);

// Deserialize the array elements.

fs.Position = 0;

TestBase[] a2 = (TestBase[]) formatter.Deserialize(fs);

}

catch (SerializationException e)

{

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

throw;

}

finally

{

fs.Close();

}


Nov 11 '05 #2

P: n/a
This cryptic error message that you are encountering occurs when the
XmlSerializer fails to serialize the type, because the type is too complex.
[ It can also occur when there are permissions problems, but that is
generally a red herring, and specifically in your case, it was certainly a
red herring!] Most often I have seen this occur on types that embed
members that are so-called "jagged" 2-D arrays, eg

public SomeType[][] SomeMember;
Can we see the type? Do you have a jagged array?

As you yourself saw, simplifying the type to be serialized can avoid the
problem. The other workaround *may be* to apply attributes to the offending
member to help the serializer understand what to do. Which of these is
preferred depends on your situation.

-Dino

"Chris Aitchison" <ch*************@hotmail.com> wrote in message
news:eV**************@TK2MSFTNGP10.phx.gbl...
Thankyou, that did tell me the exact exception that was happening behind the scenes.

Perhaps someone might now be able to give me a hand in fixing the underlying exception:

The type 'System.Data.DataRow' is defined in an assembly that is not
referenced.

I have a reference to this assembly, and the corresponding using statement - but I guess the temporary assembly that the XmlSerializer creates is where
the assembly needs to be referenced. How do I reference it to stop this
error?

many thanks, and thankyou Daniel for you help in getting me this far!

Chris Aitchison
"Daniel Cazzulino" <ya****@nospam.siderar.com> wrote in message
news:u#**************@tk2msftngp13.phx.gbl...
There's a tiny useful utility to diagnose your problem, from Chris Sells:
http://sellsbrothers.com/tools/#XmlS...zerPreCompiler

--
../d:cazz
Daniel Cazzulino
DEVerest - Lagash
Tel +54 (0) 11 4247 7396
www.deverest.com.ar
www.lagash.com
dotnetopensrc.sourceforge.net

Coauthor of:
Beginning C# Web Applications with Visual Studio .NET
Beginning Web Programming using VB.NET and Visual Studio .NET
Professional ASP.NET Server Controls: Building Custom Controls with C#
ASP.NET Components Toolkit

"He who is good for making excuses, is seldom good for anything else."

"Chris Aitchison" <ch*************@hotmail.com> wrote in message
news:O9*************@TK2MSFTNGP11.phx.gbl...
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.FileNotFoundException: 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.DataRow 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(string newtestvalue)
{
testvalue = newtestvalue;
}

public static explicit operator TestClass(System.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("DataFile.dat", FileMode.Create);

try

{

// Construct a BinaryFormatter and use it

// to serialize the data to the stream.

XmlSerializer formatter = new XmlSerializer(typeof(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.Serialize(fs, a1);

// Deserialize the array elements.

fs.Position = 0;

TestBase[] a2 = (TestBase[]) formatter.Deserialize(fs);

}

catch (SerializationException e)

{

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

throw;

}

finally

{

fs.Close();

}



Nov 11 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.