01 July 2009

Using PresentationCore in Azure requires full trust

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 this
var blobURL = "http://www.somewhere.com/image.jpg";
var multiTileImage = new BitmapImage(); 
multiTileImage.UriSource = new Uri(blobURL);
multiTileImage.CacheOption = BitmapCacheOption.None;
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.

No comments: