Redirect Trace output to Console

You can add the following to your exe’s .config file. <?xml version=”1.0″?> <configuration> <system.diagnostics> <trace autoflush=”true”> <listeners> <add name=”logListener” type=”System.Diagnostics.TextWriterTraceListener” initializeData=”cat.log” /> <add name=”consoleListener” type=”System.Diagnostics.ConsoleTraceListener”/> </listeners> </trace> </system.diagnostics> </configuration> I included the TextWriter as well, in case you’re interested in logging to a file.

.net: System.Web.Mail vs System.Net.Mail

System.Web.Mail is not a full .NET native implementation of the SMTP protocol. Instead, it uses the pre-existing COM functionality in CDONTS. System.Net.Mail, in contrast, is a fully managed implementation of an SMTP client. I’ve had far fewer problems with System.Net.Mail as it avoids COM hell.

ClickOnce and IsolatedStorage

You need to use application scoped, rather than domain scoped, isolated storage. This can be done by using one of IsolatedStorageFileStream’s overloaded constructors. Example: using System.IO; using System.IO.IsolatedStorage; … IsolatedStorageFile appScope = IsolatedStorageFile.GetUserStoreForApplication(); using(IsolatedStorageFileStream fs = new IsolatedStorageFileStream(“data.dat”, FileMode.OpenOrCreate, appScope)) { … However, now you will run into the issue of this code only working … Read more

Reading dll.config (not app.config!) from a plugin module

You will need to load the x.dll.config (with the Configuration API) yourself. All the automatic file handling (including the .Settings) is all about machine.config/y.exe.config/user-settings. To open a named config file: Reference System.Configuration.dll assembly. Using System.Configuration Create code like: Configuration GetDllConfiguration(Assembly targetAsm) { var configFile = targetAsm.Location + “.config”; var map = new ExeConfigurationFileMap { ExeConfigFilename … Read more

How to use Reflection to Invoke an Overloaded Method in .NET

You have to specify which method you want: class SomeType { void Foo(int size, string bar) { } void Foo() { } } SomeType obj = new SomeType(); // call with int and string arguments obj.GetType() .GetMethod(“Foo”, new Type[] { typeof(int), typeof(string) }) .Invoke(obj, new object[] { 42, “Hello” }); // call without arguments obj.GetType() … Read more

Registry Watcher C#

WMI can sometimes be interesting to work with…I think I understand your question, so take a look at the code snippet below and let me know if it’s what you’re looking for. // ——————————————————————————————————————— // <copyright file=”Program.cs” company=””> // // </copyright> // <summary> // Defines the WmiChangeEventTester type. // </summary> // ——————————————————————————————————————— namespace WmiExample { … Read more