Archive for the ‘.NET 3.0’ Category
Posted by jpluimers on 2015/11/26
As a reminder to self: Settings are nice (too bad they advertise them as Windows Forms Application Settings , as they are just as useful for other assemblies), but be aware…
When using Settings.Default, it will get the values to the state of the app.config (or defaults if there is no app.config) of the assembly that defined the settings, not the app.config of the starting process.
This is unless your settings are merged into the app.config of the starting process .
–jeroen
Posted in .NET , .NET 1.x , .NET 2.0 , .NET 3.0 , .NET 3.5 , .NET 4.0 , .NET 4.5 , Development , Software Development | Leave a Comment »
Posted by jpluimers on 2015/11/25
Code Analysis in Visual Studio objects against using very generic exception types:
CA2201 Do not raise reserved exception types
‘BusinessClass<T>.StopProcessing()’ creates an exception of type ‘ApplicationException’, an exception type that is not sufficiently specific and should never be raised by user code. If this exception instance might be thrown, use a different exception type.
Company.Departement.Functionality BusinessClass.cs 157
Indeed ApplicationException and SystemException are bad (both mapping to also very generic COM HRESULT values COR_E_APPLICATION / -2146232832 / 0x80131600 and COR_E_SYSTEM / -2146233087 / 0x80131501).
Using InvalidOperationException is much nicer in this case. It still maps to a COM exception (in this case COR_E_INVALIDOPERATION / -2146233079 / 0x80131509).
–jeroen
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 , C# 6 (Roslyn) , Development , Software Development | Leave a Comment »
Posted by jpluimers on 2015/11/24
A while ago, I came across a class having (among other members) two methods named like this:
Within one of the other members of the class, I had to (temporarily) Stop processing, then Start it again.
But I couldn’t, as neither Start, nor Stop would make a record of the state it left the instance in.
Always ensure you know the state of an instance.
So I added the state, and tests to ensure a Stop/Start change was indeed not breaking things.
–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 , C# 6 (Roslyn) , Delphi , Delphi 10 Seattle , Delphi 2007 , Delphi 2009 , Delphi 2010 , Delphi XE , Delphi XE2 , Delphi XE3 , Delphi XE4 , Delphi XE5 , Delphi XE6 , Delphi XE7 , Delphi XE8 , Development , Software Development | 1 Comment »
Posted by jpluimers on 2015/11/03
Lazy<T> is not constrained to static contexts.
Instance field initialisers cannot use instance references (but can use static references) as they run outside of the constructor.Though there are arguments for instance field initialisers too ., I think this is a good reason to initialise fields inside the constructor: there you do have access to instance references (but should not call virtual instance methods or properties ) which leads to another reason: consistency as field initialisers run in the opposite hierarchy order as constructors (incidentally causing this virtual method restriction).
Boy, that was a long sentence (:
–jeroen
via:
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 , C# 6 (Roslyn) , Development , Software Development | Leave a Comment »
Posted by jpluimers on 2015/10/06
Get the path to the most recent msbuild.exe from the registry :
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off
:: http://stackoverflow.com/questions/328017/path-to-msbuild
:: http://www.csharp411.com/where-to-find-msbuild-exe/
:: http://timrayburn.net/blog/visual-studio-2013-and-msbuild/
:: http://blogs.msdn.com/b/visualstudio/archive/2013/07/24/msbuild-is-now-part-of-visual-studio.aspx
setlocal
:vswhereModernTry
:: https://github.com/Microsoft/vswhere/wiki/Find-MSBuild
:: Normal output example of `vswhere -legacy -latest -property installationPath` has no trailing back-slash:
:: `C:\Program Files (x86)\Microsoft Visual Studio 14.0\`
for /f "usebackq tokens=*" %%i in (`vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath`) do (
set InstallDir=%%i
)
:: without ENABLEEXTENSIONS, %InstallDir% is only available outside the above loop.
for %%v in (15.0, 14.0) do (
if exist "%InstallDir%\MSBuild\%%v\Bin\MSBuild.exe" (
set msBuildExe="%InstallDir%\MSBuild\%%v\Bin\MSBuild.exe"
goto :finish
)
)
:manualTry
:: order of the versions is important: get the most recent one
for %%v in (14.0, 12.0, 4.0, 3.5, 2.0) do (
for /f "usebackq tokens=2* delims= " %%c in (`reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\%%v" /v MSBuildToolsPath`) do (
set msBuildExe="%%dMSBuild.exe"
goto :finish
)
)
:vswhereLegacyTry
:: -legacy is not compatible with -products or -requires
:: note there is no Visual Studio 13.0 (just like there is no Office 13.0) likely because USA superstition.
:: https://en.wikipedia.org/wiki/Microsoft_Visual_Studio#History
:: msbuild was introduced in Visual Studio 8.0: https://en.wikipedia.org/wiki/MSBuild#History
:: Legacy output example of `vswhere -legacy -latest -property installationPath` has trailing back-slash:
:: `C:\Program Files (x86)\Microsoft Visual Studio 14.0\`
for /f "usebackq tokens=*" %%i in (`vswhere -legacy -latest -property installationPath`) do (
set InstallDir=%%i
)
:: without ENABLEEXTENSIONS, %InstallDir% is only available outside the above loop.
for %%v in (14.0, 12.0, 11.0, 10.0, 9.0, 8.0) do (
if exist "%InstallDir%MSBuild\%%v\Bin\MSBuild.exe" (
set msBuildExe="%InstallDir%MSBuild\%%v\Bin\MSBuild.exe"
goto :finish
)
)
:: nothing found
:finish
endlocal & if not [%msBuildExe%]==[] if exist %msBuildExe% ( echo %msBuildExe% )
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for /f "usebackq tokens=*" %%c in (`"%~dp0get-msbuildExe-path.bat"`) do (
call %%c %*
)
With help from:
Note
This needs adoption for Visual Studio 2017 (15.0) and up; see the comments at the above gist :
–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 , C# 6 (Roslyn) , Delphi , Delphi 10 Seattle , Delphi 2007 , Delphi 2009 , Delphi 2010 , Delphi XE , Delphi XE2 , Delphi XE3 , Delphi XE4 , Delphi XE5 , Delphi XE6 , Delphi XE7 , Delphi XE8 , Development , Software Development | Leave a Comment »
Posted by jpluimers on 2015/09/28
I’ve seen this question coming up a few times, and bumped into this at a client recently: the UAC dialog coming up when debugging a 32-bit executable.
This is caused (more details below) by Installer Detection Technology introduced in Windows Vista (with UAC) and tightened in more modern Windows versions.
The solution is to either:
not include Installer, Patch, Update, Upgrade, Setup, … in your EXE name
provide a correct manifest to your EXE (getting this right can be hard)
don’t use x86 as platform target
For software you don’t have source code for, you can alter the manifest with a requestedExecutionLevel element : Fixing the way Vista Auto-detects Installers – Ben’s Writing .
A few links on Installer Detection Technology in Windows:
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# 1.0 , C# 2.0 , C# 3.0 , C# 4.0 , C# 5.0 , C# 6 (Roslyn) , Delphi , Delphi 10 Seattle , Delphi 2 , 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 , Delphi XE4 , Delphi XE5 , Delphi XE6 , Delphi XE7 , Delphi XE8 , Development , RemObjects C# , Software Development | 1 Comment »
Posted by jpluimers on 2015/09/01
I like simple solutions, thanks vcsjones for answering this :
Perhaps this:
var str = String . Join ( ", " , SupportedNotificationMethods . Select ( s => s . ToString ()));
You can read more about the String.Join method at MSDN . Older versions of String.Join don’t have an overload that takes an IEnumerable. In that case just call ToArray() after select.
–jeroen
via: c# – Convert List<Enum> to List – Stack Overflow .
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 , C# 6 (Roslyn) , Development , Software Development | Leave a Comment »
Posted by jpluimers on 2015/08/18
Had to investigate some Assembly Loading issues, so I wrote two batch files to enable and disable the .NET Fusion Log:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
reg add "HKLM\Software\Microsoft\Fusion" /v EnableLog /t REG_DWORD /d 0 /f
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
reg add " HKLM\Software\Microsoft\Fusion" /v EnableLog /t REG_DWORD /d 1 /f
They modify the HKLM\Software\Microsoft\Fusion key REG_DWORD value EnableLog.
A few notes:
It is very important to turn of the Fusion log settings as soon as you are finished investigating. Fusion logs potentially take a lot of resources.
When you have a .NET host like ISS , you have to restart that host (for instance by running iisreset )
There is also Fuslogvw.exe Assembly Binding Log Viewer , but I like logging over viewing as logs are persistent.
There are more values under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion you can configure; see the answer by Gary Kindel on StackOverflow :
DWORD ForceLog set value to 1
DWORD LogFailures set value to 1
DWORD LogResourceBinds set value to 1
String LogPath set value to folder for logs e.g. C:\FusionLog\ (ensure the final backslash is there and the folder exists).
–jeroen
via:
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 , C# 6 (Roslyn) , Development , Software Development | Leave a Comment »
Posted by jpluimers on 2015/08/11
I need to give this link from Jonathan Lange which was shared by David Millington some thought:
Embedded in Academia : How to Fuzz an ADT Implementation .
There they add fuzzers to help testing an ADT : in this case an Abstract Data Type in the form of a red-black tree .
And then see if it can be added to DUnit and NUnit or MSTest /VSTest in some way.
In the original post by Jonathan Lange , an important remark was made by Eric Castelijn :
… the downside being that having non deterministic tests means having test failures that are hard to repeat
…
When fuzzing multiple or composite values, the chances that you will hit interesting edge cases semi-reliably will drop dramatically, in my experience
–jeroen
via “This post has two points. First, you should write ADT fuzzers. It is often… .
VIDEO
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 , C# 6 (Roslyn) , Delphi , Delphi 2007 , Delphi 2009 , Delphi 2010 , Delphi XE , Delphi XE2 , Delphi XE3 , Delphi XE4 , Delphi XE5 , Delphi XE6 , Delphi XE7 , Delphi XE8 , Development , Software Development | 2 Comments »
Posted by jpluimers on 2015/08/05
Every C#/VB/.NET developer should read Difference Between Int32.Parse, Convert.ToInt32, and Int32.TryParse – CodeProject .
Then also read TryParse with default values .
It is all about handling values that are not Integers, Overflow values and Nulls. There are subtle differences, in the handling of the methods, and the exceptions they could throw: ArgumentNullException , FormatException and OverflowException .
Finally read all about the NumberStyles enumeration, IFormatProvider interface and CultureInfo (especially the difference between InvariantCulture , CurrentCulture , CurrentUICulture and InstalledUICulture ).
Because getting your conversions right matters.
–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 , C# 6 (Roslyn) , Development , Mono , Mono for Android , Prism , RemObjects C# , 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 »
lextm commented on Mar 9, 2017 •
vswhereis now recommended to locate MSBuild 15,https://github.com/Microsoft/vswhere
n9 commented on May 17, 2017
vswhere -products *to get standalone installation of BuildTools. (See Microsoft/vswhere#61.)