none
ASP.NET web project with WPF is not working in server machine(2008 RC2) but working in local machine RRS feed

  • Question

  • We have a simple ASP.NET Web project to create a png image dynamically using WPF libraries (Not using GDI+). This sample work fine in local machine. But, we are facing an issue in server machine as image is downloaded as blank. Please find the server machine configuration below.

    protected void btnCreateExcel_Click(object sender, EventArgs e)
        {
            Thread currenThread = new Thread(Sample);
            currenThread.SetApartmentState(ApartmentState.STA);
            currenThread.Start();
            currenThread.Join();
        }
    
        private void Sample()
        {
            Grid grid = new Grid();
            grid.Width = 300;
            grid.Height = 300;
    
    
            TextBlock block = new TextBlock();
            block.Text = "Test Image";
            block.Background = Brushes.Red;
            grid.Children.Add(block);
    
            Rectangle rectangle = new Rectangle();
            rectangle.Fill = Brushes.Green;
            rectangle.Width = 200;
            rectangle.Height = 100;
            grid.Children.Add(rectangle);
    
            grid.RenderTransform = new ScaleTransform(1, 1, 0.5, 0.5);
            grid.Measure(new Size(300, 300));
            grid.Arrange(new Rect(new Size(300, 300)));
            var rtb = new RenderTargetBitmap(
                (int)grid.Width,
                (int)grid.Height,
                96, //dpi x
                96, //dpi y
                PixelFormats.Pbgra32 // pixelformat
                );
            rtb.Render(grid);
            var enc = new PngBitmapEncoder();
            enc.Frames.Add(BitmapFrame.Create(rtb));
            using (var stm = File.Create(Server.MapPath("Sample.png")))
            {
                enc.Save(stm);
            }
            ClientScript.RegisterClientScriptBlock(this.GetType(), "open", "window.open('Sample.png','_blank');", true);
        }

    Server machine configuration:

    IIS Version: 7.5, 8.5.9600.16384

    Visual studio version: 2015,2017



    • Edited by dillibabu_n Monday, October 9, 2017 12:42 PM
    Monday, October 9, 2017 10:40 AM

All replies

  • Hi Team,

    Any updates on this? It is bottleneck for our project in client machine.

    Regards,

    Dilli babu.


    • Edited by dillibabu_n Tuesday, October 10, 2017 6:58 AM
    • Proposed as answer by Ankurkh Thursday, October 12, 2017 6:34 PM
    • Unproposed as answer by Ankurkh Thursday, October 12, 2017 6:34 PM
    Tuesday, October 10, 2017 5:36 AM
  • We were facing the same issue and that too, for the piece of code which has been working fine for a while.

    Searched around and found this

    https://support.microsoft.com/en-us/help/4043764/quality-rollup-for-net-framework-4-6-4-6-1-4-6-2-and-4-7-for-windows-7

    After this update, things are working again!!!

    Thursday, October 12, 2017 6:36 PM