2012-03-29 15 views
0

私はWCFサービスでWPF .png画像を生成しています。すべてはしばらくの間、うまく動作しますが、最終的に、私はこのエラーを取得する:WPFを使用してWCFサービスで画像を生成

System.Windows.Markup.XamlParseException: Initialization of 'System.Windows.Controls.TextBlock' threw an exception. ---> 
System.ComponentModel.Win32Exception: The system cannot find the file specified 
    at MS.Win32.UnsafeNativeMethods.RegisterClassEx(WNDCLASSEX_D wc_d) 
    at MS.Win32.HwndWrapper..ctor(Int32 classStyle, Int32 style, Int32 exStyle, Int32 x, Int32 y, Int32 width, Int32 height, String name, IntPtr parent, HwndWrapperHook[] hooks) 
    at System.Windows.SystemResources.EnsureResourceChangeListener() 
    at System.Windows.SystemResources.FindResourceInternal(Object key, Boolean allowDeferredResourceReference, Boolean 
mustReturnDeferredResourceReference) 
    at System.Windows.StyleHelper.GetThemeStyle(FrameworkElement fe, FrameworkContentElement fce) 
    at System.Windows.FrameworkElement.UpdateThemeStyleProperty() 
    at System.Windows.FrameworkElement.OnInitialized(EventArgs e) 
    at System.Windows.FrameworkElement.TryFireInitialized() 
    at System.Windows.FrameworkElement.EndInit() 
    at MS.Internal.Xaml.Runtime.ClrObjectRuntime.InitializationGuard(XamlType 
xamlType, Object obj, Boolean begin) 
    --- End of inner exception stack trace --- 
    at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri) 
    at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri) 
    at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader 
xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri) 
    at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream) 
    at System.Windows.Application.LoadComponent(Object component, Uri 
resourceLocator) 

私は私のホストのWebサーバー上で、ローカルにこのエラーを作成することができたことはありません。しかし、私は働く方法を見つけるためには至っていない

ASP.NET Throws Win32Exception when creating BitmapImage, cannot find file specified http://www.thejoyofcode.com/Generating_images_using_WPF_on_the_Server.aspx

:私はいくつかの修正と回避策を試してみました。誰かがこのエラーをスローしないコードを投稿しても、少なくとも何らかの形でそれを回避することができます。これは私のサービスの行いです。

// Only one copy of the dispatcher (I have tried creating a new one each time too). 
private BackgroundStaDispatcher dispatcher = new BackgroundStaDispatcher(); 
public Stream GetImage() 
{ 
    WebOperationContext.Current.OutgoingResponse.ContentType = "image/png"; 
    Stream stream = null; 
    this.dispatcher.Invoke(
     () => 
     { 
      UserControl userControl = new UserControl() 
      { 
       DataContext = "Hello World" 
      }; 
      // Use PngBitmapEncoder to convert the control to a bitmap. 
      stream = userControl.ToPng(173, 173); 
     }); 
    return stream; 
} 
+1

私は推測していますが、WebサーバーからUserControlを使用することと関連があると思います。私はあなたがWebアプリケーションからUserControlをインスタンス化することはできないと考えているので、エラーが発生しています。ローカルテストの設定にはおそらくUserControlsを作成する権限がありますが、Webはそうではありません。 –

答えて

0

この問題を抱えている人は誰でも。私は毎回新しいUserControlを作成し、DataContextを設定してPNGに変換していました。代わりに、ちょうど最初にUserControlを作成し、それを保持して再利用してください。

関連する問題