Category: .NET

  • Instrumentation in C# / .NET

    For many programmers a try/catch with stack trace it is enough Others want to see also functions arguments,like in will produce the result ERROR An exception occured in method InstrumentationPostSharp.Person.Drink with (beersNumber = 10,vodkaNumber = 2) For this you can install the package https://www.nuget.org/packages/LoggerAspect.Nlog that have full source code at https://github.com/vnvizitiu/AOP/tree/master/PostSharpTutorial and watch my video…

  • RavenDB embedabble

    I have made an application with RavenDB embeddable. The good part is that is embeddable and easy to work with – at least,at start. What I have learned: If you forgot to use using,then RavenDB will throw an exception complaining about multiple sessions. Code:   If you use multiple instance of the same EmbeddableDocumentStore,even on…

  • Export to Excel,Word,Pdf,Html,CSV

    I have made an application / package that exports data ( classes/datatable/csv/json) to Word/Excel/PDF. I have made several tries in the past,however now is the definitive source for .NET 4.x It is FULL code source,with tests and tutorials..   The code is at https://github.com/ignatandrei/Exporter  The NuGet package is at https://www.nuget.org/packages/ExporterWordExcelPDF The demo online is at…

  • Throw versus ThrowEx

        When you intercept exceptions( for logging ) you can or The difference is small – but the consequences are losing the original stack trace,if you I have done a small video about this : https://youtu.be/Deigld3Bqko I have not covered ExceptionDispatchInfo  that you can see an usage here: http://blogs.microsoft.co.il/sasha/2011/10/19/capture-transfer-and-rethrow-exceptions-with-exceptiondispatchinfo-net-45/

  • Useful Attributes in Visual Studio

      For me,I like     and   The code is the following: and the video is at https://youtu.be/ShBr1GgpZKs

  • Validation in .NET

    For validating a simple class,you can add [Required] ( see https://msdn.microsoft.com/en-us/library/ee256141(v=vs.100).aspx But how to validate same object depending on his state? For example,when it is new,the email is required. But after saving,the user mus also add FirstName( also think about workflows) There is a simple solution in .NET : IValidatableObject In this example,I validate differently…

  • IEnumerable

      Please read the code and answer question below: How many times the breakpoint at will be hit ? Why? And if your answer is not 3,please look at https://youtu.be/1fy_T9TCPpc

  • Asynchronous code and exceptions

    There are 2 kinds of coding when handling asynchronous code. The first one is  calling Result: < [code lang="csharp"] t.TwoTask().Result [/code] The second is async /await As such,we will have 2 intercepting code. For the first one we will catch AggregateException For the second one we will catch the FIRST task  exception  ( or,more generic,Exception…

  • Async / await transformation and pitfalls

    /// &lt;summary&gt; /// please read first http://blog.stephencleary.com/2012/02/async-and-await.html /// &lt;/summary&gt; Let’s say you want to transform this code to async / await public bool TwoTask() { var file= WriteToFile(); var console= ReadConsole(); return file &amp; console; } The first version is public async Task&lt;bool&gt; TwoTask() { var file=await WriteToFile(); var console = await ReadConsole(); return file…

  • Video Tutorials 5 minutes

    Videos: 5Min Logging 5min Send emails and SMTP4Dev 5Min Memory Profiler ( User Object and/or memory leaks) 5min SFHB 5min – .TT files in Visual Studio Playlist 5 Minutes .NET