S
Scott Reynolds
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(AssemblyName assemblyRef,
Boolean stringized, Evidence assemblySecurity, StackCrawlMark& stackMark)
at System.Reflection.Assembly.Load(AssemblyName assemblyRef, Evidence
assemblySecurity)
at System.CodeDom.Compiler.CompilerResults.get_CompiledAssembly()
at System.CodeDom.Compiler.CompilerResults.get_CompiledAssembly()
at System.Xml.Serialization.Compiler.Compile()
at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings)
at System.Xml.Serialization.XmlSerializer.FromMappings(XmlMapping[]
mappings)
at
System.Web.Services.Protocols.XmlReturn.GetInitializers(LogicalMethodInfo[]
methodInfos)
at
System.Web.Services.Protocols.XmlReturnWriter.GetInitializers(LogicalMethodI
nfo[] methodInfos)
at System.Web.Services.Protocols.MimeFormatter.GetInitializers(Type type,
LogicalMethodInfo[] methodInfos)
at System.Web.Services.Protocols.HttpServerType..ctor(Type type)
at System.Web.Services.Protocols.HttpServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocol.SetContext(Type type,
HttpContext context, HttpRequest request, HttpResponse response)
at System.Web.Services.Protocols.ServerProtocolFactory.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_selectUsers",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_selectUsers",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_selectUsers",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;}
}
}
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(AssemblyName assemblyRef,
Boolean stringized, Evidence assemblySecurity, StackCrawlMark& stackMark)
at System.Reflection.Assembly.Load(AssemblyName assemblyRef, Evidence
assemblySecurity)
at System.CodeDom.Compiler.CompilerResults.get_CompiledAssembly()
at System.CodeDom.Compiler.CompilerResults.get_CompiledAssembly()
at System.Xml.Serialization.Compiler.Compile()
at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings)
at System.Xml.Serialization.XmlSerializer.FromMappings(XmlMapping[]
mappings)
at
System.Web.Services.Protocols.XmlReturn.GetInitializers(LogicalMethodInfo[]
methodInfos)
at
System.Web.Services.Protocols.XmlReturnWriter.GetInitializers(LogicalMethodI
nfo[] methodInfos)
at System.Web.Services.Protocols.MimeFormatter.GetInitializers(Type type,
LogicalMethodInfo[] methodInfos)
at System.Web.Services.Protocols.HttpServerType..ctor(Type type)
at System.Web.Services.Protocols.HttpServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocol.SetContext(Type type,
HttpContext context, HttpRequest request, HttpResponse response)
at System.Web.Services.Protocols.ServerProtocolFactory.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_selectUsers",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_selectUsers",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_selectUsers",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;}
}
}