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

Inheriting from the CollectionBase causes weird Error: System.IO.FileNotFoundException

P: n/a
I am having a problem exposing a class inherited from the collection base
class as a webservice. If I expose the collection on a web page all works
well and I am very happy.
However when I try and expose this via a web service I get a weird error
saying that the dll could not be found. The specific error is:

I can't figure it out. I thought it was to do with reflection but I am able
to load and view the webservice definition which correctly shows the defn to
be returned. Any webservice I try to instantiate displays this error.

All the details are below.

----------------------------------------------------------------------------
--------
Error Trace
----------------------------------------------------------------------------
--------

System.IO.FileNotFoundException: File or assembly name ytuiu77l.dll, or one
of its dependencies, was not found.
File name: "ytuiu77l.dll"
at System.Reflection.Assembly.nLoad(AssemblyName fileName, String
codeBase, Boolean isStringized, Evidence assemblySecurity, Boolean
throwOnFileNotFound, Assembly locationHint, StackCrawlMark& stackMark)
at System.Reflection.Assembly.InternalLoad(AssemblyNa me assemblyRef,
Boolean stringized, Evidence assemblySecurity, StackCrawlMark& stackMark)
at System.Reflection.Assembly.Load(AssemblyName assemblyRef, Evidence
assemblySecurity)
at System.CodeDom.Compiler.CompilerResults.get_Compil edAssembly()
at System.CodeDom.Compiler.CompilerResults.get_Compil edAssembly()
at System.Xml.Serialization.Compiler.Compile()
at System.Xml.Serialization.TempAssembly..ctor(XmlMap ping[] xmlMappings)
at System.Xml.Serialization.XmlSerializer.FromMapping s(XmlMapping[]
mappings)
at
System.Web.Services.Protocols.XmlReturn.GetInitial izers(LogicalMethodInfo[]
methodInfos)
at
System.Web.Services.Protocols.XmlReturnWriter.GetI nitializers(LogicalMethodI
nfo[] methodInfos)
at System.Web.Services.Protocols.MimeFormatter.GetIni tializers(Type type,
LogicalMethodInfo[] methodInfos)
at System.Web.Services.Protocols.HttpServerType..ctor (Type type)
at System.Web.Services.Protocols.HttpServerProtocol.I nitialize()
at System.Web.Services.Protocols.ServerProtocol.SetCo ntext(Type type,
HttpContext context, HttpRequest request, HttpResponse response)
at System.Web.Services.Protocols.ServerProtocolFactor y.Create(Type type,
HttpContext context, HttpRequest request, HttpResponse response, Boolean&
abortProcessing)


----------------------------------------------------------------------------
-----------------
Broken Web Service Code: trying to return the Users Collection
----------------------------------------------------------------------------
-----------------
[WebMethod]
public Users GetFilteredUsers(string filter)
{
SqlDataReader reader =
SqlHelper.ExecuteReader(_connectionString,"vt_sele ctUsers",filter);
Users users = new Users(reader);
return users;
}

----------------------------------------------------------------------------
-----------------
Working Web Service Code: Returns a single User
----------------------------------------------------------------------------
-----------------
[WebMethod]
public User GetFilteredUsers(string filter)
{
SqlDataReader reader =
SqlHelper.ExecuteReader(_connectionString,"vt_sele ctUsers",filter);
Users users = new Users(reader);
return users[0];
}

----------------------------------------------------------------------------
-----------------
Working Web Service Code: Returns an Int
----------------------------------------------------------------------------
-----------------
[WebMethod]
public int GetFilteredUsers(string filter)
{
SqlDataReader reader =
SqlHelper.ExecuteReader(_connectionString,"vt_sele ctUsers",filter);
Users users = new Users(reader);
int no = 1;
foreach(User u in users)
{
Debug.Write(u.Email.ToString());
}
return no;
}

----------------------------------------------------------------------------
-----------------
Collection Base Code
----------------------------------------------------------------------------
-----------------
public class Users: System.Collections.CollectionBase
{
public Users(IDataReader Reader){Fill(Reader);}
public void Fill(IDataReader reader){
while(reader.Read())
{
User user = new
User(reader["name"].ToString(),reader["email"].ToString());
Add(user);
}
}

public void Add(User aUser)
{
List.Add(aUser);
}

public bool Remove(int index)
{
if (index > Count - 1 || index < 0)
{
return false;
}
else
{
List.RemoveAt(index);
return true;
}
}

public User this[int Index]
{
get {
try
{
return (User)List[Index];
}
catch
{
return null;
}
}
set{}
}
}
----------------------------------------------------------------------------
--------
User Class Code
----------------------------------------------------------------------------
--------
public class User
{
private string name;
private string email;

public User(){
name = "";
email = "";
}

public User(string Name, string Email){
name = Name;
email = Email;
}

public string Name{
get{return name;}
set{name = value;}
}

public string Email{
get{return email;}
set{email = value;}
}

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


P: n/a
Hi,

The problem is that your collection Users does not have a default
constructor ie. a constructor that does not require parameters, this is
required for the XmlSerialization mechanism to be able to recreate the
object when it is being deserialized.

The strange DLL name you are getting is the randomly generated name of
the dynamically generated Assembly that is used to serialize the class,
because the generation of this Assembly fails, the XmlSerialization
which WebServices rely on throws the exception that you received.

Hope this helps

Chris Taylor
http://www.xanga.com/home.aspx?user=taylorza

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #2

P: n/a
Thanks all sorted now.

Have a great new year.
"Chris Taylor" <ch*************@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi,

The problem is that your collection Users does not have a default
constructor ie. a constructor that does not require parameters, this is
required for the XmlSerialization mechanism to be able to recreate the
object when it is being deserialized.

The strange DLL name you are getting is the randomly generated name of
the dynamically generated Assembly that is used to serialize the class,
because the generation of this Assembly fails, the XmlSerialization
which WebServices rely on throws the exception that you received.

Hope this helps

Chris Taylor
http://www.xanga.com/home.aspx?user=taylorza

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.