arashmidos2020
سه شنبه 28 مهر 1388, 16:28 عصر
سلام.یک اسمبلی دارم که توش یک کلاس هست که serializable هستش و متد سازندش هم دو تا ورودی می گیره.
می خوام این اسمبلی رو جای دیگه load کنم.یعنی از هارد بخونه و لود بکنه.
خودم اینو نوشتم اما خطا میده.
کدش انجوریه:
Assembly assembly = Assembly.LoadFile("C:\\4\\AddCalculate.dll" );
string path = @"C:\4\tempDirectory";
string[] f = Directory.GetFiles(path);
AppDomain domain = AppDomain.CreateDomain(Path.GetFileName(f[0]));
StreamReader reader = new StreamReader(f[0], System.Text.Encoding.GetEncoding(1252), false);
byte[] b = new byte[reader.BaseStream.Length];
reader.BaseStream.Read(b, 0, System.Convert.ToInt32(reader.BaseStream.Length));
domain.Load(b);
System.Reflection.Assembly[] a = domain.GetAssemblies();
int index = 0;
for (int x = 0; x < a.Length; x++)
{
if (a[x].GetName().Name + ".dll" == System.IO.Path.GetFileName(f[0]))
{
index = x;
break;
}
}
حالا خطا میده انجوری :
An unhandled exception of type 'System.Runtime.Serialization.SerializationExcepti on' occurred in mscorlib.dll
Additional information: Insufficient state to deserialize the object. More information is needed.
می خوام این اسمبلی رو جای دیگه load کنم.یعنی از هارد بخونه و لود بکنه.
خودم اینو نوشتم اما خطا میده.
کدش انجوریه:
Assembly assembly = Assembly.LoadFile("C:\\4\\AddCalculate.dll" );
string path = @"C:\4\tempDirectory";
string[] f = Directory.GetFiles(path);
AppDomain domain = AppDomain.CreateDomain(Path.GetFileName(f[0]));
StreamReader reader = new StreamReader(f[0], System.Text.Encoding.GetEncoding(1252), false);
byte[] b = new byte[reader.BaseStream.Length];
reader.BaseStream.Read(b, 0, System.Convert.ToInt32(reader.BaseStream.Length));
domain.Load(b);
System.Reflection.Assembly[] a = domain.GetAssemblies();
int index = 0;
for (int x = 0; x < a.Length; x++)
{
if (a[x].GetName().Name + ".dll" == System.IO.Path.GetFileName(f[0]))
{
index = x;
break;
}
}
حالا خطا میده انجوری :
An unhandled exception of type 'System.Runtime.Serialization.SerializationExcepti on' occurred in mscorlib.dll
Additional information: Insufficient state to deserialize the object. More information is needed.