I'm working on my first Xamarin Forms application. I've run into an issue that I cannot figure out how to debug. There's a null value in the theme. But there aren't a lot of indicators as to what may be missing. If I catch this exception and ignore it, there doesn't seem to be any issue with the app execution.
When I change the orientation of the phone, I get this exception:
{System.ArgumentNullException: Value cannot be null.
Parameter name: enumerable
at Xamarin.Forms.Internals.EnumerableExtensions.IndexOf[T] (System.Collections.Generic.IEnumerable`1[T] enumerable, T item) [0x00003] in D:\a\1\s\Xamarin.Forms.Core\EnumerableExtensions.cs:79
at Xamarin.Forms.Application.OnRequestedThemeChanged (Xamarin.Forms.AppThemeChangedEventArgs args) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Application.cs:172
at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.OnConfigurationChanged (Android.Content.Res.Configuration newConfig) [0x0001e] in D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:90
at App1.Droid.MainActivity.OnConfigurationChanged (Android.Content.Res.Configuration newConfig) [0x00002] in C:\source\repos\App1\App1\App1.Android\MainActivity.cs:30 }
I see it comes from the internal Forms code. Any idea what it is trying to enumerate over?
The comment asks for the code at line MainActivity.cs:30
The code at line 30 is base.OnConfigurationChanged(newConfig);
The point is that the exception happens in the internal Xamarin.Forms code and I have no idea what the enumeration is supposed to represent.
public override void OnConfigurationChanged(Configuration newConfig)
{
try
{
base.OnConfigurationChanged(newConfig);
}
catch (ArgumentNullException ex)
{
string m = ex.Message;
}
}
I had the same problem and rolling Xamarin.Forms back to version 4.6.0.726 fixed it.
I have submitted a bug report on Xamarin.Forms Github https://github.com/xamarin/Xamarin.Forms/issues/10733
I cannot seem to find a good solution for this issue online. I have a device that is running Windows Embedded Handheld 6.5. I run the solution located at below
C:\Program Files (x86)\Windows Mobile 6.5.3 DTK\Samples\PocketPC\CS\GPS
I deploy the code to my device, not an emulator, and the code breaks with a null reference exception at
Invoke(updateDataHandler);
The solution ive seen recommends changing this to below
BeginInvoke(updateDataHandler);
But now the code breaks at Main with NullRefreceException.
Application.Run(new Form1());
Has anyone found a solution for this?
Did you alter the code? updateDataHandler is initialized in Form_Load:
private void Form1_Load(object sender, System.EventArgs e)
{
updateDataHandler = new EventHandler(UpdateData);
so that object will not be NULL. But there are other annoyances with the code, especially the Samples.Location class. You may instead use http://www.hjgode.de/wp/2010/06/11/enhanced-gps-sample-update/ as a starting point and the older one: http://www.hjgode.de/wp/2009/05/12/enhanced-gps-sampe/
The main issue with the sample is that it does not use a callback (delegate) to update the UI. If an event handler is fired from a background thread, the handler can not directly update the UI. Here is what I always use to update the UI from a handler:
delegate void SetTextCallback(string text);
public void addLog(string text)
{
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (this.txtLog.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(addLog);
this.Invoke(d, new object[] { text });
}
else
{
txtLog.Text += text + "\r\n";
}
}
I have a native plugin that has callbacks back to the C# code. This is how the callbacks are setup:
C# Side (Unity):
public delegate void Callback(int value);
[DllImport("NativePlugin")]
public static extern void setup_callback(Callback callback);
[MonoPInvokeCallback(typeof(Callback))]
private static void OnCallback(int value)
{
Debug.Log("Callback called with value: " + value);
}
void Start()
{
setup_callback(OnCallback);
}
The Objective-C side (with C wrapper so you'd be able to call it from C#):
typedef void(*Callback)(int);
Callback _callback = NULL;
void setup_callback(Callback callback)
{
_callback = callback;
}
void on_something_happened(int value)
{
if(_callback)
_callback(value);
}
Now, most of the time the above code works ok, and I receive the correct values in Unity. But sometimes when I make changes to any one of my C# scripts, Unity crashes with this:
Exception Type: EXC_BAD_ACCESS (SIGABRT)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000000ffffffa9
Exception Note: EXC_CORPSE_NOTIFY
Looking at Unity's Editor logs I found out that when I make changes to a C# script it recompiles Assembly-CSharp.dll and reloads it togheter with some other C# assemblies. So that made me think that this might cause the pointer saved in the native plugin to now point to an invalid address (because Assembly-CSharp.dll is now probably in a different address space). Note that it does not happen every time the dll gets reloaded, is it possible that it gets reloaded to the exact same address space sometimes?
Can I get an event from Unity when the editor reloads the DLL and then re-register the callbacks (assuming that this is the real problem)? Is this even the correct way to setup a callback from native code?
I have a coded UI test built with VS2010 for TFS2010 running on machine A. I have a test agent installed on machine A that the tests run on successfully. My testsettings file>Roles is set to RemoteExecution because these codedUI tests ALWAYS need to be run on machine A. The file always says "connected to the controller" that I specified.
I check the code into the build server (machine B), and it fails. With copy local set to false on the codedUI assemblies, the build fails with an error:
"Not runnable: Failed to initialize the unit test extension
'urn:CodedUITest': A unit test extension is not registered for the
following attribute:
Microsoft.VisualStudio.TestTools.UITesting.CodedUITestAttribute."
In the application logs on machine B, I get this:
(QTAgent32.exe, PID 5308, Thread 8) GetCollectorType: Failed to get
type for Collector
'Microsoft.VisualStudio.TestTools.DataCollection.SystemInfo.SystemInfoDataCollector,
Microsoft.VisualStudio.TestTools.DataCollection.SystemInfo,
Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a':
System.IO.FileNotFoundException: Could not load file or assembly
'Microsoft.VisualStudio.TestTools.DataCollection.SystemInfo,
Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or
one of its dependencies. The system cannot find the file specified.
File name:
'Microsoft.VisualStudio.TestTools.DataCollection.SystemInfo,
Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean
throwOnError, Boolean ignoreCase, Boolean reflectionOnly,
StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean
loadTypeFromPartialName, ObjectHandleOnStack type) at
System.RuntimeTypeHandle.GetTypeByName(String name, Boolean
throwOnError, Boolean ignoreCase, Boolean reflectionOnly,
StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean
loadTypeFromPartialName) at System.RuntimeType.GetType(String
typeName, Boolean throwOnError, Boolean ignoreCase, Boolean
reflectionOnly, StackCrawlMark& stackMark) at
System.Type.GetType(String typeName, Boolean throwOnError) at
Microsoft.VisualStudio.TestTools.DataCollection.ExecutionPluginManager.GetCollectorType(String
collectorTypeName, Exception& loadException)
WRN: Assembly binding logging is turned OFF. To enable assembly bind
failure logging, set the registry value
[HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. Note: There
is some performance penalty associated with assembly bind failure
logging. To turn this feature off, remove the registry value
[HKLM\Software\Microsoft\Fusion!EnableLog].
And in the Administration console I get this:
Following error encountered while reading sqm registry entry:
TF255003: The installation path cannot be found for the following
feature: ApplicationTier. Either the feature is not installed, or you
must use a different installation path.
With copy local set to true on the coded UI assemblies, I don't get any error in the Build Explorer in VS, but the build fails and says 0/0 tests run. In the application log on machine B, I get:
The description for Event ID 0 from source VSTTExecution cannot be
found. Either the component that raises this event is not installed on
your local computer or the installation is corrupted. You can install
or repair the component on the local computer.
If the event originated on another computer, the display information
had to be saved with the event.
The following information was included with the event:
(MSTest.exe, PID 5544, Thread 1) Exception thrown when enumerating
assembly:
Microsoft.VisualStudio.TestTools.Exceptions.EqtDataException: Unable
to load the test container
'C:\Builds\1\Project\Binaries\Microsoft.VisualStudio.QualityTools.CodedUITestFramework.dll'
or one of its dependencies. Error details:
System.IO.FileNotFoundException: Could not load file or assembly
'Microsoft.VisualStudio.QualityTools.Vsip, Version=10.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its
dependencies. The system cannot find the file specified.
at
Microsoft.VisualStudio.TestTools.TestTypes.Unit.AssemblyEnumerator.EnumerateAssembly(IWarningHandler
warningHandler, String location, ProjectData projectData, ObjectHandle
assemblyResolverWrapper) at
Microsoft.VisualStudio.TestTools.TestTypes.Unit.AssemblyEnumerator.EnumerateAssembly(IWarningHandler
warningHandler, String location, ProjectData projectData, ObjectHandle
assemblyResolverWrapper) at
Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAttributeEnumerator.Read(ITestTypeExtensionClientSidesProvider
provider, IWarningHandler warningHandler, String assemblyFileName,
ProjectData projectData, TestRunConfiguration testRunConfiguration)
Machine B does have VS2010 express installed.
What else do I need to do to get this building on Machine B (build machine), but tests running on Machine A (with the test agent)? What else can I do to diagnose this?
UPDATE: I tried manually copying the qualitytools.vsip dll into the project and referencing it that way with copy local set to true, but now I'm back to getting
"Failed to initialize the unit test extension 'urn:CodedUITest': A
unit test extension is not registered for the following attribute:
Microsoft.VisualStudio.TestTools.UITesting.CodedUITestAttribute."
Kindly make a check the project property that the target framework is not set to .NET framework 4 client profile. Instead set to .Net framework 4 (without client profile)
using Microsoft.VisualStudio.TestTools.UITesting;
using Microsoft.VisualStudio.TestTools.UITesting.HtmlControls;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CodedUITestProject1.Libraries
{
class generic
{
public static BrowserWindow mParentWindow { get; set; }
public static BrowserWindow ParentWindow
{
get
{
if(mParentWindow==null)
{ mParentWindow = TopParentWindow(); }
return mParentWindow;
}
}
public static BrowserWindow TopParentWindow()
{
BrowserWindow window = new BrowserWindow();
window.SearchProperties[UITestControl.PropertyNames.ClassName]=BrowserWindow.CurrentBrowser.ToString();
return window;
}
public enum PropertyType
{ Id,
Name,
ClassName,
InnerText,
TagInstance
}
public static void EnterText<T>(PropertyType type,string propvalue,string text) where T:HtmlControl
{
HtmlControl genericControl = (T)Activator.CreateInstance(typeof(T), new object[] { ParentWindow });
if (type==PropertyType.Id)
{
genericControl.SearchProperties[HtmlControl.PropertyNames.Id] = propvalue;
}
else if (type == PropertyType.Id)
{
genericControl.SearchProperties[HtmlControl.PropertyNames.Id] = propvalue;
}
Keyboard.SendKeys(genericControl, text);
}
public static void ClickLink<T>(PropertyType type, string propvalue) where T : HtmlControl
{
HtmlControl genericControl = (T)Activator.CreateInstance(typeof(T), new object[] { ParentWindow });
if (type == PropertyType.Id)
{
genericControl.SearchProperties[HtmlControl.PropertyNames.Id] = propvalue;
}
else if (type == PropertyType.Id)
{
genericControl.SearchProperties[HtmlControl.PropertyNames.Id] = propvalue;
}
//Assert.IsTrue(genericControl.WaitForControlExist(40000));
Mouse.Click(genericControl);
}
public static Boolean ExistLink<T>(PropertyType type, string propvalue) where T : HtmlControl
{
HtmlControl genericControl = (T)Activator.CreateInstance(typeof(T), new object[] { ParentWindow });
if (type == PropertyType.Id)
{
genericControl.SearchProperties[HtmlControl.PropertyNames.Id] = propvalue;
}
else if (type == PropertyType.Id)
{
genericControl.SearchProperties[HtmlControl.PropertyNames.Id] = propvalue;
}
try
{
Assert.IsTrue(genericControl.WaitForControlExist(4000));
return true;
}
catch (Exception e)
{
return false;
}
//Mouse.Click(genericControl);
}
}
}
Solution 1: Replace the name as that seen in pop UP. Might be this code can help clicking it
WinWindow pop = new WinWindow(null);
pop.SearchProperties.Add("Name", "Message from webpage", "ClassName", "#32770");
‘Windows Internet Explorer
pop.TechnologyName = "MSAA";
pop.DrawHighlight();
//------------
“Usinng MSTEST.exe to generate result”
C:\Program Files\Microsoft Visual Studio 12.0\Common7\IDE>MSTest /testcontainer:
D:\Practise\CodedUITestProject1\CodedUITestProject1\CodedUITestProject1\bin\Debu
g\CodedUITestProject1.dll /test:CodedUITestMethod1 /resultsfile:D:\SachintestRes
.trx
public void CodedUITestMethod1()
{
// To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
// To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
string testcase = " /testcontainer:" + "D:\\Practise\\CodedUITestProject1\\CodedUITestProject1\\CodedUITestProject1\\bin\\Debug\\CodedUITestProject1.dll /test:CodedUITestMethod1 /resultsfile:D:\\SachintestResAut.trx";
string Path = #"C:\Program Files\Microsoft Visual Studio 12.0\Common7\IDE\MSTest";
Process myProcess = new Process();
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(Path, testcase);
myProcessStartInfo.UseShellExecute = false;
try
{
myProcess.StartInfo = myProcessStartInfo;
myProcess.Start();
myProcess.BeginOutputReadLine();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
WinText text = new WinText(pop);
text.SearchProperties.Add("Name", "Some Name");
String msg = text.GetProperty("DisplayText").ToString();
if (msg.Contains("Data saved."))
{
Console.WriteLine("System is displaying " + msg);
}
else
{
Console.WriteLine("System is displaying " + msg);
}
WinButton ok = new WinButton(pop);
ok.TechnologyName = "MSAA";
ok.SearchProperties.Add("Name", "OK");
Mouse.Click(ok);
Solution 2: Try the Browser Dialog Actions like OK,Cancel,Close .May be it can be helpful. PFB snapshot below.
try
{
BrowserWindow browserWindow = new BrowserWindow();
browserWindow.PerformDialogAction(BrowserDialogAction.Ok);
}
catch (Exception)
{
// If a popup does not exists and an error is thrown, continue...
Playback.PlaybackSettings.ContinueOnError = true;
}
//C:\Program Files\Microsoft Visual Studio 12.0\Common7\IDE>MSTest /testcontainer:
D:\Practise\CodedUITestProject1\CodedUITestProject1\CodedUITestProject1\bin\Debu
g\CodedUITestProject1.dll /test:CodedUITestMethod1 /resultsfile:D:\SachintestRes
.trx
public void CodedUITestMethod1()
{
// To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
// To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
string testcase = " /testcontainer:" + "D:\\Practise\\CodedUITestProject1\\CodedUITestProject1\\CodedUITestProject1\\bin\\Debug\\CodedUITestProject1.dll /test:CodedUITestMethod1 /resultsfile:D:\\SachintestResAut.trx";
string Path = #"C:\Program Files\Microsoft Visual Studio 12.0\Common7\IDE\MSTest";
Process myProcess = new Process();
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(Path, testcase);
myProcessStartInfo.UseShellExecute = false;
try
{
myProcess.StartInfo = myProcessStartInfo;
myProcess.Start();
myProcess.BeginOutputReadLine();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
The thing is, I got a weird exception from Windows Phone app I am developing:
System.Exception was unhandled
Message=Unspecified error
StackTrace:
at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.Collection_AddValue[T](PresentationFrameworkCollection`1 collection, CValue value)
at MS.Internal.XcpImports.Collection_AddDependencyObject[T](PresentationFrameworkCollection`1 collection, DependencyObject value)
at System.Windows.PresentationFrameworkCollection`1.AddDependencyObject(DependencyObject value)
at System.Windows.Controls.UIElementCollection.AddInternal(UIElement value)
at System.Windows.PresentationFrameworkCollection`1.Add(UIElement value)
at System.Windows.Controls.ItemsControl.AddVisualChild(Int32 index, DependencyObject container, Boolean needPrepareContainer)
at System.Windows.Controls.ItemsControl.AddContainerForPosition(GeneratorPosition position)
at System.Windows.Controls.ItemsControl.OnItemsChangedHandler(Object sender, ItemsChangedEventArgs args)
at System.Windows.Controls.ItemContainerGenerator.OnItemAdded(Object item, Int32 index)
at System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.ICollectionChangedListener.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
at System.Windows.Controls.WeakCollectionChangedListener.SourceCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
at System.Windows.Controls.ItemCollection.NotifyCollectionChanged(NotifyCollectionChangedEventArgs e)
at System.Windows.Controls.ItemCollection.System.Windows.Controls.ICollectionChangedListener.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
at System.Windows.Controls.WeakCollectionChangedListener.SourceCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, FormItem item)
at System.Collections.ObjectModel.Collection`1.Add(FormItem item)
at //My Code
What my code tried to do is add a item to an ObservableCollection.
I want to step into System.Windows code so I can see what that "Unspecified error" is.
I already do the following in my Visual Studio:
Enable .NET Framework source stepping
Enable source server support
Enable Microsoft Symbol Servers
Despite that, I can't step in (double clicking) into any of System.Windows methods in the call stack.
Any help is appreciated. Let me know if any of you need more clarification.