How to iterate the List in Reflection

You just need to cast it: var collection = (List<Student>) studentPro.GetValue(studentObj,null); The value returned to you and stored in var is of type object. So you need to cast it to List<Student> first, before trying looping through it. RANT That is why I personally do not like var, it hides the type – unless in … Read more

How can I find the upgrade code for an installed application in C#?

I have discovered the upgrade codes are stored in the following registry location. HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UpgradeCodes The registry key name is the upgrade code and the registry key value name is the product code. I can easily extract these values however the codes are stored in a different format. The red circle shows the formatted upgrade code, … Read more

Parsing a string C# LINQ expression

You have some options: Do something homegrown, parsing the text and building an Expression Tree. The standard approach to this would be to use a language parser to parse the string (like ANTLR). Use CodeDOM to compile the query (NOT recommended for a Production environent as this is slow and generates an assembly per compilation … Read more

How to kill a process without getting a “process has exited” exception?

You could P/Invoke TerminateProcess passing it Process.Handle. Then manually evaluating the cause of it (GetLastError()). Which is roughly, what Process.Kill() does internally. But note that TerminateProcess is asynchronous. So you’d have to wait on the process handle to be sure it is done. Using Process.Kill() does that for your. Update: Correction, Process.Kill() also runs asynchronously. … Read more

Send/Receive message To/From two running application

There are different ways to share information between 2 processes. First at all you have to think if both processes are going to be always in the same machine or not when your application scales up. Different Machines Use TCP/UDP socket connection (Can be the quickest solution) Use MSMQ Use WebServices, WCF or Restful Web … Read more

Call C# dll from Delphi

You may have more luck skipping the COM part by using my project template for unmanaged exports class MyDllClass { [DllExport] static int MyDllMethod(int i) { MessageBox.Show(“The number is ” + i.ToString()); return i + 2; } } In Delphi, you’d import it like so: function MyDllMethod(i : Integer) : Integer; stdcall; extern ‘YourAssembly.dll’; I … Read more