Thursday, October 10, 2013

How to install Monodevelop 4 with F# support in Fedora

After spending quite some time to build mono & monodevelop from sources and enable F# support, I was able to do so more easily with the following steps:

1.Install Mono and Monodevelop from:

2. Setup an alternate mono environment by creating a bash script named something like ~/mono-dev-env. 
Its contents should be similar to the following:

#!/bin/bash
MONO_PREFIX=/opt/mono
GNOME_PREFIX=/opt/gnome
export DYLD_FALLBACK_LIBRARY_PATH=$MONO_PREFIX/lib:$DYLD_LIBRARY_FALLBACK_PATH
export LD_LIBRARY_PATH=$MONO_PREFIX/lib:$LD_LIBRARY_PATH
export C_INCLUDE_PATH=$MONO_PREFIX/include:$GNOME_PREFIX/include
export ACLOCAL_PATH=$MONO_PREFIX/share/aclocal
export PKG_CONFIG_PATH=$MONO_PREFIX/lib/pkgconfig:$GNOME_PREFIX/lib/pkgconfig
export PATH=$MONO_PREFIX/bin:$PATH
PS1="[mono] \w @ "

Along with setting appropriate environment variables to only use sources from /opt/mono and /opt/gnome, it also sets the Bash prompt to something other than the default, so it is easy to detect when Bash is in this alternate environment.
Finally, to enter this environment at any time, run the following from a Bash prompt:
source ~/mono-dev-env

3. Install F# from sources:
su
yum install autoconf libtool pkg-config make git
git clone https://github.com/fsharp/fsharp
cd fsharp
./autogen.sh --prefix=/opt/mono/
make
make install

4. Install F# Monodevelop addin:
- open Monodevelop
- go to Tools -> Addin Manager -> Gallery -> Language Bindings
- install F# language binding

5. Test that all works: 

Thursday, March 15, 2012

Dumping ground for some useful WinDbg commands

Dumping ground for some useful WinDbg commands and links:
1. Setup symbols path
srv*C:\symbols\web*http://msdl.microsoft.com/download/symbols;C:\symbols\web;C:\symbols\private
2. Load SOS
.loadby sos mscorwks(or "clr" when on .NET 4 tools)
.load sosex
.reload

3. Usefull commands
!threadpool
We can then use the !Threadpool-command to find out exactly what the CPU-usage was at the time the dump was taken. We'll also get some useful information like the number of work requests in the queue, completion port threads and timers.
!runaway
This is a nice command that will list all running threads and their CPU-usage. It's your best friend when troubleshooting a high CPU hang issue.
!threads
To get more information about the running threads we can run the !Threads-command. This will list all managed threads in the application, what application domain the thread is currently executing under, etc.
Switch to thread: ~[number of thread]s ex: ~50s
!clrstack -p
List the stack for the current thread
!pe
Print exception
Display all managed threads call stacks:
~*e !CLRStack (~ = symbol for thread, * = any, e = execute an action. Mean: for each thread, execute !CLRStack command)

###Memory leaks###
!eeheap -gc
!dumpheap -stat

!dumpobject (!do)
!dumpstackobjects (!dso)
!dumparray (!da)

!dumpheap -stat -type TextBox
!dumpheap -mt "address"
!gcroot "address" --see what is keeping alive this object

###Sosex###
!dlk - detect deadlock
!mk
To cancel a long execution in debugger (BUSY word on left bottom), press CTRL + Pause



Link to sosex : http://www.stevestechspot.com/
List of available commands: http://msdn.microsoft.com/en-us/library/bb190764(VS.80).aspx
Other links:
http://blogs.msdn.com/b/johan/archive/2007/01/11/how-to-install-windbg-and-get-your-first-memory-dump.aspx
http://blogs.msdn.com/b/tess/archive/tags/debugging/
http://blogs.msdn.com/b/tess/archive/2008/02/04/net-debugging-demos-information-and-setup-instructions.aspx

Friday, June 4, 2010

How to Use WinMerge as the Diff tool for Mercurial

Here is how you can setup TortoiseHg to use WinMerge for visual diffs and 3-way merges (instead of using KDiff):
  1. Open Mercurial.ini config file. On my WIN7 system, this file exists at C:\Users\MyUser\Mercurial.ini. If you are on an XP system, it's probably in C:\Documents and Settings\<your user name>\Mercurial.ini.
  2. Add the following lines:
    [extdiff]
    cmd.winmerge = C:\Program Files (x86)\WinMerge\WinMergeU.exe
    opts.winmerge = /e /x /ub /wl

    [merge-tools]
    winmergeu.executable = C:\Program Files (x86)\WinMerge\WinMergeU.exe
    winmergeu.priority= 1
    winmergeu.fixeol=True
    winmergeu.checkchanged=True
    winmergeu.args= /e /ub /dl other /dr local $other $local $output
    winmergeu.gui=False
    winmergeu.binary=True

    [tortoisehg]
    vdiff = winmerge
  3. Now run TortoiseHg's Global Settings tool. On the TortoiseHg tab, select winmerge for the Visual Diff Command, and winmergeu for the Three-way Merge Tool options, apply, close.
Sources:
http://superuser.com/questions/23576/how-to-use-winmerge-as-the-diff-tool-for-mercurial
http://stackoverflow.com/questions/2073543/use-winmerge-as-tortoisehg-merge-tool

Tuesday, April 27, 2010

Add binary serialization to a WCF webservice using UsernameOverTransport security

In order to enable this we have to add a new binding to our service and specify which endpoint to use. Add the following binding to the bindings section in the web.config on the service and client side:

<customBinding>

        <binding name="binaryHttpBinding">

          <security authenticationMode="UserNameOverTransport" requireSecurityContextCancellation="true" >

            <secureConversationBootstrap authenticationMode="UserNameForSslNegotiated" />

          </security>         

          <binaryMessageEncoding maxReadPoolSize="2147483647" maxSessionSize="2147483647" maxWritePoolSize="2147483647">

            <readerQuotas maxDepth="32" maxStringContentLength="5242880"

            maxArrayLength="200000" maxBytesPerRead="4096" maxNameTableCharCount="16384" />

          </binaryMessageEncoding>         

          <httpsTransport maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"></httpsTransport>         

        </binding>       

      </customBinding>

Specify an endpoint for it like this, and you are ready to go:

<endpoint address="" binding="customBinding" bindingConfiguration="binaryHttpBinding" contract="ServiceLibrary.MyService" />   

Hope this helps, I searched a while for the solution and it wasn't on the web.

Starting to love this WCF thingy :)

Saturday, March 20, 2010

How to properly close WCF connections

    Seems that reading InfoQ is really a good thing, even though the content related to .NET is pretty weak, it has really good content on Architecture and Languages.While doing the weekly swoop I stumbled across this article which triggered the alarm/sleepy memory in my head. The not so funny thing is that just last week I implemented the Dispose pattern for some WCF connections to a web service,  because I’m a programmer and programmers are lazy, and lazy means less code to do more, which kind of forces you to use the Dispose pattern and the “using" statement to automatically close your connections.
    If you don’t have the time to read the article and the references, the summary is that using the Dispose pattern is a bad practice for WCF connections, because well, someone at MSFT screwed up the design and ICommunicationObject.Close() throws a bunch of exceptions, which goes against the specifications for IDisposable which should NEVER throw an exception on Dispose(). So let’s see what code I have before:

   17 public partial class IFooServiceClient : IDisposable
   18 {
   19     public void Dispose()
   20     {
   21         Close();
   22     }
   23 }
    This is not good code, but not really bad either as long as Close doesn’t throw, which does, so slap in the face and let’s fix this. Someone proposed something like this which make things worse:
   25 public partial class IFooServiceClient : IDisposable
   26 {
   27     public void Dispose()
   28     {
   29         try
   30         {
   31             Close();
   32         }
   33         catch (Exception)
   34         {
   35             if (State == CommunicationState.Opened)
   36             {
   37                 Close();
   38             }
   39             else
   40             {
   41                 Abort();
   42             }
   43         }
   44     }
   45 }
    This is bad because you lose the exception context and this has the possibility to deadlock as well, checking the channel state is an anti pattern as well. This is the solution I came up with:
class IFooServiceClientHelper
{
    internal T CallServiceMethod<T>(ICommunicationObject service,    Func<T> serviceMethod)
    {
        T returnedInstance = default(T);
        try
        {
            returnedInstance = serviceMethod();
            service.Close();
        }
        catch (FaultException<IFooServiceFault> iof)
        {
            service.Abort();
            throw new IFooServiceException("Executing" + serviceMethod.Method.Name + " has failed.", iof);
        }
        catch (CommunicationException e)
        {
            service.Abort();
            throw new IFooServiceConnectionException("There was a communication problem. " + e.Message, e);
        }
        catch (TimeoutException e)
        {
            service.Abort();
            throw new IFooServiceConnectionException("The service operation timed out. " + e.Message, e);
        }
        catch (InvalidMessageContractException e)
        {
            service.Abort();
            throw new IFooServiceConnectionException(
                "The DataContract for the web service is not up-to-date. " + e.Message, e);
        }
        catch (Exception e)
        {
            service.Abort();
            throw new IFooServiceException("Executing" + serviceMethod.Method.Name + " has failed." + e.Message, e);
        }
        return returnedInstance;
    }
}
    This helper method has multiple overloads in order to call Func with parameters but the idea is the same. Calling this is pretty easy:
public Foo GetFoo()
{
    var service = new FooServiceClient();
    var serviceHelper = new FooServiceHelper();
    return serviceHelper.CallServiceMethod<Foo>(service, service.GetFoo);
}

This is better than we had before, but maybe I can improve this more. Any ideas? 
Develop with passion, 
Adrian

Wednesday, January 27, 2010

IPad

     Today Apple announced their next offering: IPad. From what it seems, this is going to be the real competitor to Kindle DX, and Amazon even has to do some catch-up in a field which until now they were leading.
     The IPad has some serious downsides,  maybe the best outcome is Amazon releasing a cheaper/better Kindle soon?
     IPad is interesting, but I still favor a netbook/PC + e-Reader, a lot more openness and possibilities.

Sunday, January 24, 2010

Building my own website

    I've started to read Professional ASP.NET MVC 1.0 , the first chapter is free. After working with Web Forms for a short period (a year and a half) the MVC framework seems like a breeze of fresh air. I don't really understand the whole debate on Web Forms vs. MVC, it's pretty clear which one is cleaner, more robust and easy to use. And no, the lack of controls is not a minus, the web is based on HTML and JavaScript served through HTTP, then why bury all those inside a bunch of web controls when we can use HTML directly?
   Giving the fact that at work I will continue working with Web Forms for the next year I think, I need to start some home project to learn Asp.Net MVC. I'm thinking for some time at creating my own website, so this seems to be a great opportunity to do something useful while learning. I know that there are a bunch of blogging engines for .NET, but I think I will do it from scratch anyway.
   I wonder how soon I will have something usable...