How to define the default implementation of an interface in c#?

Here comes the black magic: class Program { static void Main() { IFoo foo = new IFoo(“black magic”); foo.Bar(); } } [ComImport] [Guid(“C8AEBD72-8CAF-43B0-8507-FAB55C937E8A”)] [CoClass(typeof(FooImpl))] public interface IFoo { void Bar(); } public class FooImpl : IFoo { private readonly string _text; public FooImpl(string text) { _text = text; } public void Bar() { Console.WriteLine(_text); } … Read more

HttpWebRequest’s Timeout and ReadWriteTimeout — What do these mean for the underlying TCP connection?

This problem has been debated on another question, see Adjusting HttpWebRequest Connection Timeout in C#. The discussion made my head spin, so I’ll offer my summary. Although, MSDN explains that the HttpWebRequest.Timeout Property applies to HttpWebRequest.GetResponse and HttpWebRequest.GetRequestStream calls, the description is a bit confusing. Jim Mischel is more helpful: Timeout “is the time for … Read more

Is a garbage collector (.net/java) an issue for real-time systems?

To be precise, garbage collectors are a problem for real-time systems. To be even more precise, it is possible to write real-time software in languages that have automatic memory management. More details can be found in the Real Time Specification for Java on one of the approaches for achieving real-time behavior using Java. The idea … Read more

FlagsAttribute Enum problems

The definition of the shift operators means that only the 5 least significant bits are used for 32-bit numbers and only the first 6 bits for 64-bit; meaning: 1 << 5 is identical to 1 << 37 (both are 32) By making it: MsgrVersion9 = 1L << 32 you make it a 64-bit number, which … Read more

How does ItemContainerGenerator.ContainerFromItem work with a grouped list?

You have to listen and react to the ItemsGenerator.StatusChanged Event and wait until the ItemContainers are generated before you can access them with ContainerFromElement. Searching further, I’ve found a thread in the MSDN forum from someone who has the same problem. This seems to be a bug in WPF, when one has a GroupStyle set. … Read more

Is it possible to mark an assembly as deprecated?

When moving types from one assembly to another the correct thing to do is to use a type forwarder, not to mark the old assembly classes as obsolete. See: “CLR Hoser – The Wonders of Whidbey Factoring Features – Part I: Type Forwarders” by Richard Lander (2005)

Can I serialize an ExpandoObject in .NET 4?

I can’t serialize ExpandoObject, but I can manually serialize DynamicObject. So using the TryGetMember/TrySetMember methods of DynamicObject and implementing ISerializable, I can solve my problem which was really to serialize a dynamic object. I’ve implemented the following in my simple test app: using System; using System.Windows.Forms; using System.IO; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; using System.Collections.Generic; using … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)