Archive for the ‘.NET 4.5’ Category
Posted by jpluimers on 2013/01/09
Until I realized that comparing two IEnumerables needed some extra thought, I wondered why Assert.AreEqual would not support them.
jrista pointed me in the right direction answering a question about c# – How does Assert.AreEqual determine equality between two generic IEnumerables?
The correct answer is “it doesn’t”, but that is really dense.
IEnumerables are just that: being generic or normal, they allow you to enumerate things. They can get you an enumerator (generic or not) that has a notion of Current (generic or normal) and such, but no knowledge of the underlying data.
Comparing them needs you to think about the enumeration and the underlying data at the same time. You can get two kinds of comparisons: Read the rest of this entry »
Posted in .NET, .NET 3.5, .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 2012/12/26
There is a lot of information in Assembly that is either internal or private. Luckily you van get an AssemblyName instance through Assembly.GetName() or Assembly.GetName(Boolean) which has quite a few public members that get initialized while calling the internal AssemblyName.Init method.
This is the member mapping of AssemblyName members to Assembly members:
–jeroen
via: Assembly.GetName Method (Boolean) (System.Reflection).
Posted in .NET, .NET 3.5, .NET 4.5, ASP.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 2012/12/18
Ever since .NET 1 there has been no built-in way to create a file including all its parent directories.
Hence small FileHelper class far below.
The fundament of the class is this CreateUnderlyingDirectory method, that uses System.IO.Path.GetDirectoryName to obtain the parent directory of a path, and then System.IO.Directory.CreateDirectory to create it (and any parent directories) if needed.
public static void CreateUnderlyingDirectory(string path)
{
string directoryPath = Path.GetDirectoryName(path);
Directory.CreateDirectory(directoryPath); // NOP if it exists, will create all parent directories if not
}
A few helper methods get you a StreamWriter either empty/appended, or always empty Read the rest of this entry »
Posted in .NET, .NET 3.5, .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 2012/12/04
WinForms does not automatically enable Ctrl-A as “Select All” action.
The below code snippet works when you bind it to the KeyDown event of a TextBox (actually the event is on Control).
The e.SuppressKeyPress = true suppresses the bell sound in a multiline TextBox, as e.Handled = true won’t.
private void textBox_KeyDown_HandleCtrlAToSelectAllText(object sender, KeyEventArgs e)
{
TextBox textBox = sender as TextBox;
if (null != textBox)
{
if (e.Control && e.KeyCode == Keys.A)
{
textBox.SelectAll();
e.SuppressKeyPress = true;
}
}
}
–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 2012/11/21
Often when comparing characters with a list of characters, that list does not consist of consts.
It if were, you could make a switch statement:
switch (item)
{
case '/':
case '\\':
case ';':
addSeparator(separatorsUsed, item);
break;
}
But reality is that you cannot do things like this:
switch (item)
{
case Path.AltDirectorySeparatorChar: // Error: A constant value is expected
case Path.DirectorySeparatorChar:
case Path.PathSeparator:
addSeparator(separatorsUsed, item);
break;
}
However, you can perform a small trick and use LINQ to write some pretty elegant code based on Contains.
char[] pathSeparators = { Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar, Path.PathSeparator };
// LINQ: http://stackoverflow.com/questions/1818611/how-to-check-if-a-char-in-a-char-array/1818635#1818635
if (pathSeparators.Contains(item))
addSeparator(separatorsUsed, item);
The LINQ logic has the logic backwards (you can think of it like “item in pathSeparators”, but it is far easier to read than this:
if ((item == Path.AltDirectorySeparatorChar) || (item == Path.DirectorySeparatorChar) || (item == Path.PathSeparator))
addSeparator(separatoseparatorsUsedrsInUse, item);
Full source of a demo application: Read the rest of this entry »
Posted in .NET, .NET 3.5, .NET 4.5, C#, C# 3.0, C# 4.0, C# 5.0, Development, LINQ, Software Development, Visual Studio 11, Visual Studio 2008, Visual Studio 2010, Visual Studio and tools | 2 Comments »
Posted by jpluimers on 2012/11/15
A while ago, one of the users at a client got an error in a .NET 1.1 app of which the sources were not readily available:
“application has generated an exception that could not be handled”
I think it is a e0434f4d exception.
This particular site has very strict rules about what you can and cannot do as a developer. Which means that on a production system, you basically cannot do anything.
A few links that should help me finding the solution, and escalate far enough upstream to get someone with local admin rights to assist me:
If WinDbg is allows to be ran, these should help me:
–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 2012/10/25
If you get any of the two errors below while compiling your .NET app, then one of these things happened:
- You moved .NET 4 or higher code that makes use of dynamic into an assembly that does not reference the Microsoft.CSharp.dll and System.Core.dll assemblies.
- You tried changing the .NET version of a project back to .NET 3.5 or lower.
Note that it is not so much declaring a variable as dynamic, but using that variable.
Predefined type ‘Microsoft.CSharp.RuntimeBinder.Binder’ is not defined or imported
One or more types required to compile a dynamic expression cannot be found. Are you missing references to Microsoft.CSharp.dll and System.Core.dll?
–jeroen
via C# 4.0 and .Net 3.5 – Stack Overflow.
Posted in .NET, .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 2012/09/18
Having a done a lot of Async stuff in the .NET 2, 3.x and 4 era with multimedia applications (oh, the days of SynchronizationContext), this project seems very interesting:
Adds the new C#5 async features for .NET 4 projects
Download this project as a .zip file
Download this project as a tar.gz file
What does it do?
AsyncBridge lets you use the VS 11 C#5 compiler to write code that uses the async and await keywords, but to target .NET 4.0. It was published by Daniel Grunwald (from SharpDevelop) here.
As an extra, I’ve thrown in the new C#5 caller info attributes, which lets you automatically add the method name, line number or file path to your code.
Authors and Contributors
Daniel Grunwald (@dgrunwald) – Original code.
Omer Mor (@OmerMor) – Turned it into a full blown github repo with the complimentary nuget.
Alex Davies (@alexdavies74) – Wrote the blog post that inspired this, and is actively improving the code.
–jeroen
via: AsyncBridge.
Posted in .NET, .NET 4.5, C#, C# 4.0, C# 5.0, Development, Software Development | Leave a Comment »
Posted by jpluimers on 2012/09/06
So I won’t forget: .NET Framework Libraries.
It contains the download links, setup instructions (for debugging, troubleshooting and source/symbols downloading) and licensing information.
–jeroen
Posted in .NET, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, ASP.NET, Development, Software Development | Leave a Comment »
Posted by jpluimers on 2012/08/28
Dang; I thought this had long left the posting queue, but somehow it ended in the drafts (:
Since then, many more event videos made it to Channel 9, including Build 2011, and TechDays 2012.
Anyway, here it is:
Microsoft’s PDC 2010 was held at the end of October 2010 in Redmond, WA, USA.
For the people that could not attend, it is very nice to view the sessions using the PDC10 player (it seems still people didn’t learn and start stripping the century parts from years again!).
Even if you are not using Visual Studio, .NET Azure or other Microsoft Technologies, there are a lot of interesting sessions showing the directions that Microsoft is taking.
Comparing that to what you do today is always a good thing to do: it helps you reflect, an important part of your personal development.
A few things I found interesting (in no particular order):
- Asynchrony support in C# 5 and VB.NET 11 based on the Task Parallel Library
- The choice to favour HTML 5 over SilverLight, even though Internet Explorer 9 and Microsoft’s HTML 5 authoring/development tools are far from ready
- Azure reporting: is reporting the next big thing on clouds?
- Offline versus online in the cloud world
- NuPack – does it bring package management to the same level as Ruby or *nix?
- XNA for XBox, Windows and Windows Phone
Enjoy!
–jeroen
Posted in .NET, .NET 4.5, C#, C# 4.0, C# 5.0, Channel9, Cloud Development, Database Development, Delphi, Development, HTML, HTML5, Mobile Development, SilverLight, SocialMedia, Software Development, Visual Studio 11, Visual Studio 2010, Visual Studio and tools, Web Development, Windows Azure, Windows Phone Development, XNA | 2 Comments »