将CodedUI dll导入WPF应用程序,然后引发空引用引用 [英] import CodedUI dlls into WPF application then throw null reference expcetion

查看:57
本文介绍了将CodedUI dll导入WPF应用程序,然后引发空引用引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi, I want to have a application that can control the tests, so I'm trying to not using codedUI project but create a WPF project then import the following assemblies instead:

然后我在MainWindow.Xaml中创建一个按钮,并将以下代码提供给它的click事件:

ApplicationUnderTest app = ApplicationUnderTest.Launch (Environment.GetFolderPath(Environment.SpecialFolder.Windows)+ @"\ system32 \ calc.exe" );

,则将发生以下错误,我尝试了不同的方法,但是由于来自

then the following error will occur, I try different ways but they all failed due to null reference exception from

Microsoft.VisualStudio.TestTools.UITesting,can you give some advice, thanks.

Microsoft.VisualStudio.TestTools.UITest.Extension.FailedToLaunchApplicationException未处理
  HResult = -268111863
  Message =启动此过程时发生以下错误:对象引用未设置为对象的实例文件:C:\ Windows \ system32 \ calc.exe.
  ; Source = Microsoft.VisualStudio.TestTools.UITesting
  BasicMessage =启动此过程时发生以下错误:对象引用未设置为对象的实例. \ Windows \ system32 \ calc.exe.
  StackTrace:
         在Microsoft.VisualStudio.TestTools中. UITesting.ApplicationUnderTest.Start(ProcessStartInfo startInfo)
    在Microsoft.VisualStudio.TestTools.UITesting.ApplicationUnderTest.. ctor(字符串fileName,字符串alterFileName,字符串参数)
       在Microsoft.VisualStudio.TestTools.UITesting.ApplicationUnderTest.<> c__DisplayClass1.< Launch> b__0()
        at Microsoft.VisualStudio.TestTools.UITesting.CodedUITestMethodInvoker.InvokeMethod [T](Func`1函数,UITestControl控件,布尔型firePlaybackErrorEvent,布尔型logAsAction)
        at Microsoft.VisualStudio.TestTools.UITesting.ApplicationUnderTest.Launch(字符串fileName,字符串alterFileName,字符串参数)
        at Microsoft.VisualStudio.TestTools.UITesting.ApplicationUnderTest.Launch(String fileName)
     在c:\ Users \ j-xiaozh \ Desktop \ CarPlateSHTest \ CarPlateSHTest \ MainWindow.xaml.cs:第36行
        at System.Windows.EventRoute.InvokeHandlersImpl(对象源,RoutedEventArgs参数,布尔值重新引发)
       位于System.Windows.UIElement.RaiseEventImpl(DependencyObject发送者,RoutedEventArgs参数)
       在System.Windows.Controls.Button.OnClick()
        at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
       在System.Windows.RoutedEventArgs.InvokeHandler(委托处理程序,对象目标)处
        at System.Windows.EventRoute.InvokeHandlersImpl(对象源,RoutedEventArgs参数,布尔值重新引发)
        at System.Windows.UIElement.ReRaiseEventAs(DependencyObject发送者,RoutedEventArgs参数,RoutedEvent newEvent)
       在System.Windows.RoutedEventArgs.InvokeHandler(委托处理程序,对象目标)处
        at System.Windows.EventRoute.InvokeHandlersImpl(对象源,RoutedEventArgs参数,布尔值重新引发)
       位于System.Windows.UIElement.RaiseEventImpl(DependencyObject发送者,RoutedEventArgs参数)
       在System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)中
       在System.Windows.Input.InputManager.ProcessStagingArea()
       在System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
        at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd,InputMode模式,Int32时间戳,RawMouseActions操作,Int32 x,Int32 y,Int32滚轮)
       在System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd,WindowMessage消息,IntPtr wParam,IntPtr lParam,布尔值和已处理)
        at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd,Int32 msg,IntPtr wParam,IntPtr lParam,布尔值和已处理)
     在MS.Win32.HwndWrapper.WndProc中(IntPtr hwnd,Int32 msg,IntPtr wParam,IntPtr lParam,布尔值和已处理)
       位于MS.Win32.HwndSubclass.DispatcherCallbackOperation(对象o)
        at System.Windows.Threading.ExceptionWrapper.InternalRealCall(委托回调,对象args,Int32 numArgs)
     在MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(对象源,委托方法,对象args,Int32 numArgs,委托catchHandler)
     在System.Windows.Threading.Dispatcher.LegacyInvokeImpl中(DispatcherPriority优先级,TimeSpan超时,Delegate方法,对象args,Int32 numArgs)
        at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd,Int32 msg,IntPtr wParam,IntPtr lParam)
        at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       在System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       在System.Windows.Application.RunInternal(窗口"窗口中​​)
       在System.Windows.Application.Run()
       在c:\ Users \ j-xiaozh \ Desktop \ CarPlateSHTest \ CarPlateSHTest \ obj \ Debug \ App.g.cs:line 0中的CarPlateSHTest.App.Main()
  ;      在System.AppDomain._nExecuteAssembly(RuntimeAssembly程序集,String []参数)
       在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       在System.Threading.ExecutionContext.RunInternal(ExecutionContext执行上下文,ContextCallback回调,对象状态,布尔值saveSyncCtx)
       位于System.Threading.ExecutionContext.Run(ExecutionContext执行上下文,ContextCallback回调,对象状态,布尔值saveSyncCtx)
       在System.Threading.ExecutionContext.Run(ExecutionContext执行上下文,ContextCallback回调,对象状态)中
       在System.Threading.ThreadHelper.ThreadStart()
  InnerException:System.NullReferenceException
        HResult = -2147467261
        Message =对象引用未设置为对象的实例.
        Source = Microsoft.VisualStudio.TestTools.UITest.Playback
        StackTrace:
           在Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.FindFromWindowHandle(IntPtr windowHandle)
           在Microsoft.VisualStudio.TestTools.UITesting.UITestControl..ctor(IntPtr windowHandle)中
           在Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FromWindowHandle(IntPtr windowHandle)中
           在Microsoft.VisualStudio.TestTools.UITesting.ApplicationUnderTest.SetCurrentProcessPrivate(过程值)
           在Microsoft.VisualStudio.TestTools.UITesting.ApplicationUnderTest.<> c__DisplayClassb.< set_Process> b__a()
           在Microsoft.VisualStudio.TestTools.UITesting.CodedUITestMethodInvoker.InvokeMethod [T](Func`1函数,UITestControl控件,布尔firePlaybackErrorEvent,布尔logAsAction)
           在Microsoft.VisualStudio.TestTools.UITesting.ApplicationUnderTest.set_Process(过程值)
           在Microsoft.VisualStudio.TestTools.UITesting.ApplicationUnderTest.Start(ProcessStartInfo startInfo)
        InnerException:

Microsoft.VisualStudio.TestTools.UITest.Extension.FailedToLaunchApplicationException was unhandled
  HResult=-268111863
  Message=The following error occurred when this process was started: Object reference not set to an instance of an object. File: C:\Windows\system32\calc.exe.
  Source=Microsoft.VisualStudio.TestTools.UITesting
  BasicMessage=The following error occurred when this process was started: Object reference not set to an instance of an object. File: C:\Windows\system32\calc.exe.
  StackTrace:
       at Microsoft.VisualStudio.TestTools.UITesting.ApplicationUnderTest.Start(ProcessStartInfo startInfo)
       at Microsoft.VisualStudio.TestTools.UITesting.ApplicationUnderTest..ctor(String fileName, String alternateFileName, String arguments)
       at Microsoft.VisualStudio.TestTools.UITesting.ApplicationUnderTest.<>c__DisplayClass1.<Launch>b__0()
       at Microsoft.VisualStudio.TestTools.UITesting.CodedUITestMethodInvoker.InvokeMethod[T](Func`1 function, UITestControl control, Boolean firePlaybackErrorEvent, Boolean logAsAction)
       at Microsoft.VisualStudio.TestTools.UITesting.ApplicationUnderTest.Launch(String fileName, String alternateFileName, String arguments)
       at Microsoft.VisualStudio.TestTools.UITesting.ApplicationUnderTest.Launch(String fileName)
       at CarPlateSHTest.MainWindow.Button_Click(Object sender, RoutedEventArgs e) in c:\Users\j-xiaozh\Desktop\CarPlateSHTest\CarPlateSHTest\MainWindow.xaml.cs:line 36
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.Controls.Button.OnClick()
       at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
       at System.Windows.Input.InputManager.ProcessStagingArea()
       at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
       at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
       at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at System.Windows.Interop.HwndSource.InputFilterMessage(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.LegacyInvokeImpl(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 CarPlateSHTest.App.Main() in c:\Users\j-xiaozh\Desktop\CarPlateSHTest\CarPlateSHTest\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.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.NullReferenceException
       HResult=-2147467261
       Message=Object reference not set to an instance of an object.
       Source=Microsoft.VisualStudio.TestTools.UITest.Playback
       StackTrace:
            at Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.FindFromWindowHandle(IntPtr windowHandle)
            at Microsoft.VisualStudio.TestTools.UITesting.UITestControl..ctor(IntPtr windowHandle)
            at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FromWindowHandle(IntPtr windowHandle)
            at Microsoft.VisualStudio.TestTools.UITesting.ApplicationUnderTest.SetCurrentProcessPrivate(Process value)
            at Microsoft.VisualStudio.TestTools.UITesting.ApplicationUnderTest.<>c__DisplayClassb.<set_Process>b__a()
            at Microsoft.VisualStudio.TestTools.UITesting.CodedUITestMethodInvoker.InvokeMethod[T](Func`1 function, UITestControl control, Boolean firePlaybackErrorEvent, Boolean logAsAction)
            at Microsoft.VisualStudio.TestTools.UITesting.ApplicationUnderTest.set_Process(Process value)
            at Microsoft.VisualStudio.TestTools.UITesting.ApplicationUnderTest.Start(ProcessStartInfo startInfo)
       InnerException: 

推荐答案

请尝试在按钮点击方法中添加Playback.Initialize()和Plauback.Cleanup()代码.

参考:

Reference: http://blogs.microsoft.co.il/shair/2010/07/15/running-codedui-test-from-another-application/

谢谢


这篇关于将CodedUI dll导入WPF应用程序,然后引发空引用引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆