.net

Using .Net XmlSerialize for strings with embedded <cr><lf> loses <cr> when deserializing

The following (abysmal) code demonstrates how standard serialize/de-serialize in VB loses the CR when on de-serialize. This can be overcome by applying 'XmlAttribute(DataType:="string")' to Description. Why does it do this? I would like to fix this without applying a 'LF' -> 'CR''LF' in every affected class. This is fixing a bug in exist...

Why does StyleCop recommend prefixing method or property calls with "this"?

I have been trying to follow StyleCop's guidelines on a project, to see if the resulting code was better in the end. Most rules are reasonable or a matter of opinion on coding standard, but there is one rule which puzzles me, because I haven't seen anyone else recommend it, and because I don't see a clear benefit to it: SA1101: The c...

Prevent WebBrowser control from stealing focus?

Is there a way to stop the WebBrowser control from causing its parent form to bring itself to the front? If you use the InvokeScript method to invoke a JavaScript function that calls focus() on an iframe within the main parent document, it will cause the window to bring itself directly to the front(or atleast cause the taskbar icon to s...

Moving a custom configuration group to a separate file

I've recently wrote a rather large custom configuration group. I'm curious if it is possible to move this configuration to a separate file via the following: <configuration> <configSections> <sectionGroup name="MyCustomGroup"> <section name="MyCustomSection"/> </sectionGroup> </configSections> <MyCustomGroup ...

VB.NET overload default functionality when user clicks the X (Close Program)

How do I go about overriding the default functionality when a user clicks the X in a VB.NET form-based application? I am currently handling the MyBase.Closing event... but since it's a DirectX app, I need to do some cleanup before allowing the form the close. Thanks ...

Preferred ordering of terms in namespace name

I'm about to set out on developing a .NET class library that will be consumed by several projects. I've reached a point in my design where I'm not 100% sure which order my namespaces should be nested in. The two options I see are: The shared project uses MyCompany.Common.Web MyCompany.Common.Data MyCompany.Common.Utils with e...

VB.NET - Precise Time

I need access to very precise timing in a .NET application. I need microsecond precision. Is there an easy way to do this in .NET? ...

Best practice of use member of Primitive types

How I should write: long.MaxValue or Int64.MaxValue? Are there standard from Microsoft? ...

Splitting a string at all whitespace

I need to split a string at all whitespace, it should ONLY contain the words themselves. How can I do this in vb.net? Tabs, Newlines, etc. must all be split! This has been bugging me for quite a while now, as my syntax highlighter I made completely ignores the first word in each line except for the very first line. ...

WPF, WCF Seucity using ASP.Net Authentication

I am building an application that has a WCF service that a WPF and ASP.Net MVC client will connect to. I want to use the ASP.Net Membership providers for authentication for both the MVC and WPF clients. What is the best way to go about this? I have read a number of articles on-line (see below) and tried following them through but keep...

Fast work with Bitmaps in C#

I need get all pixels from Bitmap, work this they and save them to Bitmap. If I use Bitmap.GetPixel() and Bitmap.SetPixel() then I have very slow program. How I can fast convert Bitmap to byte[] and back? I need byte[] with size (4 * width * height) and contains RGBA of each pixel ...

C# - Hook into existing COM object

Say we have an existing process (or application) that calls a COM object from an ocx file such as "MyCOMLibrary.ocx". Is there a way to write a C# library to exactly replicate the ocx file? So that the original application can call your C# code rather than the original COM object? You would, of course, have to use identical CLSID and ...

How do I read the PE header of a module loaded in memory?

I'm experimenting with memory access in .NET. At the moment, I have a managed program that starts an unmanaged process and retrieves the BaseAddress of one of its loaded modules (a DLL). What I would like to do is somehow read the PE header of the loaded module so that I can later retrieve the addresses of its exports. Unfortunately, I ...

C# cleanest way to write retry logic?

Occasionally I have a need to retry an operation several times before giving up. My code is like... int retries = 3; while(true) { try { DoSomething(); break; // success! } catch { if(--retries == 0) throw; else Thread.Sleep(1000); } } I would like to rewrite this in a general retry function like... TryThreeTim...

iPhone Web Service Communication

I have been searching around the web all day for the best way to interface my iPhone application with a Linq .NET SOAP web service. I think that this project is my answer: wsdl2objc http://code.google.com/p/wsdl2objc/wiki/UsageInstructions The software creates several classes. It looks great, but the documentation is very limited and ...

embed a WinForms app in a web page?

Is there a way to embed a WinForms app in a web page (assuming the browser is running on a machine with .NET)? ...

Log4Net can't find %username property when I name the file in my appender

Hi, Log4Net doesn't do the correct patternString substitution for my login name (minus domian) that I'm expecting. Anyone have an example of inserting the "username" in the apppender's file name? I've tried a bunch of things, I'm still scratching my head. <appender name="core_Appender" type="log4net.Appender.RollingFileAppender" > <!--...

Create a .NET Windows Service on Windows Mobile 6.x

I would like to create a windows service in .NET that runs on WinMo 6.x.... There r a lot of documentation for how to do that in MFC (and non-MFC) http://msdn.microsoft.com/en-us/library/ms838599.aspx but I can't find any pointers for .NET stuff, is it even doable? Thanks, ...

How do I read the names from a PE module's export table?

I've successfully read a PE header from an unmanaged module loaded into memory by another process. What I'd like to do now is read the names of this module's exports. Basically, this is what I have so far (I've left out a majority of the PE parsing code, because I already know it works): Extensions public static IntPtr Increment(this I...

Best HashTag Regex

I'm trying to find all the hash tags in a string. The hashtags are from a stream like twitter, they could be anywhere in the text like: this is a #awesome event, lets use the tag #fun I'm using the .NET framework (c#), I was thinking this would be a suitable regex pattern to use: #\w+ Is this the best regex for this purpose? ...