Archive for the ‘.NET 4.0’ Category
Posted by jpluimers on 2013/10/10
Still a C# 4.0 / .NET 4 feature that I need to investigate more deeply: ExpandoObject, partially because I had very bad memories of Variant support in Delphi.
So here are a few links.
First of all: since VB.NET already does late binding with the Object keyword, you cannot use ExpandoObject with Strict On in VB.NET 10.0 and up:
Now the C# links:
–jeroen
Posted in .NET, .NET 4.0, .NET 4.5, C#, C# 4.0, C# 5.0, Delphi, Delphi 2005, Delphi 2006, Delphi 2007, Delphi 2009, Delphi 2010, Delphi 3, Delphi 4, Delphi 5, Delphi 6, Delphi 7, Delphi XE, Delphi XE2, Delphi XE3, Development, Software Development | 5 Comments »
Posted by jpluimers on 2013/10/08
When debugging from Visual Studio, the actual process is often the .vshost.exe one.
Visual Studio 2005 and up use to the .vshost.exe to expedite the debugging sequence startup, and enables some debugger and design-time features. This is also the reason why your bin directory is locked as soon as you open a project in Visual Studio.
You can disable this feature, but then starting the debugging sequence gets a lot slower, and you loose some security and design-time expression evaluation.
Often (for instance when your process needs to start itself multiple times) you want to have the name without the .vshost part.
There are also circumstances, where the encompassing process is not a .NET one but a native process (for instance when running under IIS, or when running an Office Add-In).
So I wrote an AssemblyHelper class that retrieves some key properties of the currently running process, be it a .NET assembly or a native process.
Part of the code was inspired by the original Delphi .NET (not Prism) run-time library.
A few notes: 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 »
Posted by jpluimers on 2013/09/25
Roel van Lisdonk probably has one blog reason that is part of my reasons: posting quick notes or snippets of code/text in order to be able to find them back.
I especially like this C# snippet because he uses both an includeMask and excludeMask to filter a DirectoryInfo.GetFiles result.
Clever (:
–jeroen
via: GetFiles, sorted by Creation DateTime, filtered by include file mask and exclude file mask, including subfolders in C#.
Posted in .NET, .NET 4.0, .NET 4.5, C#, C# 4.0, C# 5.0, Development, Software Development | Leave a Comment »
Posted by jpluimers on 2013/09/24
When you call a DbDataAdapter.Update, and it throws an exception, the exception does not include the underlying Command and its parameters.
Since the DbDataAdapter can have three commands for applying changes (DeleteCommand, InsertCommand and UpdateCommand), asking those is a bit inconvenient.
The other way is to attach an event handler to the DAL specific RowUpdated event (for instance SqlDataAdapter.RowUpdated).
This is event is called from the virtual OnRowUpdatedMethod, and has a value parameter of type RowUpdatedEventArgs which contains the Command, and Errors that occurred. Errors is just the Exception that can help indicate what went wrong.
–jeroen
via: DbDataAdapter.Update Method System.Data.Common.
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/09/18
Need to research this further, as I’ve seen some Interop DLLs that – when automatically merged from within Visual Studio – will not function correctly.
Keywords: ILMerge, msbuild, mkbundle.
–jeroen
Posted in .NET, .NET 4.0, .NET 4.5, C#, C# 4.0, C# 5.0, Development, Software Development | Leave a Comment »
Posted by jpluimers on 2013/09/17
Igor Ostrovsky wrote a few very nice MSDN magazine articles. Not all of them have ended up in the list at MSDN magazine, so here is a more complete list:
Though the articles show the majority of sample code in C#, the actual topics are of great interest to any developer writing .NET code or interfacing to it.
Some keywords in his articles: 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, .NET CF, C, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, C++, Delphi, Development, F#, LINQ, PLINQ, 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 | Leave a Comment »
Posted by jpluimers on 2013/09/10
Just came across this nice answer by harpo containing a small class that can Escape/Unescape double-quotes in strings.
–jeroen
via: Good CSV Writer for C#? – Stack Overflow.
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, CSV, Development, Software Development | Leave a Comment »
Posted by jpluimers on 2013/09/04
Lots of people are confused about the different time out options you can set in ADO.NET.
Thanks NinethSense for explaining this well for the SqlClient DAL. Other DALs work in a similar way.
- SqlCommand.CommandTimeout = timeout limit for your SQL query. Means, how much time a (eg: SELECT, UPDATE) query can take for its execution. If it exceeds SqlCommand.CommandTimeout, then it stops execution. A command timeout error will occur.
- SqlConnection.ConnectionTimeout = timeout limit for your connection. Means, how much time your connection object can try to connect. If it exceeds the specified time, it stops connecting. A connection timeout error will occur.
–jeroen
via: .net – What is the difference between SqlCommand.CommandTimeout and SqlConnection.ConnectionTimeout? – Stack Overflow.
Posted in .NET, .NET 1.x, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, Development, Software Development | 1 Comment »
Posted by jpluimers on 2013/09/03
A while ago, I inherited a .NET project that used the EnterpriseLibrary, the original developers (it got developed around 2003) were gone, and every exception would end up in this:
SecurityException: The source was not found, but some or all event logs could not be searched. To create the source, you need permission to read all event logs to make sure that the new source name is unique. Inaccessible logs: Security.
Searching for the combination “EnterpriseLibrary” “The source was not found, but some or all event logs could not be searched. To create the source, you need permission to read all event logs to make sure that the new source name is unique. Inaccessible logs: Security.” revealed only 1 result:
patterns & practices – Enterprise Library – View Discussion: Logging Error of FormattedEventLogTraceListener in Win7.
Even though I didn’t want anything to be logged in the EventLog, I wanted text logs, and looking at the .config files in the main project, the Enterprise Library logging setup was correct (right sinks, etc).
Somehow, the EnterpriseLibrary still insisted on writing to the eventlog, and this particular exception was the only one tricking to the unhandled exception layer…
For logging in the Eventlog, that particular event log must exist. In order to create an eventlog, you need to have administrator access. And here is the crux: apparantly, the original developers were (while working on Windows NT 4) all Administrators. So they never noticed this problem (and maybe never even looked for that log). After having the Visual Studio debugger break on all CLR exceptions, not only the unhandled ones, I could see this one shown below fired deep inside the EnterpriseLibrary. Which means that the original developers:
- did add the EnterpriseLibrary V2 (yes, this project still had V2 and part of the config files were V1.1!) configuration files to the main project:
- Had forgotten to mark these files as “Copy to Output Directory” to have the value “Copy if Newer” or “Copy Always”
Marking the files as such solved the below exception, and now on my todo list is to make the old V1.1 stuff go away, and migrate to the most current Enterprise Library. 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, Development, EnterpriseLibrary, Software Development | Leave a Comment »
Posted by jpluimers on 2013/08/29
When you have a layered exception handling (for instance to translate general exceptions into domain or business exceptions, and want to control which exceptions trickle up to where), then from a debugger perspective, most exceptions actually handled.
However debugging those layers, it often makes sens to be able to break where all these exceptions are actually fired.
The screenshots (click on each to enlarge) are for Visual Studio 2010, but it works in any Visual Studio version and (since it is a debugger feature, not a language one) for all .NET languages I tried so far.
Note that as of Visual Studio 2010, if you disable these, it still breaks when exceptions are thrown from code called through reflection. This seems intentional and has 3 workarounds, but it might have been reverted in Visual Studio 2012.
This is a setting stored on the Solution level (.suo file) in Visual studio which by default is turned off. Luckily, it is very easy to turn this feature on, for instance for CLR (.NET Common Language Runtime) exceptions:
- In the “Debug” menu, choose “Exceptions” (or Press Ctrl+D, E),
- Wait a few moments for the dialog to appear
- Put a checkmark in the “Thrown” column for the “Comon Language Runtime Exceptions” row.
- Click the “OK” button. 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, 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 | 1 Comment »