PDA

View Full Version : error in load assemblies runtime



arashmidos2020
سه شنبه 28 مهر 1388, 15: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.

arashmidos2020
سه شنبه 28 مهر 1388, 16:45 عصر
پیداش کردم با تست زیادی که انجام دادم.
با این کار فقط اسمبلی لود میشه . مثلا تو کار من از شبکه یک آبجکت از اون اسمبلی می گیرم که تا وقتی اون اسمبلی تو اون کامپیوتر لود نشه نمیشه بگیرتش.

arashmidos2020
سه شنبه 28 مهر 1388, 16:46 عصر
پیداش کردم با تست زیادی که انجام دادم.
با این کار فقط اسمبلی لود میشه . مثلا تو کار من از شبکه یک آبجکت از اون اسمبلی می گیرم که تا وقتی اون اسمبلی تو اون کامپیوتر لود نشه نمیشه بگیرتش.

static void Main(string[] args)
{

string path = @"E:\my Source codes\x_dotGrid Testing\10\TestBenches\1\AddCalculate\bin\Debug";

Assembly a = Assembly.LoadFile(path +@"\AddCalculate.dll");

Type[] type = a.GetTypes();
AppDomain.CurrentDomain.Load(type.GetType().Assemb ly.ToString());