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,862 other subscribers

Archive for the ‘.NET 4.0’ Category

.NET/C#: extension method shows what SQL + parameter values are sent to the server (via StackOverwlow)

Posted by jpluimers on 2013/08/28

Every once in a while you are in situation where you are not allowed to use SQL Server Profiler, nor to see any query plans, but you still want see the SQL going from your .NET apps to the database server.

With that SQL, you can feed it through your favourite database tool, and see where the culprit is.

There are various ways of getting rudimentary or a bit more advanced SQL out of this. Flapper posted a solution that is specific for SQL Server (and requries both ObjectExtensions.cs and StringExtensions.cs from the DotNetX library), but posted more ready to use SQL.

I opted – and wanted to hank Justin Harris – for this piece of code on StackOverflow, which works on any IDbCommand (so you can use it for any ADO.NET data provider, like SQL Server, OLE DB, Oracle, etc):

While you will not be able to plug is into something like Enterprise Manager to run it works for logging.

public static string ToReadableString(this IDbCommand command)
{
    StringBuilder builder = new StringBuilder();
    if (command.CommandType == CommandType.StoredProcedure)
        builder.AppendLine("Stored procedure: " + command.CommandText);
    else
        builder.AppendLine("Sql command: " + command.CommandText);
    if (command.Parameters.Count > 0)
        builder.AppendLine("With the following parameters.");
    foreach (IDataParameter param in command.Parameters)
    {
        builder.AppendFormat(
            "     Paramater {0}: {1}",
            param.ParameterName,
            (param.Value == null ?
            "NULL" : param.Value.ToString())).AppendLine();
    }
    return builder.ToString();
}

answered Apr 12 ’10 at 20:26; juharr

You saved my day! Not being allowed to use the profiler, this is a great way to get the actual SQL, then run it from SSMS or the Enterprise Manager. – Jeroen Wiert Pluimers

I pasted it in a DataExtensions class like this: Read the rest of this entry »

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

.NET/VB.NET: solving the error “The system cannot find the file specified.” “\Temp\.NETFramework,Version=v4.0.AssemblyAttributes.vb”

Posted by jpluimers on 2013/08/22

Bumped into this error a while ago in Visual Studio 2010:

Kind Error
Number 80
Description Unable to open module file ‘C:\Users\username\AppData\Local\Temp\.NETFramework,Version=v4.0.AssemblyAttributes.vb’: The system cannot find the file specified.
File C:\Users\username\AppData\Local\Temp\.NETFramework,Version=v4.0.AssemblyAttributes.vb
Line 1
Column 1
Project VbPowerPack

(I replaced the column separators by line separators to make it more readable)

The code was using the VBPowerPack download I wrote about before, but that appeared to be irrelevant.

This is how I solved it:

  1. Build -> Clean Solution
  2. Build -> Rebuild Solution
  3. File -> Close Solution
  4. View -> Start Page
  5. Open most recent solution from the Start Page

I’m not the only one that has this problem every now and then.

Thanks to these posts that helped me out with the above solution:

–jeroen

via: “The system cannot find the file specified.” “\Temp\.NETFramework,Version=v4.0.AssemblyAttributes.vb”

Posted in .NET, .NET 4.0, Development, Software Development, VB.NET, VB.NET 10.0, Visual Studio 2010, Visual Studio and tools | 4 Comments »

.NET/C#: LineSplit tool for splitting large text files every number of lines

Posted by jpluimers on 2013/08/21

c# – How to split a text file into multiple files? – Stack Overflow.

c# – File.ReadLines without locking it? – Stack Overflow.

c# – Whats the fastest wto read a file by one line at a moment – Stack Overflow.

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

Paint.NET v3.5.11 is now available (via: Paint.NET Blog)

Posted by jpluimers on 2013/08/17

Programmers scale: time versus project completeness

Programmers scale: time versus project completeness

I totally agree that Paint.NET is the best free image and photo editor on Windows.

Writing quality software takes time, not only when writing it in spare time like Rick Brewster does. Getting things “right” is a tedious process and often will set you back: just watch the graph on the right.

So I’m not surprised that it took a very long time after the first Paint.NET 4.0 idea in 2008 to get “close” to a release.

And indeed, it looks like Rick has become much closer which will please many people waiting for Paint .NET 4.

I’m really glad with the announcement that Paint.NET v3.5.11 BETA is now available – Paint.NET Discussion & Questions – Paint.NET Forum.

Edit: while writing this, the final Paint.NET v3.5.11 came out.

It paves the way for Paint .NET 4.0 update in the future, and fixes/improves quite a few things.

A few quotes from it:

This is probably not the update you were expecting I need to push out an update to v3.5 in preparation for the eventual release of v4.0 […] releasing a “beta” today […] I’ll be pushing out the Final/RTM in a few days.

The primary goal of this update is preparing for the v4.0 release: v3.5.10 will not be able to offer the v4.0 update, but v3.5.11 will. […]

Here are the changes for this release:

  • Fixed: The Gaussian Blur effect was incorrectly calculating alpha values for non-opaque pixels. (http://forums.getpaint.net/index.php?/topic/18483-gaussian-blur-mistreats-alpha/)
  • Improved performance of the Sharpen effect by about 25%
  • Improved performance of the Median effect by about 30%
  • Improved performance of the Fragment effect by about 40%
  • Improved performance of the Unfocus effect by about 100%
  • Reduced memory usage when many selection manipulation operations are in the history/undo stack (the undo data is now saved to disk)
  • The built-in updater now supports upgrading to paint.net 4.0 (once it’s available)

There have been rumors floating around that Paint.NET is “dead.” This is not true!

–jeroen

via: Paint.NET Blog | The best free image and photo editor. By Rick Brewster..

Posted in .NET, .NET 3.5, .NET 4.0, Algorithms, Development, Floating point handling, Power User, Software Development, Windows, Windows 7, Windows 8, Windows Server 2000, Windows Server 2003, Windows Server 2003 R2, Windows Server 2008, Windows Server 2008 R2, Windows Vista, Windows XP | Tagged: , , | Leave a Comment »

.NET/C#: UnitPrefixes class that facilitates distinguishing decimal and binary file/drive/memory size (mega versus mibi, etc)

Posted by jpluimers on 2013/08/14

Everyone knows there is a size difference between a gigabyte of memory, and a gigabyte of disk space.

The former is 102410241024, the latter is 100010001000.

To facilitate this, I’ve created a C# class UnitPrefixes containing quite a few constants and readonly values.

The class is below, but a few interesting facts first:

  • Most values are const, but a few are readonly static variables because they cannot calculated at compile time (the C# compiler by design does very limited calculations at compile time; it is complex enough as it already is).
    As Jon Skeet explains, there are some other differences between const and readonly static, which is why I favour const.
  • Though all consts are positive, I could have used UInt32 and UInt64, but the .NET framework favours signed Int32 and Int64 types for parameters, so to avoid casting, I used the signed ones.
  • There is no Int128 or UInt128, but there is System.Numerics.BigInteger which I use for values too large for 64-bit integers.
    Note that BigInteger is relatively new, so this code will only work in C# 4 or higher, and requires .NET 4 or higher.
    This is also the place where I use the public readonly static fields, as I need to call the BigInteger constructor to initialize it.
  • I used the Decimal type, as the mantissa holds up to 28 digits of accuracy.

I used the Wikipedia pages Binary Prefix and Metric Prefix (I could also have used File Size) for the unit names and abbreviations.

Note that BitsPerByte is a const I needed too, and I will probably add constants for 512 and 4096, as you see those often in computing as well.

The below sample code is also available as a changeset on BeSharp.CodePlex.com. Read the rest of this entry »

Posted in .NET, .NET 4.0, .NET 4.5, C#, C# 4.0, C# 5.0, Conference Topics, Conferences, Development, Event, Jon Skeet, Software Development | Tagged: , | Leave a Comment »

.NET/C#: some starting posts on the `yield` keyword.

Posted by jpluimers on 2013/08/08

Peter Leslie Morris asked if Delphi already incorporates the `yield` keyword that C# had introduced in C# 2.

Delphi doesn’t, but for the people interested what it does in C#:

Basically `yield` is syntactic sugar to make it a lot easier to write methods that return enumerators of some sort.

It delays (hence the yield keyword) execution until the enumerator as actually being used.

It is one of the hardest C# things to master (it is the most complicated transformation in the compiler, followed by anonymous methods – well maybe with the exception of async/await), but it can be very useful.

VB.NET doesn’t have it either (thanks André!) has it too, but and also has iterator blocks.

Some start posts on yield:

–jeroen

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, Delphi, Development, Software Development | 10 Comments »

CLR week on the Old New Thing has started: first one about Static Constructors

Posted by jpluimers on 2013/08/06

Finally a new CLR Week on the Old New Thing.

It starts with via: Why does BitConverter.LittleEndian return false on my x86 machine? which is all about static constructors.

So you should read these as well:

(Note that virtually anything from Eric Lippert and Jon Skeet it worth reading anyway).

--jeroen

via: Why does BitConverter.LittleEndian return false on my x86 machine? – The Old New Thing – Site Home – MSDN Blogs.

Posted in .NET, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, Development, Jon Skeet, Software Development | Leave a Comment »

It works! Install Visual Studio 2010 AFTER Visual Studio 2012 – Stack Overflow

Posted by jpluimers on 2013/08/06

Never thought this would work so smoothly: Install Visual Studio 2010 AFTER Visual Studio 2012 – Stack Overflow.

–jeroen

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, Development, Software Development, VB.NET, VB.NET 10.0, VB.NET 11.0, VB.NET 8.0, VB.NET 9.0, Visual Studio 11, Visual Studio 2010, Visual Studio and tools | 7 Comments »

.NET/C# – InvalidCastException for two Objects of the same type (via: G+/Stack Overflow)

Posted by jpluimers on 2013/08/03

If you ever get something similar to

InvalidCastException: [A]Person cannot be cast to [B]Person.

then you are (or more precise: your process is) probably loading the same assembly twice, but from a different context.

.NET allows that, and for reason (side by side loading, appdomains, etc).

Delphi doesn’t (thanks Warren Postma for noticing). But a mistake you see quite often is that Delphi developers try to load the same Delphi type from both an EXE and a DLL wondering why they don’t match. If you want to spread your types in Delphi, then use BPLs (run-time packages) for that. BPLs are similar to .NET assemblies, but cannot be loaded in memory twice.

–jeroen

via c# – InvalidCastException for two Objects of the same type – Stack Overflow.

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, Development, Software Development, VB.NET, VB.NET 10.0, VB.NET 11.0, VB.NET 8.0, VB.NET 9.0, Visual Studio 11, Visual Studio 2005, Visual Studio 2008, Visual Studio 2010, Visual Studio and tools | Leave a Comment »

Reminder to Self: Messagepack / BSON / ProtocolBuffers

Posted by jpluimers on 2013/07/25

Need to find/create a Delphi compatible version of Messagepack or BSON.

–jeroen

via Serializing and deserializing (packing/unpacking) to a file and/or memorystream with MessagePack in C# ».

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, Delphi, Delphi XE2, Delphi XE3, Development, Software Development | 4 Comments »