i have tried to sign the Bin folder's full control to networkservice aspnet
everyone internetuser,
and i got the same error (windows 2003)
the Loader.dll is in Bin folder , and the Loader.dll will load another
assembly in another folder.
does it matter ?
you can track my previous post to find out what am i trying to do
http://www.developersdex.com/asp/message.asp?p=2912&ID=<[email protected]>
*****Full Code Below***********
// Loader.cs
// Compile Loader.cs into Loader.dll
using System;
using System.Reflection;
using System.Runtime.Serialization;
namespace Loader
{
// container for assembly and exposes a GetObject function
// to create a late-bound object for casting by the consumer
// this class is meant to be contained in a separate appDomain
// controlled by ObjectLoader class to allow for proper encapsulation
// which enables proper shadow-copying functionality.
public class AssemblyLoader : MarshalByRefObject, IDisposable
{
#region class-level declarations
private Assembly assembly = null;
private CAssemblyInfo assemblyInfo;
public CAssemblyInfo AssemblyInfo
{
get{return assemblyInfo;}
}
#endregion
#region constructors and destructors
public AssemblyLoader( string fullPath )
{
if( assembly == null )
{
assembly = Assembly.LoadFrom( fullPath );
assemblyInfo = new CAssemblyInfo();
assemblyInfo.fullName = assembly.FullName;
assemblyInfo.version = assembly.GetName().Version;
}
}
~AssemblyLoader()
{
dispose( false );
}
public void Dispose()
{
dispose( true );
}
private void dispose( bool disposing )
{
if( disposing )
{
assembly = null;
assemblyInfo = null;
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
System.GC.Collect( 0 );
}
}
#endregion
//object GetObject ()
//{
// i delete this function for i don't need it.
//}
}
[Serializable]
public class CAssemblyInfo
{
public CAssemblyInfo()
{
}
internal string fullName;
public string FullName
{
get{return fullName;}
}
internal Version version;
public Version Version
{
get{return version;}
}
}
}
// ObjectLoader.cs and WebService.asmx is in the same project
// ObjectLoader.cs
using System;
using System.Reflection;
using System.Collections;
namespace Loader
{
/* contains assembly loader objects, stored in a hash
* and keyed on the .dll file they represent. Each assembly loader
* object can be referenced by the original name/path and is used to
* load objects, returned as type Object. It is up to the calling class
* to cast the object to the necessary type for consumption.
* External interfaces are highly recommended!!
* */
public class AssemblyInfoHelper : IDisposable
{
public AssemblyInfoHelper() {/*...*/}
private AppDomainSetup setup;
private AppDomain domain;
private Loader.CAssemblyInfo assemblyInfo;
public Loader.CAssemblyInfo GetAssemblyinfo(string AssemblyName)
{
Loader.AssemblyLoader al = null;
setup = new AppDomainSetup();
setup.ShadowCopyFiles = "true";
domain = AppDomain.CreateDomain( AssemblyName, null, setup );
BindingFlags bindings = BindingFlags.CreateInstance |
BindingFlags.Instance | BindingFlags.Public;
object[] parms = { AssemblyName };
al = (Loader.AssemblyLoader)domain.CreateInstanceFromAndUnwrap(
"Loader.dll", "Loader.AssemblyLoader", true, bindings, null, parms,
null, null, null);
assemblyInfo = al.AssemblyInfo;
AppDomain.Unload(domain);
return assemblyInfo;
}
~AssemblyInfoHelper()
{
dispose( false );
}
public void Dispose()
{
dispose( true );
}
private void dispose( bool disposing )
{
if( disposing )
{
if (domain != null)
AppDomain.Unload(domain);
}
}
}
}
//WebService.asmx
[WebMethod]
public string GetVersion()
{
Loader.AssemblyInfoHelper ai = new Loader.AssemblyInfoHelper();
string ver = "";
try
{
// get the assembly version info with the physical path
// and the assembly will be unloaded with the separate appDomain
// so i can update the assembly anytime,otherwise i have to manully
// stop the w3p.exe process and will cause other WebApp crash
// this code works in a winform app
ver = ai.GetAssemblyinfo(@"C:\MyAssembly.exe").Version.ToString();
}
catch (Exception ex)
{
return ex.Message;
}
return ver;
}