This project is read-only.
3
Vote

OutOfBrowser Support - "System.NotSupportedException: This operation is not supported in the current context." when trying to use AutomationFactory.CreateObject within a unit test

description

Hi.
 
Thank you for StatLight v1.3.
 
I am using Visual Studio 2010 Premium and Silverlight 4.0.50917.0 on Windows 7 Ultimate x64.
 
I created a new silverlight application, created a new class, and added the following:
 
[TestClass]
public class Tests
{
[TestMethod]
public void TestMe()
{
dynamic fileSystem = AutomationFactory.CreateObject("Scripting.FileSystemObject");
}
}
 
I also added a reference to the following assemblies:
"C:\Program Files (x86)\Microsoft SDKs\Silverlight\v4.0\Toolkit\Apr10\Testing\Microsoft.Silverlight.Testing.dll"
"C:\Program Files (x86)\Microsoft SDKs\Silverlight\v4.0\Toolkit\Apr10\Testing\Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight.dll"
 
But when I tried to run StatLight.exe passing it the silverlight xap file using the -x command line parameter, I received the following error:
 
StatLight - Version 1.3.3981
Copyright (C) 2009 Jason Jarrett
All Rights Reserved.



Starting Test Run: 2/9/2011 5:49:56 PM

.
------------------ Test Failed ------------------
Test Namespace: MyTestAssembly
Test Class: Tests
Test Method: TestMe
Exception Message:
System.NotSupportedException: This operation is not supported in the current context.
 at MS.Internal.Error.MarshalXresultAsException(UInt32 hr, COMExceptionBehavior comExceptionBehavior)
 at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
 at MS.Internal.ComAutomation.ComAutomationNative.CreateObject(String progID, IntPtr& nativeObject)
 at MS.Internal.ComAutomation.ComAutomationServices.CreateObject(String progID, ComAutomationParamWrapService paramWrapService)
 at System.Runtime.InteropServices.Automation.AutomationFactory.CreateObject(String progID)
 at MyTestAssembly.Tests.TestMe()

--- Completed Test Run at: 2/9/2011 5:49:58 PM. Total Run Time: 00:00:02.5672567

Test run results: Total 1, Successful 0, Failed 1,
 
Any ideas?
 
A unit test without using AutomationFactory.CreateObject works without issues.
 
Thank you.

file attachments

comments

icnocop wrote Feb 10, 2011 at 2:30 AM

I think this is related to the discussion here:
http://statlight.codeplex.com/Thread/View.aspx?ThreadId=235367
Is it possible to run OOB tests using statlight?
Not immediately possible to run OOB tests with StatLight. I do think it might be possible with some effort. I have a feeling to do so StatLight would have to "install" the app before trying to kick off the tests, which would mean it should uninstall it when done. If you manage to figure out how to do this I'd love to hear about it.
AutomationFactory.CreateObject requires running silverlight application elevated\oob.

Here is an article that outlines the different command line options for sllauncher.exe which can be used to install, launch, and uninstall a silverlight application oob:
http://timheuer.com/blog/archive/2010/03/25/using-sllauncher-for-silent-install-silverlight-application.aspx

staxmanade wrote Feb 19, 2011 at 5:51 PM

I made recent code changes to possibly support out of browser. It's totally hanging and I'm having trouble figuring out why... If anyone wants to take a look and give any feedback or ideas as to why it's hanging, maybe we can push forward with out of browser support.

https://github.com/staxmanade/StatLight/commit/7cbb547863d4caf20d35c9c57f0adcc1d5d86f5e

wrote Feb 19, 2011 at 5:51 PM

wrote Feb 23, 2011 at 7:57 PM

icnocop wrote Feb 23, 2011 at 7:57 PM

Hi Jason,

Thank you for the oob branch.

I built StatLight from source on Windows 7 Ultimate 64-bit with Visual Studio 2010 Premium.
The only issue I had was that I could not build it from the sln file as I would get errors with the AssemblyInfo.cs file until I ran "build-Full-Release-skip-tests.bat" for example.

But then when I tried to run it instead of StatLight v1.2, I received the following error:
Could not find file 'C:\github\StatLight\src\build\bin\Debug\StatLight.Client.For.April2010.xap'.

So I copied it from StatLight v1.2 and ran StatLight again.

This time the StatLight Browser Host appeared as usual, but silverlight did not get loaded.
When I clicked the button to install silverlight, I received the message "Microsoft Silverlight cannot be used in browsers running in 64 bit mode."
See attached screenshot.

But yes, I am experiencing the same issue, StatLight.exe hangs even after I manually close the browser host.

icnocop wrote Feb 23, 2011 at 8:28 PM

Running the x86 version of StatLight resolves the silverlight loading issue...

icnocop wrote Feb 23, 2011 at 8:50 PM

I also had to copy "StatLight.Client.Harness.xap" to the output directory and use it instead of "StatLight.Client.For.April2010.xap" for example.

icnocop wrote Feb 23, 2011 at 8:57 PM

Ok, I found the issue here:
StatLight.Client.Harness\Hosts\NormalStatLightSystem.cs
Line 16
var src = Application.Current.Host.Source;

When you run "StatLight.Client.Harness.xap" out of browser, you will notice that src is the path to the physical xap file and not a url as the code expects.

:)

staxmanade wrote Feb 24, 2011 at 5:01 AM

The typical F5 build/debug story is not really there with StatLight. You must build using psake. Take a look at the bat files to see how they do it. Or try "Invoke-Psake ?" to get a list of commands you can run... You can then run a simple test I created in psake with a task named "test-OutOfBrowser".
<br><br>
Another interesting place to look is https://github.com/staxmanade/StatLight/commit/74b1d870ecbb79ded46e557adb6e20c5d586d41e#L10R32
The value being passed in to the /origin:{1} parameter has something to do with what is set in the Application.Current.Host.Source; (With what's checked in - if you execute it through the psake test - all that seemed to check out. - but right after that it just hung and sat there...)

Hope this helps.

Yes, Yes I know... I need to get a how-to-develop-in-the-statlight-project documentation together... I'll try to put something together in the next couple weeks...

icnocop wrote Mar 1, 2011 at 12:19 AM

I would recommend:
  1. add "Debugger.Break();" in the constructor in "src\StatLight.Client.Harness\App.xaml.cs"
  2. include the pdb files within the xap files if they are built in debug mode (ex. "StatLight.Client.For.May2010.xap")
  3. run "test-OutOfBrowser" and then step through the code when the debugger break signal is hit

staxmanade wrote Mar 2, 2011 at 12:03 AM

Debugger.Break doesn't work. However I placed this in the beginning of Application_Start and could attach the debugger to the process.
        if (IsRunningOutOfBrowser)
            while (true)
                System.Threading.Thread.Sleep(1000);
Updated the build (and pushed to the oob branch) to include the pdb's in debug mode (don't think this helped with anything).

Still not finding the problem. I debug through the call that is making a service request to get the test run configuration and it just never comes back. Just hangs there...

wrote Oct 31, 2011 at 11:52 PM

wrote Feb 14, 2013 at 9:18 PM