0

I'm using WPF in an Azure Worker Role to composite several images into a single image and save to disk. Everything runs fine in the emulator, but when I deploy to Azure the areas where I expect to see scaled/resized images are completely black.

I packaged the code into a console app and, using Remote Desktop, I copied it up to the same instance that hosts the worker role. That app runs perfectly fine. This tells me that everything I need to be able to run my code is present on a vanilla azure instance.

What is different about running in the context of a worker role that could be interfering with WPF image processing?

UPDATE This is specifically only affecting the 3D transformations. In pseudocode, I'm doing something like this:

  • Create the mesh, apply the texture and add them to a ModelVisual3D
  • Create a Viewport3DVisual, set up an orthographic camera and add the ModelVisual3D
  • Render the viewport to a RenderTargetBitmap
  • Use DrawingContext.DrawImage() to draw the RenderTargetBitmap onto the "scene canvas"

When there's no 3D needed, the image is scaled and added with DrawingContext.DrawImage() as well. That's working fine. So the issue is somehow related to creating or using the RenderTargetBitmap from a 3D scene.

UPDATE It turns out that WPF will not render the 3D content when it's not interacting with the desktop. The emulator runs under my personal user context, whereas in Azure it's running as the System account. The problem can be replicated locally by creating a Windows Service that logs on as Local System and following the same steps. Getting around that is probably going to be a big challenge; we may have to go with a VM instead.

roufamatic
  • 18,187
  • 7
  • 57
  • 86

2 Answers2

0

Is your worker role running under Full Trust?

Ani
  • 10,826
  • 3
  • 27
  • 46
0

Even though it works fine in the emulator, could you try changing the ApartmentState for your WPF code to STA (read about WPF & STA here: https://stackoverflow.com/a/1293433/384546)?

public class WorkerRole : RoleEntryPoint
{
    public override void Run()
    {
        Thread thread = new Thread(new ThreadStart(MyWPFCode));
        thread.SetApartmentState(ApartmentState.STA);
        thread.Start();

        while (true)
        {
            Thread.Sleep(10000);
        }
    }

    private void MyWPFCode()
    {
        // WPF code goes here.
    }
}
Community
  • 1
  • 1
Sandrino Di Mattia
  • 24,739
  • 2
  • 60
  • 65
  • Unfortunately, I tried this as well. I'm running this in a `Parallel.ForEach` loop, using the `StaTaskScheduler` from here: http://blogs.msdn.com/b/pfxteam/archive/2010/04/07/9990421.aspx – roufamatic Jul 31 '12 at 21:58
  • ... But that said, my `BitmapSource` objects (that I use to texture my meshes) are loaded from the main worker role thread. I've used `.Freeze()` on them, but maybe that's not enough? I'll see if making my whole app run in an STA thread changes anything. – roufamatic Jul 31 '12 at 22:00
  • Nope, no luck. Just... blackness. – roufamatic Jul 31 '12 at 23:37