The Wiert Corner – irregular stream of stuff

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

  • My work

  • My badges

  • Twitter Updates

  • My Flickr Stream

    20140508-Delphi-2007--Project-Options--Cannot-Edit-Application-Title-HelpFile-Icon-Theming

    20140430-Fiddler-Filter-Actions-Button-Run-Filterset-now

    20140424-Windows-7-free-disk-space

    More Photos
  • Pages

  • All categories

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

    Join 1,501 other followers

Archive for the ‘.NET’ Category

anoymyous type trick: Check if KeyValuePair exists with LINQ’s FirstOrDefault – via Stack Overflow

Posted by jpluimers on 2015/08/27

When you have a Dictionary<TKey, TValue>, then LINQ results will get you a enumerables of KeyValuePair<TKey, TValue>.

Since KeyValuePair is a struct, selecting FirstOrDefault will not get you a null, but a default(KeyValuePair<TKey, TValue>) which is a lot harder to handle than null.

Sometimes, being able to get a null out of FirstOrDefault is very useful, so a bit thank you to Marc Gravell for answering this very neat trick:

If you just care about existence, you could use ContainsValue(0) or Any(p => p.Value == 0) instead? Searching by value is unusual for a Dictionary<,>; if you were searching by key, you could use TryGetValue.

One other approach:

       var record = data.Where(p => p.Value == 1)
            .Select(p => new { Key = p.Key, Value = p.Value })
            .FirstOrDefault();

This returns a class – so will be null if not found.

The trick is this portion:

p => new { Key = p.Key, Value = p.Value }

It introduces an anonymous type with two fields: Key and Value. (Note you can introduce any anonymous type here). Since these are classes, FirstOrDefault will return null if nothing was found.

–jeroen

via:

Posted in .NET, .NET 3.5, .NET 4.0, .NET 4.5, C#, C# 3.0, C# 4.0, C# 5.0, C# 6 (Roslyn), Development, Software Development | Leave a Comment »

.NET enable and disable Fusion log to investigate assembly loading issues

Posted by jpluimers on 2015/08/18

Had to investigate some Assembly Loading issues, so I wrote two batch files to enable and disable the .NET Fusion Log:

They modify the HKLM\Software\Microsoft\Fusion key REG_DWORD value EnableLog.

A few notes:

  • It is very important to turn of the Fusion log settings as soon as you are finished investigating. Fusion logs potentially take a lot of resources.
  • When you have a .NET host like ISS, you have to restart that host (for instance by running iisreset)
  • There is also Fuslogvw.exe Assembly Binding Log Viewer, but I like logging over viewing as logs are persistent.
  • There are more values under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion you can configure; see the answer by Gary Kindel on StackOverflow:
    • DWORD ForceLog set value to 1
    • DWORD LogFailures set value to 1
    • DWORD LogResourceBinds set value to 1
    • String LogPath set value to folder for logs e.g. C:\FusionLog\ (ensure the final backslash is there and the folder exists).

–jeroen

via:

Posted in .NET, .NET 1.x, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, C# 6 (Roslyn), Development, Software Development | Leave a Comment »

Fuzzing in addition to Unit Tests – via: David Millington G+

Posted by jpluimers on 2015/08/11

I need to give this link from Jonathan Lange which was shared by David Millington some thought:

Embedded in Academia : How to Fuzz an ADT Implementation.

There they add fuzzers to help testing an ADT: in this case an Abstract Data Type in the form of  a red-black tree.

And then see if it can be added to DUnit and NUnit or MSTest/VSTest in some way.

In the original post by Jonathan Lange, an important remark was made by Eric Castelijn:

… the downside being that having non deterministic tests means having test failures that are hard to repeat

When fuzzing multiple or composite values, the chances that you will hit interesting edge cases semi-reliably will drop dramatically, in my experience

–jeroen

via “This post has two points. First, you should write ADT fuzzers. It is often….

Posted in .NET, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, C#, C# 2.0, C# 3.0, C# 4.0, C# 5.0, C# 6 (Roslyn), Delphi, Delphi 2007, Delphi 2009, Delphi 2010, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Delphi XE5, Delphi XE6, Delphi XE7, Delphi XE8, Development, Software Development | 2 Comments »

Translating non-English error messages into English

Posted by jpluimers on 2015/08/06

For a long time, I’ve persuading people to install English versions of their operating systems (especially on server side) at least for some parts of their environment.

The main reason is that searching for English error messages gives you a much bigger chance of finding the cause than non-English ones.

I’m still standing by that recommendation, but life has become a bit easier because of these two sites that offer quite good translations of Windows Error messages in many languages to English:

I like the latter a bit more because of the overview, but the former more because of the catalog.

The way I landed there was because of a search for “Cannot SetData on a frozen OLE data object” which I bumped into for one of my C# .NET projects.

–jeroen

Posted in .NET, C#, Development, Power User, Software Development, Windows, Windows 7, Windows 8, Windows 8.1, Windows 9, Windows Server 2003, Windows Server 2003 R2, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2, Windows Vista | Leave a Comment »

Difference Between Int32.Parse, Convert.ToInt32, and Int32.TryParse – CodeProject

Posted by jpluimers on 2015/08/05

Every C#/VB/.NET developer should read Difference Between Int32.Parse, Convert.ToInt32, and Int32.TryParse – CodeProject.

Then also read TryParse with default values.

It is all about handling values that are not Integers, Overflow values and Nulls. There are subtle differences, in the handling of the methods, and the exceptions they could throw: ArgumentNullException, FormatException and OverflowException.

Finally read all about the NumberStyles enumeration, IFormatProvider interface and CultureInfo (especially the difference between InvariantCulture, CurrentCulture, CurrentUICulture and InstalledUICulture).

Because getting your conversions right matters.

–jeroen

Posted in .NET, Software Development, Development, C#, Prism, C# 2.0, C# 3.0, C# 4.0, VB.NET, Mono for Android, .NET 4.5, C# 5.0, C# 1.0, .NET 3.5, .NET 1.x, .NET 2.0, .NET 3.0, .NET 4.0, VB.NET 7.0, VB.NET 7.1, VB.NET 8.0, VB.NET 9.0, VB.NET 10.0, VB.NET 11.0, RemObjects C#, Mono, C# 6 (Roslyn) | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.

Join 1,501 other followers

%d bloggers like this: