Archive for the ‘.NET’ Category
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
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, the System.Data.dll assembly contributes to namespaces like System.Data (e.g. the class System.Data.DataTable) and Microsoft.SqlServer.Server (e.g. the class Microsoft.SqlServer.Server.SqlContext).
- Multiple assemblies can contribute to a single namespace.
For instance both the System.Data.dll assembly and the System.Xml.dll assembly contribute to the System.Xml namespace.
Which means that if you use the System.Xml.XmlDataDocument class from your project, you need to reference the System.Data.dll assembly.
And if you use the System.Xml.XmlDocument class, you need to reference the System.Xml.dll from 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:
–jeroen
via: C# assemblies, whats in an assembly? – Stack Overflow.
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 += b
is equivalent to
a = a + b
You might think that this also holds:
a += b + c
is 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
Don’t increase your Windows Timer Resolution. And keep an eye on programs that do:
Raising the Windows timer frequency is bad. It wastes power and makes your computer slower. Routinely doing this in all sorts of programs that end up sitting idle for hours really needs to stop.
You can use ClockRes to monitor the time resolution and what programs changed it.
–jeroen
via: Windows Timer Resolution: Megawatts Wasted | Random ASCII.
Posted in .NET, Development, Opinions, Pingback, Power User, Software Development, WPF | Tagged: computer, software, technology, timer resolution | 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 »