Never thought this would work so smoothly: Install Visual Studio 2010 AFTER Visual Studio 2012 – Stack Overflow.
–jeroen
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 »
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 »
Posted by jpluimers on 2013/07/25
Need to find/create a Delphi compatible version of Messagepack or BSON.
–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, Delphi XE2, Delphi XE3, Development, Software Development | 4 Comments »
Posted by jpluimers on 2013/07/23
Ever since I started .NET programming after .NET Beta 1 Arrived in 2001, I found that many people struggle with the relation between assemblies and namespaces.
So I was glad that I posted this answer about 2.5 years ago on StackOverflow. Below is the slightly edited form:
People are easily confused by the namespace/assembly thing, as it decouples the concept of where your code is physically located (the assembly) and how you reference it:
- logically reference is by using the namespace
- physical reference is by referencing the assembly
I usually explain the relation using the word contribute:
- An assembly can contribute to multiple namespaces.
For instance, theSystem.Data.dllassembly contributes to namespaces likeSystem.Data(e.g. the classSystem.Data.DataTable) andMicrosoft.SqlServer.Server(e.g. the classMicrosoft.SqlServer.Server.SqlContext).- Multiple assemblies can contribute to a single namespace.
For instance both theSystem.Data.dllassembly and theSystem.Xml.dllassembly contribute to theSystem.Xmlnamespace.
Which means that if you use theSystem.Xml.XmlDataDocumentclass from your project, you need to reference theSystem.Data.dllassembly.
And if you use theSystem.Xml.XmlDocumentclass, you need to reference theSystem.Xml.dllfrom your project.(the above examples are .NET 4.0, but likely hold for previous .NET versions as well).
Danny Thorpe explained the concept of namespace and internal really well, so I won’t go into detail about those.
Ever since I started .NET courses 10 years ago, I draw a table explaining assemblies and namespaces like this:
| Assembly | Namespaces it contributes to | ||
|---|---|---|---|
| ↓ | System.Data | Microsoft.SQLServer.Server | System.Xml |
| ↑ Example classes | |||
| System.Data.dll | DataTable | SqlContext | XmlDataDocument |
| System.Xml.dll | — | — | XmlDocument |
–jeroen
Posted in .NET, .NET 1.x, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, .NET CF, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Development, Software Development | Leave a Comment »
Posted by jpluimers on 2013/07/18
A while ago, I wrote about .NET/C# duh moment of the day: “A char can be implicitly converted to ushort, int, uint, long, ulong, float, double, or decimal (not the other way around; implicit != implicit)”.
There is another duh moment having to do with the various C# operators like += which is being described as being
a += bis equivalent to
a = a + b
You might think that this also holds:
a += b + cis equivalent to
a = (a + b) + c
But Eric Lippert has explained this is not the case: it is equivalent to:
a = a + (b + c)
In his explanation, he also shows the confusion can get you very surprising results if you mix string, chars and ints in the expression: depending on the statement and ordering, you either concatenate characters, or add ints to characters.
He also recommends you should not do concatenation: either use String.Format, or StringBuilder. I totally agree with that.
Recommended reading!
–jeroen
Posted in .NET, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Development, Software Development | Leave a Comment »
Posted by jpluimers on 2013/07/11
Josh Stodola wrote a nice answer on the Determine .NET Framework version for dll – Stack Overflow question for using ILDASM to show the required .NET Framework/CLR version for an assembly.
From that, I wrote this tiny batch file:
ildasm.exe %1 /metadata[=MDHEADER] /text /noil | find "Metadata section:"
It gives output like this:
ildasm.exe C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.XML.dll /metadata[=MDHEADER] /text /noil | find "Metadata section:"
// Metadata section: 0x424a5342, version: 1.1, extra: 0, version len: 12, version: v4.0.30319
The cool thing is that older ILDASM versions work on assemblies requiring newer .NET Frameworks/CLRs.
So it is relatively future proof.
–jeroen
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 »
Posted by jpluimers on 2013/07/04
I’m not the only a big fan of almost anything that Eric Lippert writes on tech subjects on both his new personal Fabulous Adventures In Coding blog as well as his old microsoft Fabulous Adventures In Coding blog (a little more than half a year ago, he moved from Microsoft to Coverity.
On his old blog, he had a great series of posts on the “Fragile Base Class problem” (which he calls the Brittle Base Class problem) from a C# perspective.
Be sure to also read the comment threads, as they provide some very valuable information too (for instance, about Extension Methods that can make your code more fragile).
Recommended reading!
–jeroen
via: Browse by Tags – Fabulous Adventures In Coding – Site Home – MSDN Blogs.
Posted in .NET, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Development, Software Development | Leave a Comment »
Posted by jpluimers on 2013/06/27
log4net configuration can be a tad intimidating at first.
When you do not want to log all levels, and the levels you want to log are not noncontinuous, then you can combine the LevelMatchFilter with a DenyAllFilter.
The filter classes in the log4net do not provide much help on this, but the filters section in the log4net manual is better.
This StackOverflow question has a very nice answer explaining it: Discarding several log levels within a range with log4net.
–jeroen
via: Discarding several log levels within a range with log4net – 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 | Leave a Comment »
Posted by jpluimers on 2013/06/18
A lot of people have written .NET equivalents of netstat code. Basically there are two starting points:
I adapted the first, made the output very much like the built-in Windows netstat, and added some LINQ code to demonstrate grouping and ordering.
Now you get grouped output like this:
Distinct Remote Address:Port pairs by Remote Address: 107.20.249.140 443 107.20.249.78 443 127.0.0.1 6421, 19872 192.168.1.81 17500, 61678 199.47.218.159 443 199.47.219.148 80 199.47.219.160 443 23.21.220.140 443 23.23.127.94 443
The code below is part of the DotNetStat example.
It demonstrates a few important LINQ aspects beyond the LINQ Query Expressions (C# Programming Guide) intro and 101 LINQ Samples 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, Development, Jon Skeet, Software Development | Leave a Comment »
Posted by jpluimers on 2013/06/13
A while ago I needed unique temporary directories. This appears not to be standard functionality in the .NET System.IO.Path or System.IO.Directory class.
Josh Kelley asked a question about it before, and I adapted the example by Scott-Dorman based on GetTempPath and GetRandomFileName and comments by Chris into a more robust CreateTemporaryRandomDirectory one that works in .NET 2.0 and higher:
using System.IO;
namespace BeSharp.IO
{
public class DirectoryHelper
{
public static string GetTemporaryDirectory()
{
do
{
try
{
string tempPath = Path.GetTempPath();
string randomFileName = Path.GetRandomFileName();
string tempDirectory = Path.Combine(tempPath, randomFileName);
Directory.CreateDirectory(tempDirectory);
return tempDirectory;
}
catch (IOException /* ex */)
{
// continue
}
} while (true);
}
}
}
You can call it like this: 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# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Development, Software Development | 2 Comments »