The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,861 other subscribers

Archive for the ‘.NET’ Category

Converting Visual Studio 2003 WinForms to Visual Studio 2005/2008/2010/2012 partial classes (via: Duncan Smart’s Weblog)

Posted by jpluimers on 2013/01/10

In the .NET 1.x past, the WinForms designers in Visual Studio .NET and Visual Studio 2003 would put the C# or VB.NET code containing the form code as the InitializeComponent method of the top most class monolithic C# and VB.NET files that also contain the user code (for events and such).

As of Visual Studio 2005 (actually: Whidbey and higher), this code is based on partial classes. For each form (actually designable entity, but lets limit this to WinForms forms) you get a MyForm.cs and MyForm.Designer.cs

As a side note, with a bit of effort, you can generate the Windows Form Designer generated code yourself as this answer shows. This is for instance convenient when you have form definitions in a different technology and want to convert it to WinForms, WPF or another form of designer based .NET code.

I long time ago I wrote a short manual for co-workers on converting the monolithic files (for people interested, it is below).

Since then I found a couple of very interesting links: Read the rest of this entry »

Posted in .NET, .NET 1.x, .NET 2.0, .NET 3.0, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Development, Software Development, Visual Studio 11, Visual Studio 2002, Visual Studio 2003, Visual Studio 2005, Visual Studio 2008, Visual Studio 2010, Visual Studio and tools, WinForms | 1 Comment »

.NET/C#: what is the meaning of “Comparing two IEnumerables for equality”?

Posted by jpluimers on 2013/01/09

Until I realized that comparing two IEnumerables needed some extra thought, I wondered why Assert.AreEqual would not support them.

jrista pointed me in the right direction answering a question about c# – How does Assert.AreEqual determine equality between two generic IEnumerables?

The correct answer is “it doesn’t”, but that is really dense.

IEnumerables are just that: being generic or normal, they allow you to enumerate things. They can get you an enumerator (generic or not) that has a notion of Current (generic or normal) and such, but no knowledge of the underlying data.

Comparing them needs you to think about the enumeration and the underlying data at the same time. You can get two kinds of comparisons: Read the rest of this entry »

Posted in .NET, .NET 3.5, .NET 4.5, C#, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Development, Software Development | Leave a Comment »

Delphi and C# compiler oddities

Posted by jpluimers on 2013/01/08

When developing in multiple languages, it sometimes is funny to see how they differ in compiler oddities.

Below are a few on const examples.

Basically, in C# you cannot go from a char const to a string const, and chars are a special kind of int.

In Delphi you cannot go from a string to a char. Read the rest of this entry »

Posted in .NET, ASCII, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Delphi, Delphi 2009, Delphi 2010, Delphi XE, Delphi XE2, Development, Encoding, Software Development, Unicode | Leave a Comment »

Wordify: .NET/C# – Convert enums to human readable values – Stack Overflow

Posted by jpluimers on 2013/01/03

You’d hope that a method like Wordify with the signature below would be simple right?

public static string Wordify(string pascalCaseString)

Not so. Read the rest of this entry »

Posted in .NET, C#, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Development, Software Development | 1 Comment »

.NET regular expressions classic: to compile or not to compile?

Posted by jpluimers on 2013/01/01

Every time I use regular expressions (or post about them), it makes me think about the classic RegEx post by Jeff Atwood: to compile or not to compile.

BTW: Happy 2013!

–jeroen

Posted in .NET, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Development, RegEx, Software Development | Leave a Comment »

.NET/C#: use Assembly.GetName() if you to access internal/private information from Assembly

Posted by jpluimers on 2012/12/26

There is a lot of information in Assembly that is either internal or private. Luckily you van get an AssemblyName instance through Assembly.GetName() or Assembly.GetName(Boolean) which has quite a few public members that get initialized while calling the internal AssemblyName.Init method.

This is the member mapping of AssemblyName members to Assembly members:

AssemblyName member Assembly member
Name GetSimpleName() *internal
GetPublicKey() GetPublicKey() *internal
GetPublicKeyToken() null
Version GetVersion() *internal
contains the AssemblyVersionAttribute of the assembly
CultureInfo GetLocale() *internal
HashAlgorithm GetHashAlgorithm() *private
VersionCompatibility AssemblyVersionCompatibility.SameMachine
CodeBase GetCodeBase(Bool) *internal
Flags GetFlags() | AssemblyNameFlags.PublicKey
KeyPair null
ProcessorArchitecture complex set of calls

–jeroen

via: Assembly.GetName Method (Boolean) (System.Reflection).

Posted in .NET, .NET 3.5, .NET 4.5, ASP.NET, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Development, Software Development | Leave a Comment »

Learning F# – Stack Overflow

Posted by jpluimers on 2012/12/20

If you want to learn F#, start at this SO question:

Learning F# – Stack Overflow.

–jeroen

Posted in .NET, Development, F#, Software Development | Leave a Comment »

.NET/C# – How to create a file and its parent directories in one method call? (via: Stack Overflow)

Posted by jpluimers on 2012/12/18

Ever since .NET 1 there has been no built-in way to create a file including all its parent directories.

Hence small FileHelper class far below.

The fundament of the class is this CreateUnderlyingDirectory method, that uses System.IO.Path.GetDirectoryName to obtain the parent directory of a path, and then System.IO.Directory.CreateDirectory to create it (and any parent directories) if needed.

        public static void CreateUnderlyingDirectory(string path)
        {
            string directoryPath = Path.GetDirectoryName(path);
            Directory.CreateDirectory(directoryPath); // NOP if it exists, will create all parent directories if not
        }

A few helper methods get you a StreamWriter either empty/appended, or always empty Read the rest of this entry »

Posted in .NET, .NET 3.5, .NET 4.5, C#, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Development, Software Development | Leave a Comment »

.NET/MSBuild: A solution for Skipped Build: Project: MyProject, Configuration: Debug Any CPU; Project not selected to build for this solution configuration

Posted by jpluimers on 2012/12/12

One of our solutions would not completely build.

An console application that was hardly used, was not built.

No warnings or hints in the “Error List”.

This is what the build log would show:

------ Skipped Build: Project: App404.UI, Configuration: Debug Any CPU ------
Project not selected to build for this solution configuration
========== Build: 21 succeeded or up-to-date, 0 failed, 1 skipped ==========

None of the suggestions at the Stack Overflow question visual studio 2005: skipping builds for unknown reason? would work (not even running msbuild with the highest verbosity level, you get so much information that it is impossible to weed the useful from the useless information).

Luckily, About | WishMesh pointed me in the right direction: inspect your solution file for anomalies. Read the rest of this entry »

Posted in .NET, C#, C# 4.0, Development, Software Development, Visual Studio 11, Visual Studio 2005, Visual Studio 2008, Visual Studio 2010, Visual Studio and tools | Leave a Comment »

x64 debugging on Windows: usually not directly by the IDE, but trough a debug helper process (msvsmon / PAServer / dbkw64_16_0)

Posted by jpluimers on 2012/12/07

While developing x64 applications, most Windows development tools are actually running in x86 mode, and use an intermediate x64 layer to debug the x64 process even for local debugging.

For Visual Studio 2008 and up, this is msvsmon.exe (for Delphi XE2 and up it is PAServer.exe for remote debugging or [WayBack] dbkw64_16_0.exe for local debugging, other tools use a similar mechanism).

The fun thing with Visual Studio is that when msvsmon.exe fails to load locally, you get a misleading error message:

[Microsoft Visual Studio]
Error while trying to run project: Unable to start debugging.
The Microsoft Visual Studio Remote Debugging Monitor has been closed on the remote machine.
[OK]

I found two workarounds myself :

  1. Kill msvsmon.exe if it is running but Visual Studio cannot talk to it
  2. Restart Visual Studio if it cannot start msvsmon.exe

I learned the why from Steve Steiner: he posted the StackOverflow answer explaining msvsmon.exe is also used for local x64 debugging.

Delphi XE2 and up sometimes have a similar cryptic message (I forgot to jolt it down, next time I come across it, I will edit this blog post) and usually killing PAServer.exe or dbkw63*.exe or restarting the IDE solves it.

–jeroen

via:

Posted in .NET, Debugging, Delphi, Delphi x64, Development, QC, Remote Debugging, Software Development, Visual Studio 11, Visual Studio 2008, Visual Studio 2010, Visual Studio and tools | Leave a Comment »