Getting BCE0004 in monodevelop but not on editor

Hello,

I starting getting a BCE0004 only on monodevelop O_o, in Unity the code compiles fine. The code was working fine before I set mono as the external editor.

This is the code:

public static function action_0(_callback)
{
	var callback = _callback as Action; //=> ERROR BCE004
	callback();
}

public static function action(_callback, _parameters)
{
	var callback = _callback as Action.<Object>; //=> NO ERROR
	callback(_parameters);
}

public static function callback_0(_callback)
{
	var callback : Func.<Object> = _callback as Func.<Object>;//=> ERROR BCE004
	return callback();
}

public static function callback(_callback, _parameters)
{
	var callback : Func.<Object,Object> = _callback as Func.<Object,Object>;//=> ERROR BCE004
	return callback(_parameters);
}

Does anybody know why this is happening?

In case you run into this issue the solution is to set the target framework to .net 4.0 on all code projects, (the .csproj files and the .unityproj files). This thread shows a script that does it for .csproj files:

http://forum.unity3d.com/threads/monodevelop-problems-with-default-parameters.67867/

But in case you don’t feel like reading it, here’s a modified version of the script that does the trick for both .csproj and .unityproj files:

using UnityEngine;
using UnityEditor;
using System.IO;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Collections;
using System;

class RXSolutionFixer : AssetPostprocessor 
{
    private static void OnGeneratedCSProjectFiles() //secret method called by unity after it generates the solution
    {
        string currentDir = Directory.GetCurrentDirectory();
        string[] csprojFiles = Directory.GetFiles(currentDir, "*.csproj");

        foreach(var filePath in csprojFiles)
        {
            FixProject(filePath);
        }

        string[] unityprojFiles = Directory.GetFiles(currentDir, "*.unityproj");

        foreach(var filePath in unityprojFiles)
        {
            FixProject(filePath);
        }
    }

    static bool FixProject(string filePath)
    {
        string content = File.ReadAllText(filePath);

        string searchString = "<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>";
        string replaceString = "<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>";

        if(content.IndexOf(searchString) != -1)
        {
            content = Regex.Replace(content,searchString,replaceString);
            File.WriteAllText(filePath,content);
            return true;
        }
        else 
        {
            return false;
        }
    }
}

Just paste this script anywhere in yous scripts folder and you are good to go. The reason why this works is explained in the thread above =D