XMLSerializer and Parametersless Constructors

M

Michael Brockman

I have an ASP.NET custom control that has to serialize the following
class in order to save it to view state. If I leave out the
parameterless constructor I get:

System.IO.FileNotFoundException: File or assembly name luasprru.dll,
or one of its dependencies, was not found.

It works if I include a parameterless constructor. Most of the
postings regarding this type of error involve incorrect security
settings for the Windows temp folder, assembly files, or conflicting
..NET versions. None of these resolved my issue, only adding the
parameterless constructor did. Does anyone know why? Thanks.

-------------------------

using System;
using System.Xml;
using System.Collections;
using System.IO;

namespace WebControls.Common
{
/// <summary>
/// Summary description for DbSchema.
/// </summary>
public class DbSchema
{
private Database _database;

// Required constructor for serializing:
public DbSchema()
{
}


public DbSchema(Database database)
{
_database = database;
GetSchema();
}

public string DatabaseName
{
get{return _database.Name;}
set{_database.Name = value;}
}

protected void GetSchema()
{
// (...)
}
}
}
 
D

Derek Harmon

Michael Brockman said:
If I leave out the parameterless constructor I get:

System.IO.FileNotFoundException: File or assembly name luasprru.dll,
or one of its dependencies, was not found. : :
None of these resolved my issue, only adding the
parameterless constructor did. Does anyone know why?

In order to be serializable (whether binary or XML serializable) a class
must have a default (parameterless) constructor.

Serializers work by creating an empty instance of your class. It won't
know what parameterized constructor to call to obtain such an empty
object ... therefore you must provide a default constructor. This is the
constructor a serializer counts on being there.


Derek Harmon
 
M

Michael Brockman

Thanks for the clarification Derek. I suppose the fact that the
serializer couldn't create an empty instance lead to the
FileNotFoundException which was misleading me.

Michael Brockman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top