Archive for the ‘.NET’ Category
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 »
Posted by jpluimers on 2013/08/28
Every once in a while you are in situation where you are not allowed to use SQL Server Profiler, nor to see any query plans, but you still want see the SQL going from your .NET apps to the database server.
With that SQL, you can feed it through your favourite database tool, and see where the culprit is.
There are various ways of getting rudimentary or a bit more advanced SQL out of this. Flapper posted a solution that is specific for SQL Server (and requries both ObjectExtensions.cs and StringExtensions.cs from the DotNetX library), but posted more ready to use SQL.
I opted – and wanted to hank Justin Harris – for this piece of code on StackOverflow, which works on any IDbCommand (so you can use it for any ADO.NET data provider, like SQL Server, OLE DB, Oracle, etc):
While you will not be able to plug is into something like Enterprise Manager to run it works for logging.
public static string ToReadableString(this IDbCommand command)
{
StringBuilder builder = new StringBuilder();
if (command.CommandType == CommandType.StoredProcedure)
builder.AppendLine("Stored procedure: " + command.CommandText);
else
builder.AppendLine("Sql command: " + command.CommandText);
if (command.Parameters.Count > 0)
builder.AppendLine("With the following parameters.");
foreach (IDataParameter param in command.Parameters)
{
builder.AppendFormat(
" Paramater {0}: {1}",
param.ParameterName,
(param.Value == null ?
"NULL" : param.Value.ToString())).AppendLine();
}
return builder.ToString();
}
answered Apr 12 ’10 at 20:26; juharr
You saved my day! Not being allowed to use the profiler, this is a great way to get the actual SQL, then run it from SSMS or the Enterprise Manager. – Jeroen Wiert Pluimers
I pasted it in a DataExtensions class like this: Read the rest of this entry »
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 »
Posted by jpluimers on 2013/08/22
Bumped into this error a while ago in Visual Studio 2010:
| Kind |
Error |
| Number |
80 |
| Description |
Unable to open module file ‘C:\Users\username\AppData\Local\Temp\.NETFramework,Version=v4.0.AssemblyAttributes.vb’: The system cannot find the file specified. |
| File |
C:\Users\username\AppData\Local\Temp\.NETFramework,Version=v4.0.AssemblyAttributes.vb |
| Line |
1 |
| Column |
1 |
| Project |
VbPowerPack |
(I replaced the column separators by line separators to make it more readable)
The code was using the VBPowerPack download I wrote about before, but that appeared to be irrelevant.
This is how I solved it:
- Build -> Clean Solution
- Build -> Rebuild Solution
- File -> Close Solution
- View -> Start Page
- Open most recent solution from the Start Page
I’m not the only one that has this problem every now and then.
Thanks to these posts that helped me out with the above solution:
–jeroen
via: “The system cannot find the file specified.” “\Temp\.NETFramework,Version=v4.0.AssemblyAttributes.vb”
Posted in .NET, .NET 4.0, Development, Software Development, VB.NET, VB.NET 10.0, Visual Studio 2010, Visual Studio and tools | 4 Comments »
Posted by jpluimers on 2013/08/17

Programmers scale: time versus project completeness
I totally agree that Paint.NET is the best free image and photo editor on Windows.
Writing quality software takes time, not only when writing it in spare time like Rick Brewster does. Getting things “right” is a tedious process and often will set you back: just watch the graph on the right.
So I’m not surprised that it took a very long time after the first Paint.NET 4.0 idea in 2008 to get “close” to a release.
And indeed, it looks like Rick has become much closer which will please many people waiting for Paint .NET 4.
I’m really glad with the announcement that Paint.NET v3.5.11 BETA is now available – Paint.NET Discussion & Questions – Paint.NET Forum.
Edit: while writing this, the final Paint.NET v3.5.11 came out.
It paves the way for Paint .NET 4.0 update in the future, and fixes/improves quite a few things.
A few quotes from it:
This is probably not the update you were expecting I need to push out an update to v3.5 in preparation for the eventual release of v4.0 […] releasing a “beta” today […] I’ll be pushing out the Final/RTM in a few days.
The primary goal of this update is preparing for the v4.0 release: v3.5.10 will not be able to offer the v4.0 update, but v3.5.11 will. […]
Here are the changes for this release:
- Fixed: The Gaussian Blur effect was incorrectly calculating alpha values for non-opaque pixels. (http://forums.getpaint.net/index.php?/topic/18483-gaussian-blur-mistreats-alpha/)
- Improved performance of the Sharpen effect by about 25%
- Improved performance of the Median effect by about 30%
- Improved performance of the Fragment effect by about 40%
- Improved performance of the Unfocus effect by about 100%
- Reduced memory usage when many selection manipulation operations are in the history/undo stack (the undo data is now saved to disk)
- The built-in updater now supports upgrading to paint.net 4.0 (once it’s available)
There have been rumors floating around that Paint.NET is “dead.” This is not true!
–jeroen
via: Paint.NET Blog | The best free image and photo editor. By Rick Brewster..
Posted in .NET, .NET 3.5, .NET 4.0, Algorithms, Development, Floating point handling, Power User, Software Development, Windows, Windows 7, Windows 8, Windows Server 2000, Windows Server 2003, Windows Server 2003 R2, Windows Server 2008, Windows Server 2008 R2, Windows Vista, Windows XP | Tagged: computer, software, technology | Leave a Comment »
Posted by jpluimers on 2013/08/14
Everyone knows there is a size difference between a gigabyte of memory, and a gigabyte of disk space.
The former is 102410241024, the latter is 100010001000.
To facilitate this, I’ve created a C# class UnitPrefixes containing quite a few constants and readonly values.
The class is below, but a few interesting facts first:
- Most values are const, but a few are readonly static variables because they cannot calculated at compile time (the C# compiler by design does very limited calculations at compile time; it is complex enough as it already is).
As Jon Skeet explains, there are some other differences between const and readonly static, which is why I favour const.
- Though all consts are positive, I could have used UInt32 and UInt64, but the .NET framework favours signed Int32 and Int64 types for parameters, so to avoid casting, I used the signed ones.
- There is no Int128 or UInt128, but there is System.Numerics.BigInteger which I use for values too large for 64-bit integers.
Note that BigInteger is relatively new, so this code will only work in C# 4 or higher, and requires .NET 4 or higher.
This is also the place where I use the public readonly static fields, as I need to call the BigInteger constructor to initialize it.
- I used the Decimal type, as the mantissa holds up to 28 digits of accuracy.
I used the Wikipedia pages Binary Prefix and Metric Prefix (I could also have used File Size) for the unit names and abbreviations.
Note that BitsPerByte is a const I needed too, and I will probably add constants for 512 and 4096, as you see those often in computing as well.
The below sample code is also available as a changeset on BeSharp.CodePlex.com. Read the rest of this entry »
Posted in .NET, .NET 4.0, .NET 4.5, C#, C# 4.0, C# 5.0, Conference Topics, Conferences, Development, Event, Jon Skeet, Software Development | Tagged: endregion, region | Leave a Comment »
Posted by jpluimers on 2013/08/08
Peter Leslie Morris asked if Delphi already incorporates the `yield` keyword that C# had introduced in C# 2.
Delphi doesn’t, but for the people interested what it does in C#:
Basically `yield` is syntactic sugar to make it a lot easier to write methods that return enumerators of some sort.
It delays (hence the yield keyword) execution until the enumerator as actually being used.
It is one of the hardest C# things to master (it is the most complicated transformation in the compiler, followed by anonymous methods – well maybe with the exception of async/await), but it can be very useful.
VB.NET doesn’t have it either (thanks André!) has it too, but and also has iterator blocks.
Some start posts on yield:
–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, Development, Software Development | 10 Comments »
Posted by jpluimers on 2013/08/06
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 »