473,399 Members | 4,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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

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
2 2709
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Steve M | last post by:
I have subclassed CollectionBase. I have also implemented GetEnumerator(). I have tried to set the DataSource of a DataGrid to an instance of my subclass. However, the items in the grid are not...
1
by: Ot | last post by:
I have two different solutions that use xml serialization to create xml from a given class. The class is defined identically in both solutions. I copied the code for both the class and the code...
11
by: Noah Coad [MVP .NET/C#] | last post by:
How do you make a member of a class mandatory to override with a _new_ definition? For example, when inheriting from System.Collections.CollectionBase, you are required to implement certain...
5
by: Eric Johannsen | last post by:
I have a simple object that inherits from CollectionBase and overrides the Count property: namespace MyTest { public class CollTest : System.Collections.CollectionBase { public override int...
0
by: Eric van Wijk | last post by:
Hi All, After installing SP1 for Windows 2003, I'm running into the 'Error loading type library/DLL' exception when using CDO through System.Web.Mail: ...
1
by: Matthew Roberts | last post by:
Howdy Everyone, I am having trouble understanding the process of creating a type-safe collection by inheriting from the CollectionBase class. I have done it plenty of times, but now that I sit...
1
by: Kyle Novak | last post by:
I have a question about strongly typed objects when looping through a collection based on the CollectionBase object and using a For..Each loop. I have 2 objects: -Invoice: Holds all properties...
9
by: Gustaf | last post by:
I'm confused about structured error handling. The following piece of code is a simplification of a class library I'm working on. It works, and it does what I want, but I'm still not convinced that...
5
by: jc | last post by:
RE: Two Classes with the same Data Structure.. saving code? Inheriting a structure? I have two classes. One in Inherits System.Collections.CollectionBase, the other does not, but they both have...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.