1

我是使用 Microsoft Visual C# 2010 进行 C# 编程的新手,我XamlParseExcepion在尝试将其VncSharpWpf.dll用作参考时需要帮助。发生以下错误。

图书馆链接和示例代码来自:http ://d.hatena.ne.jp/horus531/20110515/1305443108

当我尝试将相同的代码添加到作者提供的示例代码中时(即在项目中导入表面库,相同的代码可以工作)。

我不知道是什么导致库每次尝试加载时都会在新制作的表面项目上崩溃。

有人可以指导我使用什么软件/方法来识别和解决此类问题吗?

错误是:

System.Windows.Markup.XamlParseException was unhandled
  Message='The invocation of the constructor on type 'TestVncSharpWpf.SurfaceWindow1' that matches the specified binding constraints threw an exception.' Line number '5' and line position '5'.
  Source=PresentationFramework
  LineNumber=5
  LinePosition=5
  StackTrace:
       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.LoadBamlStreamWithSyncInfo(Stream stream, ParserContext pc)
       at System.Windows.Application.LoadComponent(Uri resourceLocator, Boolean bSkipJournaledProperties)
       at System.Windows.Application.DoStartup()
       at System.Windows.Application.<.ctor>b__1(Object unused)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.DispatcherOperation.InvokeImpl()
       at System.Threading.ExecutionContext.runTryCode(Object userData)
       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Windows.Threading.DispatcherOperation.Invoke()
       at System.Windows.Threading.Dispatcher.ProcessQueue()
       at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       at System.Windows.Application.RunInternal(Window window)
       at System.Windows.Application.Run()
       at TestVncSharpWpf.App.Main() in C:\surface\TestVncSharpWpf\obj\Debug\App.g.cs:line 0
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.BadImageFormatException
       Message=Could not load file or assembly 'VncSharpWpf, Version=0.0.0.1, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.
       Source=TestVncSharpWpf
       FileName=VncSharpWpf, Version=0.0.0.1, Culture=neutral, PublicKeyToken=null
       FusionLog==== Pre-bind state information ===
LOG: User = test-PC\test
LOG: DisplayName = VncSharpWpf, Version=0.0.0.1, Culture=neutral, PublicKeyToken=null
 (Fully-specified)
LOG: Appbase = file:///C:/surface/TestVNCSharpWPF/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : TestVncSharpWpf, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/surface/TestVNCSharpWPF/bin/Debug/VncSharpWpf.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.

       StackTrace:
            at TestVncSharpWpf.SurfaceWindow1..ctor()
       InnerException: 
4

1 回答 1

0

在错误消息中间它说System.BadImageFormatException 这篇文章表明问题可能是由于 32 位/64 位问题。
此外,有关故障排除的文档

  • 如果您的应用程序使用 32 位组件,请确保它始终作为 32 位应用程序运行
  • 确保您没有使用使用不同版本的 .NET Framework 创建的组件。
  • 确保文件映像是有效的托管程序集或模块。
于 2013-09-25T08:50:53.633 回答