Using PresentationCore in Azure requires full trust
less than 1 minute read
Sometimes the answer is staring you in the face... I was trying to load an image from an URL in code. Imagine the code for that being something like thisvar blobURL = "http://www.somewhere.com/image.jpg";
var multiTileImage = new BitmapImage();
multiTileImage.BeginInit();
multiTileImage.UriSource = new Uri(blobURL);
multiTileImage.CacheOption = BitmapCacheOption.None;
multiTileImage.EndInit();
This fails with an security expection, you get something like "Request for the permission of type 'System.Security.Permissions.MediaPermission failed in System.Windows.Media.Imaging.BitmapImage.EndInit"
Dennis van der Stelt suggested that this may have to do something with full trust. And indeed it does. In your service definition file by default is defined<WebRole name="WebRole" enableNativeCodeExecution="false">
I noticed that, I just failed to see the connection between "enableNativeCodeExecution" and "full trust". In fact, I still fail to see that connection ;-) but you just need to set the value for enableNativeCodeExecution in the appropriate tag to "true" and then PresentationCore classes - with apparently are not thrustworthy - can be used from Web- or Worker roles.