Click here to Skip to main content
15,924,317 members
Home / Discussions / C#
   

C#

 
GeneralRe: Right to left problem Pin
Heath Stewart11-Nov-03 3:19
protectorHeath Stewart11-Nov-03 3:19 
QuestionIs MS Access transaction-aware? Pin
CillyMe10-Nov-03 23:53
CillyMe10-Nov-03 23:53 
AnswerRe: Is MS Access transaction-aware? Pin
Hesham Amin11-Nov-03 0:41
Hesham Amin11-Nov-03 0:41 
GeneralRe: Is MS Access transaction-aware? Pin
CillyMe11-Nov-03 2:02
CillyMe11-Nov-03 2:02 
GeneralRe: Is MS Access transaction-aware? Pin
CillyMe11-Nov-03 2:50
CillyMe11-Nov-03 2:50 
GeneralRe: Is MS Access transaction-aware? Pin
Hesham Amin11-Nov-03 7:44
Hesham Amin11-Nov-03 7:44 
GeneralRe: Is MS Access transaction-aware? Pin
CillyMe11-Nov-03 16:47
CillyMe11-Nov-03 16:47 
GeneralBuilding Objects with Reflection Pin
Dennis Klein10-Nov-03 22:49
Dennis Klein10-Nov-03 22:49 
Hello,

I've a problem creating objects using Reflection. I tried to create a new System.Drawing.Size object using the CreateInstance Method from the Assembly class. Everything worked well, but if i try to cast this object into another Size object my application crashes.

Here is the source :

//----------------------------------------
using System;
using System.Drawing;
using System.Reflection;

namespace TestApp
{
public class TestApp
{
public static void Main ()
{
object[] args = new object[2];
args[0] = (int) 200;
args[1] = (int) 400;

object o1 = null;
object o2 = null;
Size s1 = new Size ();

try
{
o1 = CreateInstance ("System.Drawing.dll", "System.Drawing.Size", args);
}
catch (Exception ex)
{
Console.WriteLine (ex.Message);
}

try
{
o2 = new Size (200, 400);
}
catch (Exception ex)
{
Console.WriteLine (ex.Message);
}

try
{
Console.Write ("Trying to cast o2 to Size s1...");
s1 = (Size) o2;
Console.WriteLine ("DONE");
Console.WriteLine ("s1 : " + s1.ToString ());
Console.ReadLine ();

Console.Write ("Trying to cast o1 to Size s1...");
s1 = (Size) o1;
Console.WriteLine ("DONE");
Console.WriteLine ("s1 : " + s1.ToString ());
Console.ReadLine ();
}
catch (Exception ex)
{
Console.WriteLine (ex.Message);
Console.ReadLine ();
}
}

private static string GetSystemDir ()
{
Assembly [] assemblies = AppDomain.CurrentDomain.GetAssemblies ();
foreach (Assembly a in assemblies)
{
string codebase = a.CodeBase;
if (codebase.EndsWith ("corlib.dll"))
{
return codebase.Substring (0, codebase.LastIndexOf ("/")).Substring (8);
}
}

return "";
}

private static object CreateInstance (string AssemblyName, string ClassName, object[] args)
{
try
{
Assembly a = Assembly.LoadFile (GetSystemDir () + "/" + AssemblyName);
return a.CreateInstance (ClassName, true, BindingFlags.CreateInstance, null, args, null, null);
}
catch (Exception ex)
{
Console.WriteLine (ex.Message);
}

return null;
}

}
}
//----------------------------------------

I hope someone can help me. Thanx in advance Smile | :)

( Sorry about some mistakes, my english is not so good Wink | ;-) )
GeneralRe: Building Objects with Reflection Pin
Heath Stewart11-Nov-03 3:32
protectorHeath Stewart11-Nov-03 3:32 
GeneralRe: Building Objects with Reflection Pin
Dennis Klein11-Nov-03 22:12
Dennis Klein11-Nov-03 22:12 
GeneralRe: Building Objects with Reflection Pin
Heath Stewart12-Nov-03 2:39
protectorHeath Stewart12-Nov-03 2:39 
GeneralRe: Building Objects with Reflection Pin
Dennis Klein12-Nov-03 3:25
Dennis Klein12-Nov-03 3:25 
Generalcommunicate with service Pin
Member 67650610-Nov-03 22:45
Member 67650610-Nov-03 22:45 
GeneralRe: communicate with service Pin
Arjan Einbu10-Nov-03 23:03
Arjan Einbu10-Nov-03 23:03 
GeneralCOM+ application load balancing Pin
CillyMe10-Nov-03 20:34
CillyMe10-Nov-03 20:34 
GeneralLoading data to string variable Pin
Rostrox10-Nov-03 19:19
Rostrox10-Nov-03 19:19 
GeneralRe: Loading data to string variable Pin
Corinna John10-Nov-03 19:47
Corinna John10-Nov-03 19:47 
GeneralRe: Loading data to string variable Pin
Jeff Varszegi11-Nov-03 4:54
professionalJeff Varszegi11-Nov-03 4:54 
GeneralRe: Loading data to string variable Pin
Jeff Varszegi11-Nov-03 6:04
professionalJeff Varszegi11-Nov-03 6:04 
GeneralControl/Class Existence Pin
Anonymous10-Nov-03 17:47
Anonymous10-Nov-03 17:47 
GeneralRe: Control/Class Existence Pin
Heath Stewart11-Nov-03 3:36
protectorHeath Stewart11-Nov-03 3:36 
GeneralRe: Control/Class Existence Pin
Bhangorix11-Nov-03 23:55
Bhangorix11-Nov-03 23:55 
GeneralRe: Control/Class Existence Pin
Heath Stewart12-Nov-03 2:57
protectorHeath Stewart12-Nov-03 2:57 
GeneralRe: Control/Class Existence Pin
Bhangorix16-Nov-03 19:12
Bhangorix16-Nov-03 19:12 
GeneralConverting an Image to an Icon Pin
Adam Turner10-Nov-03 13:47
Adam Turner10-Nov-03 13:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.