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

Forcing decimal dot (.) for number parsing

Posted by jpluimers on 2011/10/11

Small but useful, especially in countries that have something else than a dot (.) as decimal digit separator (all of the green countries: probably more than you’d thought).

The C# sourcecode is really simple use a NumberFormatInfo instance (or an instance of another class implementing IFormatProvider) in a Single.ToString call:

                float number = 3.1415;
                NumberFormatInfo numberFormatInfo = new NumberFormatInfo();
                numberFormatInfo.NumberDecimalSeparator = ".";
                numberFormatInfo.NumberGroupSeparator = string.Empty;
                string numberString = number.ToString(numberFormatInfo);

The classes implementing IFormatProvider are CultureInfo, DateTimeFormatInfo and NumberFormatInfo.

–jeroen

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

Registry Search-Replace tools – correcting the havoc after a data migration

Posted by jpluimers on 2011/10/07

A while ago, I found myself in the situation where at a corporate client the user profiles had moved on the LAN. Very understandable: it was one of the migrations towards DFS. They notified this in advance, so I made backups of everything (home drive and user profile) just to make sure.

The move indeed caused all sorts of havoc, because the data was moved, but the registry was only slightly modified.

Some of the errors I got were like these:

[Internet Explorer - Search Provider Default]
A program on your computer has corrupted your default search provider setting for Internet Explorer.

Internet Explorer has reset this setting to your original search provider, Live Search (search.live.com).

Internet Explorer will now open Search Settings, where you can change this setting or install more search providers.
[OK]

and

[Desktop]
\\old-server\old-share\user-id\Desktop refers to a location that is unavailable. It could be on a hard drive on this computer, or on a network. Check to make sure that the disk is properly inserted, or that you are connected to the Internet or your network, and then try again. If it still cannot be located, the information might have been moved to a different location.
[OK]

Below some of the ramblings on what I did to get everything working again, including registry searches when you are not allowed to run RegEdit, searching through text, and the places in the registry that had to change. Read the rest of this entry »

Posted in .NET, C#, Delphi, Development, Encoding, Power User, Software Development, Unicode | Leave a Comment »

C#/Windows: why LastWriteTime can be earlier than CreationTime

Posted by jpluimers on 2011/10/05

I was wondering about file times like these:

CreationTime....: 5-10-2011 10:00:13
LastAccessTime..: 5-10-2011 12:05:58
LastWriteTime...: 5-10-2011 10:00:10

I found the answer on stackoverflow.

If a file is copied to another file, the new file retains the LastWriteTime of the source but the CreationTime will be the time of the copy.

And indeed: the file had been copied from a local directory to a central network location.

–jeroen

via c# – Windows: How to determine if a file has been modified since a given date – Stack Overflow.

Posted in .NET, C#, Development, Power User, Software Development, Windows, Windows 7, Windows 8, Windows Vista, Windows XP | Leave a Comment »

CRC32 Calculators in Delphi and .NET

Posted by jpluimers on 2011/10/05

For a couple of projects, I needed to calculate CRC32 hashes (they same CRC that for instance is used in ZIP files).

A few of the projects used C#, others used Delphi, so here are a few references:

FileFormat.info has a good on-line hasher (that does CRC32, md5 and a bunch of others) accepting both strings, hex bytes and files.

–jeroen

via: CRC32 Calculator.

Posted in .NET, C#, Delphi, Development, Software Development | 1 Comment »

.NET based iOS development: MonoTouch 4.2.2 is out

Posted by jpluimers on 2011/09/30

While starting MonoDevelop this morning, I found out that MonoTouch 4.2.2 is out.

New Features in MonoTouch 4.2.2

This is a minor update to MonoTouch 4.2, with the following bug fixes:

Changes in MonoTouch 4.2.2

Bug fixes:

  • #587 – Full-AOT failure when *not* linking the application
  • #923 – UISegmentedControl: -[NSCFString BridgeSelector]: unrecognized selector sent to instance 0xe084860
  • #931 – UITapGestureRecognizer fails with “unrecognized selector sent”
  • #942 – Wrong binding for CGPDFArray.GetDictionary()
  • #975 – CGPDFDictionary.GetString() returns invalid strings
  • #980 – Cannot use ABPeoplePickerNavigationController after update to 4.2

–jeroen

via: MonoTouch 4.2 – MonoTouch.

Posted in .NET, Development, iOS, iPad, iPhone, Mobile Development, MonoTouch, Software Development | Leave a Comment »

Just uploaded by BASTA.NET conference session materials on .NET Cross Platform Mobile Development on Windows 7, Android and iOS

Posted by jpluimers on 2011/09/27

This morning I gave a well attended session at the BASTA.NET conference on .NET Cross Platform Mobile Development on Windows 7, Android and iOS

If you were attending my session, or just interested in Cross Platform Development with a touch – pun intended – of .NET (and Mono, MonoTouch, MonoDroid, MonoMac, Xcode) then you can download the materials here: http://bo.codeplex.com/SourceControl/changeset/changes/70132 and http://bo.codeplex.com/SourceControl/changeset/changes/70133 (yes, 2 change sets: somehow with SVN  “Check for modifications” I still missed part of the batch).

It consists of the PDF with session slides and the demo apps based on an old (.NET 1.1 and .NET Compact Framework 1.0 era) C# tic tac toe demo (which was based on some Turbo Pascal sources from 20+ years ago), now revived for the Windows Phone 7 (with Visual Studio), iOS (with MonoTouch) and Android (with MonoDroid) platforms.

The conference is held at the beautifully designed Rheingoldhalle conference center adjacent to the Rhine (German: Rhein) river in Mainz, Germany.

Oh: and I enjoyed a bit of the great weather outside (while it lasts <g>).

–jeroen

Posted in .NET, BASTA!, C#, Conferences, Development, Event, Software Development | Leave a Comment »

C# Using Blocks can Swallow Exceptions | DigitallyCreated

Posted by jpluimers on 2011/09/22

I got to the SafeUsingBlock extension method because of a nice StackOverflow thread on exceptions swallowed in a using block.

Actually, you can broaden the case into a wider scope: in any language when you protect resources in a try finally block (essentially, a using will turn into an implicit try finally block), and both the core logic and the finally throw an exception, the exception from the core block is swallowed.

Simple C# example:

using System;
public class Example
{
    public void Main()
    {
        try
        {
                try
                {
                    throw new ApplicationException("logic block");
                }
                finally
                {
                    throw new ApplicationException("finally block");
                }
        }
        catch (Exception error)
        {
            Console.WriteLine(error.ToString());
        }
    }
}

Simple Delphi example:

program Example;
begin
  try
    try
      raise Exception.Create('logic block');
    finally
      raise Exception.Create('finally block');
    end;
  except
    on error: Exception do
    begin
      Write(error.ClassName, ' ', error.Message);
    end;
  end;
end.

Both examples will only write out the finally block exception message, not the logic block exception message.

This is a corner case (like the example from the MSDN documentation), from which the SafeUsingBlock protects you from by providing an AggregateException class.

In C#, it is a guideline to avoid throwing exceptions in the Dispose when implementing the disposable pattern.

This is good practice in any programming environment: when disposing objects, only throw exceptions in very critical situations when the containing process has been corrupted.

Practically this is very easy as the disposers are very thin and should not contain any business logic, so it is pretty easy to spot places where the program state really is corrupt.

An other alternative is for instance have a Close method that throws an exception, and a disposer not throwing.

–jeroen

via C# Using Blocks can Swallow Exceptions | DigitallyCreated.

Posted in .NET, C#, Delphi, Development, Software Development | 7 Comments »

Windows Metro Style Apps Developer Downloads: very early version of Windows 8

Posted by jpluimers on 2011/09/14

The download page states

The Windows Developer Preview is a pre-beta version of Windows 8 for developers.

But of course this is also interesting to designers and regular users: getting a hands-on impression of what Metro will bring to Windows 8.

–jeroen

via: Windows Metro Style Apps Developer Downloads.

Posted in .NET, Delphi, Development, Power User, Software Development, Windows, Windows 8 | 2 Comments »

Entity Framework: EF4 – update model from database ignores some changes

Posted by jpluimers on 2011/09/13

Almost a year ago there was a post on the MSDN forums titled EF4 – update model from database ignores some changes.

These are the changes it ignores that I found so far:

  • Column renames
  • Column data type changes
  • Changed foreign key relations

Have you found others?

Which EF versions are worse/better in this respect?

Note that the EF support in Visual Studio 2010 does not warn you if the the model is incompatible with your database.
You will get errors like this at run-time:

Read the rest of this entry »

Posted in .NET, .NET ORM, Database Development, Development, EF Entity Framework, Software Development | 2 Comments »

Triest bericht: de SDC gaat dit jaar niet door. De altijd kleurrijke conferentie van de SDN voor Nederlandse software ontwikkelaars heeft het dit jaar niet gehaald

Posted by jpluimers on 2011/09/12

Quote van de SDC site:

Helaas heeft de SDN moeten besluiten om SDC voor dit jaar (2011) van de agenda te halen.

In 2012 zullen wij opnieuw een SDC organiseren.

De aankomende SDE van 9 december is reeds in ver gevorderd stadium

Wij hopen u daar te mogen begroeten

Echt heel jammer, want de SDC bracht al heel lang kleur in het landschap van de Nederlandse software ontwikkelaar, juist vanwege de keur aan sprekers (ze haalden altijd de meeste interessante sprekers uit buiten- en binnenland).

SDC (en haar voorloper CttM) was erbij toen Clipper begon, Delphi begon en .NET begon. Warme herinneringen komen boven aan al die prachtige conferenties, en mensen die ik er heb leren kennen.

Laten dus hopen dat het volgend jaar gewoon weer door gaat.

–jeroen

via SDN – Software Development Network > SDN > SDN Event > SDN Conferences 2011.

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