Archive for the ‘C# 3.0’ Category
Posted by jpluimers on 2016/03/22
Even though as of 12c R1, Oracle supports a row limiting clause, NHibernate 4.2 with Oracle.DataAccess.dll 2.112.3.0 does not support that.
When you let it generate the SQL for a LINQ Take call to limit the number of results, you get an exception like this (full exception and stack trace are below):
System.NotSupportedException was unhandled by user code
HResult=-2146233067
Message=Specified method is not supported.
The place where you Take is important, as this does fail:
Read the rest of this entry »
Posted in .NET, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, .NET ORM, C#, C# 2.0, C# 3.0, C# 4.0, C# 5.0, C# 6 (Roslyn), Database Development, Development, NHibernate, OracleDB, Software Development | Leave a Comment »
Posted by jpluimers on 2016/03/17
When you have one app.config for your whole set of DTAP environments (develop/test/acceptance production), every once in a while you get this error:
ORA-12154: TNS:could not resolve the connect identifier specified
For this particular setup, it means the replacement of parameters in the app.config with actual values from the DTAP went wrong (or was missing). For that we’ve some steps in both the PreBuildEvent and PostBuildEvent of the .csproj file:
PreBuildEvent:
del "$(ProjectDir)$(TargetFileName).config"
copy "$(ProjectDir)app.config" "$(ProjectDir)$(TargetFileName).config"
PostBuildEvent:
powershell -noprofile -file Replace-Parameter.ps1 -Path "$(TargetDir)$(TargetFileName).config"
The PreBuildEvent looks like it is not needed, but sometimes Visual Studio forgets to perform the copy action.
–jeroen
Posted in .NET, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, .NET ORM, C#, C# 2.0, C# 3.0, C# 4.0, C# 5.0, C# 6 (Roslyn), Database Development, Development, NHibernate, OracleDB, Software Development | Leave a Comment »
Posted by jpluimers on 2016/03/16
It seems I always forget about the InternalsVisibleTo attribute which allows you to specify which external assembly can see your internal types and type members:
Internal classes need to be tested and there is an assembly attribute:
using System.Runtime.CompilerServices;
[assembly:InternalsVisibleTo("MyTests")]
Add this to the project info file, e.g. Properties\AssemblyInfo.cs.
Thanks Eric Schaefer for that answer.
–jeroen
via .net – C# “internal” access modifier when doing unit testing – 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, C# 6 (Roslyn), Development, Software Development | Leave a Comment »
Posted by jpluimers on 2016/02/16
This was very useful to get a WebClient with a WebProxy configured to use a proxy server that is based on NTLM authentication.
The note in the MSDN NTLM and Kerberos Authentication. documentation however was totally wrong.
String MyURI = "http://www.contoso.com/";
WebRequest WReq = WebRequest.Create MyURI;
WReq.Credentials = CredentialCache.DefaultCredentials;
Note NTLM authentication does not work through a proxy server.
This code works perfectly fine as the CredentialsCache.DefaultCredentials contains your NTLM or Kerberos credentials.
It even works when you have a local Fiddler http proxy as a facade in front of your NTLM proxy.
Read the rest of this entry »
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), Development, Fiddler, Software Development, Web Development | Leave a Comment »
Posted by jpluimers on 2016/01/27
Duh: same for VS2013
It is still available, you just need to add it back to the View menu. Tools + Customize, Commands tab, Menu bar = View. Select the menu item in Controls where you want to insert it, say the bottom one. Then Add Command, Category = View, Commands = Tab Order.
Source: winforms – Where is the Tab Order Assignment dialog in Visual Studio 2012? – Stack Overflow
–jeroen
Posted in .NET, .NET 4.0, .NET 4.5, C#, C# 3.0, C# 4.0, C# 5.0, Development, Software Development, Visual Studio 2012, Visual Studio 2013, Visual Studio 2014, Visual Studio 2015, Visual Studio and tools | Leave a Comment »
Posted by jpluimers on 2016/01/27
You’d think this is a simple question.
Be amazed by the many ways leading into to creating a temporary file with a specific extension.
This list doesn’t even cover all of them:
- Create a file name based on GetTempPath, a Guid and an extension.
- Use the TempFileCollection from the Compiler in System.CodeDom.
- Get a random file name, then change the extension. Loop until it is unique.
- Use a timestamp to generate unique file names.
All via: c# – How can I create a temp file with a specific extension with .net? – Stack Overflow.
Which one would you choose?
–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, RemObjects C#, Software Development | Leave a Comment »
Posted by jpluimers on 2016/01/18
Still a great book. I love the chapter Threading in C# – Free E-book which you also can get as a PDF download.
It’s a chapter from C# 56/5/… in a Nutshell by Joseph Albahari. Great book!
Don’t forget to read these as well: Jon Skeet: Multi-threading in .NET: Introduction and suggestions (printable) Multi-threading in .NET: Introduction and suggestions (browseable)
--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), Development, Jon Skeet, Software Development, Visual Studio 2008, Visual Studio 2010, Visual Studio 2012, Visual Studio 2013, Visual Studio 2014, Visual Studio 2015, Visual Studio and tools | Leave a Comment »
Posted by jpluimers on 2015/12/15
Quite a while ago I learned about the clip.exe tool.
clip.exe is a nifty tool that allows you to copy console text output to the clipboard. Though shipping with Windows Server 2003, it wasn’t part of Windows XP, but as of Windows Vista it shipped on desktop versions of Windows.
Digging a bit deeper, I found out it was already part of the Windows NT 4 Resource Kit.
So I wrote PasteText:
PasteText: the reverse of clip.exe; pastes Clipboard.GetText() or Clipboard.GetFileDropList() to the standard output.
The full source code is below and in my repository.
There are many examples on the internet about Clipboard.GetText, but there is very little about Clipboard.GetFileDropList. 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, The Old New Thing, Windows 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 »