9

I am running a console application on OSX that has the following...

public static void main(string[] args)
{
    string mongoEndpoint = Environment.GetEnvironmentVariable("MONGO_ENDPOINT");

    if(string.IsNullOrEmpty(mongoEndpoint))
    {
        _log.Fatal("Invalid Mongo Endpoint");
        throw new Exception("Invalid Mongo Endpoint");
    }
}

I have added a MONGO_ENDPOINT environment variable to my ~/.bash_profile and when I run echo $MONGO_ENDPOINT it outputs the correct value.

However, when I run my console application from Xamarin Studio in OSX, it returns null.

I tried running the following to see if it was all environment variables, and it returned the correct value.

Console.Out.WriteLine(Environment.GetEnvironmentVariable("HOME"));

and it outputted /usr/myname perfectly fine.

Any reason why it would not be able to find this environment variable?

Brandon Minnick
  • 13,342
  • 15
  • 65
  • 123
TheJediCowboy
  • 8,924
  • 28
  • 136
  • 208

1 Answers1

6

OS-X GUI apps will not inherit your private/custom env vars that are defined via a shell (bash, zsh, etc...) if they are launched from Finder/Spotlight. You have two choices:

1) Start Xamarin Studio from the cmd line so your current users' environment will be used:

/Applications/Xamarin\ Studio.app/Contents/MacOS/XamarinStudio &

2) If you want user environment vars available to GUI apps launched from Finder/Spotlight you need to modify your /etc/launchd.conf, see this SO answer:

https://stackoverflow.com/a/3756686/4984832

Runtime Configuration Guidelines

Community
  • 1
  • 1
SushiHangover
  • 73,120
  • 10
  • 106
  • 165