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 ‘C# 5.0’ Category

.NET/C#: you cannot do string? because Nullable is for value type, and string is a reference type

Posted by jpluimers on 2014/01/15

At clients, I see quite a few people being confused by this compiler error message:

Error 1 The type 'string' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'System.Nullable'

One of the reasons about the confusion is that a string variable behaves like a value type, but in fact is a reference type because their values can consume a huge amount of memory (thanks User codekaizen).

A few interesting questions on that on StackOverflow:

Anyway, back to the error message above.

Lots of people are confused by it, just see a few questions on StackOverflow: Read the rest of this entry »

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, Jon Skeet, Software Development | Leave a Comment »

When two types are not the same: Assembly Load Contexts Subtleties (via: All Your Base Are Belong To Us)

Posted by jpluimers on 2014/01/09

Reading c# – Type.IsSubclassOf does not behave as expected – Stack Overflow, I found this very interesting link via Assembly Load Contexts Subtleties at Sasha Goldshtein’s blog (I love the name of the blog: All Your Base Are Belong To Us).

He explains the reasons for the error message

System.InvalidCastException: Unable to cast object of type ‘Plugin.MyPlugin’ to type ‘Plugin.MyPlugin’.

Actually his blog entry is an abstract of a 200+ page thesis on  that is also recommended reading: Flexible Dynamic Linkin for .NET (by Anders Aaltonen, Alex Buckley and Susan Eisenbach).

–jeroen

via:

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

.NET/C# – opposite of Path.Combine: remove trailing DirectorySeparatorChar

Posted by jpluimers on 2014/01/01

For a project, I needed to strip the potential Path.DirectorySeparatorChar and Path.AltDirectorySeparatorChar.

Where Path.Combine will combine two paths and insert the DirectorySeparatorChar, I could not find the opposite, so I wrote this little piece of code:

using System.IO;

namespace BeSharp.IO
{
    public class PathHelper
    {
        public static string RemoveTrailingDirectorySeparators(string directory)
        {
            string result = directory.TrimEnd(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
            return result;
        }
    }
}

–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, Development, Software Development | Leave a Comment »

.NET/C#: System.Environment.GetLogicalDrives Method is identical to System.IO.Directory.GetLogicalDrives

Posted by jpluimers on 2013/12/26

My mental association with getting LogicalDrives was always the System.IO namespace, so I’ve always used Directory.GetLogicalDrives Method (System.IO) .

Recently I bumped into Environment.GetLogicalDrives Method (System), and discovered it has been available for the same time: since .NET 1.x.

I was not so much amazed that these methods return exactly the same data, but that they have identical code. Not just a single call to some common code: their code is the same, line by line. In .NET 4, they have the code below. Read the rest of this entry »

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, Development, Software Development | Leave a Comment »

.net – xcopy ASP.NET / WinForms deployment: find common location to access relative files to it (via: Stack Overflow)

Posted by jpluimers on 2013/12/25

StackOverflow user Joe (sorry, no last name) helped me big time by answering my question on Business logic shared by ASP.NET / WinForms: find the location of the assembly to access relative files to it.

Before showing the code at the bottom of this blog post, let me explain the question in more detail:

Basically I was in the midst of refactoring some ‘inherited’ business logic code that – before refactoring – for the ASP.NET side needs to be initialized with an absolute path, but on the WinForms / WPF side only with a relative path to a GetExecutingAssembly directory.

To ease xcopy deployment, I wanted all configuration settings to be relative. But I hadn’t found a common means for these platforms to obtain a directory usable as a root for accessing relative files.

That way I could put identical settings in both the Web.config and App.config, heck even generate them based on a common fragment, whithout having to hard-code absolute path names.

I knew about Assembly.GetExecutingAssembly, but in ASP.NET that location is not where the web site is (both IIS and the WebDevelopment server make use of temporary locations to store the assemblies).

ASP.NET does have Server.MapPath and HostingEnvironment.MapPath, but I didn’t want to make the business logic depend on ASP.NET.

Joe came up with this solution, which works dandy: Read the rest of this entry »

Posted in .NET, .NET 1.x, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, ASP.NET, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Development, F#, Prism, Software Development, VB.NET, VB.NET 10.0, VB.NET 11.0, VB.NET 7.0, VB.NET 7.1, VB.NET 8.0, VB.NET 9.0, Web Development | Leave a Comment »

DelphiSpec Library Announce « Роман.Янковский.me

Posted by jpluimers on 2013/12/22

Cool stuff: DelphiSpec library, inspired by Cucumber. It runs on top of DUnit.

via DelphiSpec Library Announce « Роман.Янковский.me.

A similar one in the .NET realm: SpecFlow – Pragmatic BDD for .NET.

–jeroen

Posted in .NET, .NET 3.5, .NET 4.0, .NET 4.5, C#, C# 3.0, C# 4.0, C# 5.0, Delphi, Delphi 2005, Delphi 2006, Delphi 2007, Delphi 2009, Delphi 2010, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Delphi XE5, Development, Software Development | Leave a Comment »

.NET/C#: On my research list is the Mono.Options arguments parser

Posted by jpluimers on 2013/12/17

The Mono.Options single .cs source file seems very well suited for arguments parsing of (especially) console application:

https://github.com/mono/mono/blob/master/mcs/class/Mono.Options/Mono.Options/Options.cs

so it is on my research list, like some other .NET/C# based command line parsing libraries (:

–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 | Leave a Comment »

Attach attach a debugger to a WebService (via: Stack Overflow)

Posted by jpluimers on 2013/12/10

Some things you have done for ages, are already phrased so nicely, the only thing you can do is quote.

Thanks Dave Coulter:

You can attach the Visual Studio debugger to a process by:

Debug > Attach to Process > Attach Read the rest of this entry »

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, 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 | Leave a Comment »

.NET/C#: Some links on validation/guarding/checking

Posted by jpluimers on 2013/12/05

From my link archive:

–jeroen

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 »

Two ways of adding a classic .asmx WebService in .net 4+ using Visual Studio 2010 SP1 and up (via: Stack Overflow)

Posted by jpluimers on 2013/11/27

As of Visual Studio 2010 SP1 (I think it was there in the original non-SP1 version of VS2010), Microsoft has hidden the addition of classic ASCX webservices as they favour WCF over ASPX (there are quite a few differences).

It is easy to workaround though as Stack Overflow users User Cyberherbalist and User Alejandro Martin have shown, with a little bit post-editing from me: Read the rest of this entry »

Posted in .NET, .NET 4.0, .NET 4.5, ASP.NET, C#, C# 4.0, C# 5.0, Development, SOAP/WebServices, Software Development, Visual Studio 11, Visual Studio 2010, Visual Studio and tools | Leave a Comment »