Validation does not work when I use Validator.TryValidateObject

I found the answer here: http://forums.silverlight.net/forums/p/149264/377212.aspx MVC recognizes the MetaDataType attribute, but other projects do not. Before validating, you need to manually register the metadata class: TypeDescriptor.AddProviderTransparent( new AssociatedMetadataTypeTypeDescriptionProvider(typeof(Customer), typeof(CustomerMetadata)), typeof(Customer)); var isValid = Validator.TryValidateObject(new Customer(), context, results, true);

SetWindowsHookEx failing in .NET 4.0 on 32-bit machine with “module not found”?

Yup, I think you understand what’s going on. SetWindowsHookEx() requires a valid module handle, and verifies it, but it doesn’t actually use it when you set a low-level hook. You just need a valid handle, it doesn’t matter which specific one. Calling LoadLibrary(“user32.dll”) is a good way to get a handle, that DLL will always … Read more

How Can I add properties to a class on runtime in C#?

You cannot extend an existing class with new members at runtime. However, you can create a new class using System.Reflection.Emit that has the existing class as base class. typeBuilder.SetParent(typeof(MyClass)); typeBuilder.DefineProperty(“Prop1”, …, typeof(System.Int32), null); … See TypeBuilder.DefineProperty Method (String, PropertyAttributes, Type, Type[]) for a full example.

Inserting Certificate (with privatekey) in Root, LocalMachine certificate store fails in .NET 4

I had exactly the same problem and the solution turned out to be really simple. All I had to do is to pass X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet to X509Certificate2’s ctor. Now you are using the DotNetUtilities to convert the bouncycastle certificate to the .net one, but the helper method creates the .net cert with the DefaultKeySet … Read more

tech