hi , yes , that's the case , I was searching for a way to solve this at runtime. anyway I got a clue a from Simon_Whale. thanks.
prasadbuddhika
Posts
-
casting at runtime in c# -
casting at runtime in c#hi thanks it seems to be working, though it is a workaround . thanks for the clue . ** yes i noticed that and i fixed it by calling the GetType() thanks.
-
casting at runtime in c#thanks , yes this is the place where i'm stuck , need to cast in runtime , if you find a way please share it .
-
casting at runtime in c#hi , this is how i'm doing the deserialization
Type genericSyncObj = typeof(SyncObject<>);
Type syncObj = genericSyncObj.MakeGenericType(type);
IList customObjectList = (IList)Activator.CreateInstance((typeof(List<>).MakeGenericType(type)));foreach (string value in pullRequest.Knowledge)
{
dynamic syncObject = JasonSerializer.Deserialize(value, syncObj, null);
customObjectList.Add(syncObject.Object);
}and i'm getting the exception at here
dynamic responseSync = Activator.CreateInstance(typeof(SyncObject<>).MakeGenericType(type));
responseSync.Object = customObjectList[y] ;thanks .
-
casting at runtime in c#Thanks again , ok then I think I have to focus on the deserialzed object , unfortunately i haven't got the code snippet right now , but I will definitely post that code snippet soon. thanks .
-
casting at runtime in c#thanks , I also tried the value types and it works , but the problem came when i'm trying to assign reference type.
-
casting at runtime in c#hi , I got an object which is a generic, at runtime i pass the type for T and create the proper object. the generic object as follows
class parent {
string name;
T childObject;
}I create the parent in runtime using the reflection , for e.g.
Type type = x;
Dynamic response = Activator.CreateInstance(typeof(parent<>).MakeGenericType(type));it works fine , but the problem is when I try to assign an object to response.childObject it gives me an exception saying that i'm missing cast and it cannot implicitly cast the object. the object try to assign is also created using reflection, ADDED LATER: I'm not sure this part will be important for this issue , but anyway , the object i'm trying to assign to response.childObject is also an object created by deserialization , means for in order to deserialize this object i have to give the type , so that type also crated using reflection in a similar way described above. i would really appreciate your help on this. thanks in advance.
-
Problem with messagequeuein my application i create a msmq , before creating the queue i check for existence and if exist delete it and then create, this works fine, but sometimes i get an exception saying "access denied" a security exception. when creating the msmq i assign the permission too for the local user through "environment.user" but still i get this exception , appreciate your ideas about this . thanks in advance.
-
Problem with reteriving xml data from sql data base.I have a table which have a filed which is xml type, and some more fields such as name and id.i want to read the xml field as well as the other fields in C#, i searched and got this
XmlReader rdr = cmd.ExecuteXmlReader();
but i want to get the other data in the table too. is there any option to do this using one command , or do i have to call two times to get the data. any idea. thanks in advance.
-
msmq throws an exception when called the receive.i'm using a msmq for my application and i create a queue when the application is loading.And to receive the message i set the timespan for 10, in the debug mode it works fine and the messages received as expected, but when i deploy the application in the release mode it gives a "timeout exception" at the receive method. i would really appreciate your ideas about this . thanks in advance.
-
Is there any way to prioratize a task in TPL.i'm new to TPL and , trying to achieve prioritization in tasks using TPL. which means for example , i have to start two tasks parallel (t1 and t2) but i need to give the priority to t1 means both are having messages to deliver but t1 got the highest priority messages so i need to send them before t2 messages. is this possible, thanx in advance
-
problem with calling folderbrowingDialog in a child thread.thanks again . i found the issue , i'm using a separate class for creating threads in the application , and i had set the
l_thrd.SetApartmentState(ApartmentState.STA);
out side that class , when i moved this line into that thread creating class i got my problem solved. but i really don't know difference the two places i used the code thankx .
-
problem with calling folderbrowingDialog in a child thread.thanks,actually what i'm doing is creating a new window in the child thread, so in that window i want to open this folderbrowsingdialog, so at that point i get the exception. and following is the exception i got Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process. thanks in advance.
-
problem with calling folderbrowingDialog in a child thread.in a child thread i'm calling folderbrowsing dialog , i get the exceptiuon and , i got some articles saying i must use STAThreadAttribute attribute for the main method , i did that and the result was the same "Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process." i tried
inthrd.SetApartmentState(System.Threading.ApartmentState.STA);
too but still the same result. can any one have any idea about this. thanx in advance.
-
get the unicode of a character in c#thanx it works for me thax again.
-
get the unicode of a character in c#i'm trying to get the unicode value of a character when the character is given , for example, i can get the character using
string s = '\u0061';
so the character is assigned to s , but now i want the vise versa , means i want to get the unicode of the s , the result should be '\u0061'.any one gat an idea . thanx in advance.
-
get invalid handle when called GetWindowLong.thanx, ok actually i made that call in the onpaint method, but when i debug this.handle returned a value. so even though the handle is there it is not enough , is it the reason , means the control is not completely drawn. thanx
-
get invalid handle when called GetWindowLong.i'm trying to get information about a panel in my application , so i called GetWindowLong passing this.handle in the custom panel class, but i get the error 6 saying invalid handle, this.handle returns "2081229920" value. any idea, thanx in advance.
-
problem with unicode. [modified]thanx Luc, i had made a mistake , i had used "U" instead of "u" , when i use "U" it gives me the unrecognized escape sequence . but with "u" it works fine thank you.
-
problem with unicode. [modified]yea, sorry about that mistake.