.net

DataGridView from Binary File

I'm reading data out of a binary file into structs in C#. What's the best way to populate a DataGridView with these records? I've only ever used the Binding with actual databases and in fact all the examples I can find cover using flat text files or databases. Should I not be using the DataGridView at all? Should I be creating a Data...

Use XDocument as the source for XmlSerializer.Deserialize?

I would like to invoke XmlSerializer.Deserialize passing it an XDocument. It can take a Stream, an XmlReader or a TextReader. Can I generate one of the above from XDocument without actually dumping the XDocument into some intermediate store, such as a MemoryStream? It seems that what I'm after is an implementation of XmlReader that wor...

XAML ImageBrush using a BitmapImage without a URI

I have the following XAML that displays a cover image for a book using a URI: <Rectangle.Fill> <ImageBrush ImageSource="{Binding CoverUrl}" /> </Rectangle.Fill> However, the image I would like to use is not on disk anywhere or accessible via a URI; it comes from inside a binary file that I parse out into a BitmapImage object. Whe...

StyleCop integration with CI build process (Criuse Control, Nant, msbuild and StyleCop)

I have been asked to integrate StyleCop in our CI build process in such a way that: Individual project file in our (large) solution are not affected I don't have to use any 3rd party tool The first requirement (and I don't fully understand this yet) is due to the fact that we don't want to run StyleCop on our entire solution straight...

Difference between Activator.CreateInstance() and typeof(T).InvokeMember() with BindingFlags.CreateInstance

Forgive me if this question has already been asked and answered. Given a class of type T, what is the difference between the following? T myObj = Activator.CreateInstance<T>(); T myObj = typeof(T).InvokeMember(null, BindingFlags.CreateInstance, null, null, null); Is one solution preferred over the other? ...

Why am I seeing slower performance here from WCF than Remoting?

Everything I'm told says that WCF should be at least as fast as remoting. I have a specific scenario here, however, where it isn't even close, and I'm wondering if someone can spot something obvious that I'm doing wrong. I'm looking into the possibility of replacing remoting with wcf for the in-process intra-appdomain communication heavy...

Best practices: When should I use a delegate in .NET?

Possible Duplicates: Delegate Usage : Business Applications Where do I use delegates? Hi, I'm new to the concept of a delegate in .NET - I haven't really used them yet and think they are probably there for a good reason - when should I be using a delegate? Examples are very welcome. ...

Storyboard duration cutting off animation

I'm running into a really weird issue with Silverlight 3. I've defined an extension method to create a storyboard around a given DoubleAnimation and play that animation. I know the default duration for storyboards in Silverlight is 1s, but I would like to change that for my animations. However, when I set a different duration, instead of...

Using Office 2007 UI ribbon .dll file with my project

I have downloaded the official office 2007 UI ribbon .dll, but now what? I am coding in VB.net. I do not know where to place this .dll, and I do not see any additional controls anywhere at all. The readme explains how to license your copy, which I have done. Now what? I am hoping to magically see the ribbon control in the list of compon...

Deserializing empty xml attribute value into nullable int property using XmlSerializer

Hello, I get an xml from the 3rd party and I need to deserialize it into C# object. This xml may contain attributes with value of integer type or empty value: attr=”11” or attr=””. I want to deserialize this attribute value into the property with type of nullable integer. But XmlSerializer does not support deserialization into nullable ...

Random LINQ to SQL records w/ "int" primary keys

How do I get a 5 random records from a LINQ to SQL Table[T]? All the examples I've found via google use uniqueidentifier as the primary key http://www.davidmuto.com/Blog.muto/View/random-records-with-linq-to-sql Is there a way to do this when the primary key is an auto-incrementing integer? Some records can be deleted too, so the min...

How can I achieve a modulus operation with System.TimeSpan values, without looping?

I'm in a very performance-sensitive portion of my code (C#/WPF), and I need to perform a modulus operation between two System.TimeSpan values in the quickest way possible. This code will be running thousands of times per second, and I would very much prefer to avoid using a manual loop calculation - at all costs. The idea of a modu...

Visual Studio 2008 Project won't load, but no errors

Hi, I've got a VS 2008 SP1 solution with multiple projects. Two of the projects appear in the list, but they have a folder icon instead of the normal project icon. The folder is grayed out and I can't expand the folder. The files are definitely available and security is fine. I edited the SLN file and removed the projects, then re-...

How to treat nulls in equality comparisons?

When I have to implement equality comparers for public class SampleClass { public int Prop { get; set; } } Should I make null == new SampleClass() and new SampleClass() == null and new SampleClass().Equals(null) false? And what about new SampleClass() != null Should it be also false? UPDATE People are questioning th...

In WCF is there a way to set ServiceContract Namespace assembly-wide?

In WCF land, you can specify a Namespace prefix for anything that has a [DataContract] like so: [DataContract(Namespace="MyApp")] public class whatever... However if you wanted to apply a common namespace to ALL data contracts assembly-wide, you can use the ContractNamespaceAttribute: /* in AssemblyInfo.cs */ [assembly: ContractNames...

How do I view Windows Azure Analytics

I've been running some background processes using the Worker role in Azure to test out Azure to see if it something I can consider for one of my projects. When I click on the Analytics tab, I get a message saying "Coming soon.". Is there any way for me to determine some metrics? I'm mostly interested in trying to calculate a potential ...

Byte order: converting java bytes to c#

While converting a Java application to C# I came through a strange and very annoying piece of code, which is crucial and works in the original version. byte[] buf = new byte[length]; byte[] buf2 = bout.toByteArray(); System.arraycopy(buf2, 0, buf, 0, buf2.length);; for (int i = (int) offset; i < (int) length; ++i) { buf[i] = (byte) 25...

A .NET custom attribute to perform impersonation?

I have some methods that need to run as a certain service account, so I do the normal thing: public DoSomeWorkAsServiceAccount() { ... // assume I am given tokenHandle WindowsIdentity newId = new WindowsIdentity(tokenHandle); WindowsImpersonationContext impersonatedUser = newId.Impersonate(); ... // do the work...

TeamCity & MSBuild integration

Is there any way to get TeamCity's build numbering to match the publish version (ApplicationRevision) number generated by MSBuild's publish task? ...

How to Compare two exe files One built from the old code now and the existing exe that was built a few months ago?

I am looking to compare two exe files. I should ensure that the existing exe on the server is a product of the code I have now. I am using >dumpbin /rawdata oldfile.exe > oldfile.txt >dumpbin /rawdata newfile.exe > newfile.txt >fc /b oldfile.txt newfile.txt //compare them like this >windiff oldfile.txt newfile.txt // or this I gue...