C# VSTO Addin Exception With CurrentItem - c#

When trying to obtain the current item with focus in an outlook 2013 addin I get this exception: An exception of type 'System.MissingMemberException' occurred in System.Dynamic.dll but was not handled in user code
Additional information: Error while invoking [PROPERTYGET, DISPID(0)].
The code throwing the exception is this:
Inspector curObj = Globals.ThisAddIn.Application.ActiveInspector();
Object curItem = curObj.CurrentItem();
The second line throws the exception. The addin is launched from a button on the ribbon when in the create message window.
What is the proper way to access the current item as I think I'm doing it wrong which is causing the issue, since it's saying CurrentItem is not a member. The VBA code examples do it similar to this, but in C# CurrentItem doesn't seem to work the same.

CurrentItem is a property, not a method.

Related

Invalid parameter on FullSeriesCollection

Hi I'm taking back the lead on a project for an Excel plugin. But I ran into a kind of strange error:
System.Runtime.InteropServices.COMException (0x800A03EC): Parameter not valid at Microsoft.Office.Interop.Excel._Chart.FullSeriesCollection(Object Index)
The corresponding line is:
chart.FullSeriesCollection(1).DataLabels.ShowValue = true;
Any idea of what's wrong in there?

How to get a the value of "background-color" property of an element that I have in my NATIVE App

I'm developing a test code in c# (v3.0.02 of Appium) and I need to get the value of "background-color" property of an element that I have in my NATIVE App.
Here is a part of the code:
ReadOnlyCollection obj = driver.FindElementsByName("lblProtocolo");
for(int i=0;i<obj.Count;i++)
{
var str = obj[i].GetCssValue("background-color");
}
but is throwing an exception:
Test method ASEXamarin.Shared.Tests.TelaInicial.TesteRows threw exception:
System.NotImplementedException: Not yet implemented. Please help us: http://appium.io/get-involved.html
There is any form to get this property in NATIVE Apps?
There is a related post in:
Appium Android UI testing - how to verify the style attribute of an element?

Error while drawing shape on Canvas Windows 10 Universal Apps

I am creating an app that draws shapes on canvas and those shapes are recognized as letters using https://github.com/phatware/WritePadSDK sdk for writing pad. but the problem is that this api code works fine when it is used in windows 8.1 project but when the same code is used in windows 10 universal app it produces error when i debugged the code. Code of xaml is given bellow
<Canvas Background="WhiteSmoke" Name="InkCanvas" PointerPressed="OnCanvasPointerPressed" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" PointerReleased="OnCanvasPointerReleased" PointerCaptureLost="OnCanvasPointerCaptureLost" PointerExited="InkCanvas_OnPointerExited" PointerMoved="OnCanvasPointerMoved" LostFocus="InkCanvas_LostFocus">
and the code which is recognizes the shape using sdk is given bellow which is executed on PointerReleased event of Canvas:-
var resultValue = recognizerShared.RecognizeStrokes(InkCanvas.Children.ToList(), false);
and when i inspected the method given in sdk i.e. RecognizeStrokes which does the recolonization i got error when i did debugging
As this code works fine in windows 8.1 project i think it can be something todo with windows 10 universal app problem
Excelption details is given bellow:-
AccessKey = 'new System.Collections.Generic.Mscorlib_CollectionDebugView<Windows.UI.Xaml.UIElement>(strokes).Items[0].AccessKey' threw an exception of type 'System.InvalidCastException'
AccessKeyScopeOwner = 'new System.Collections.Generic.Mscorlib_CollectionDebugView(strokes).Items[0].AccessKeyScopeOwner' threw an exception of type 'System.InvalidCastException'
AllowFocusOnInteraction = '((Windows.UI.Xaml.FrameworkElement)new System.Collections.Generic.Mscorlib_CollectionDebugView(strokes).Items[0]).AllowFocusOnInteraction' threw an exception of type 'System.InvalidCastException'
AllowFocusWhenDisabled = '((Windows.UI.Xaml.FrameworkElement)new System.Collections.Generic.Mscorlib_CollectionDebugView(strokes).Items[0]).AllowFocusWhenDisabled' threw an exception of type 'System.InvalidCastException'
ContextFlyout = 'new System.Collections.Generic.Mscorlib_CollectionDebugView(strokes).Items[0].ContextFlyout' threw an exception of type 'System.InvalidCastException'
ExitDisplayModeOnAccessKeyInvoked = 'new System.Collections.Generic.Mscorlib_CollectionDebugView(strokes).Items[0].ExitDisplayModeOnAccessKeyInvoked' threw an exception of type 'System.InvalidCastException'
FocusVisualMargin = '((Windows.UI.Xaml.FrameworkElement)new System.Collections.Generic.Mscorlib_CollectionDebugView(strokes).Items[0]).FocusVisualMargin' threw an exception of type 'System.InvalidCastException'
FocusVisualPrimaryBrush = '((Windows.UI.Xaml.FrameworkElement)new System.Collections.Generic.Mscorlib_CollectionDebugView(strokes).Items[0]).FocusVisualPrimaryBrush' threw an exception of type 'System.InvalidCastException'
new System.Collections.Generic.Mscorlib_CollectionDebugView(strokes).Items[0].IsAccessKeyScope
Please help me to solve the problem above.
Link to download the sample project code is given bellow for testing where you can see the problem
https://www.dropbox.com/s/1xbtxbxwyoyuf00/WindowsSDK.rar?dl=0
Thanks!

Saving collection using PhoneApplicationService.Current.State

I'm trying to save a collection where a store a diagnostic log temporarily when navigating away from my app - I've looked at other sample code and it seems pretty basic as I've done below:
Saving:
PhoneApplicationService.Current.State["DiagnosticLog"] = DiagnosticLog;
Loading:
if (PhoneApplicationService.Current.State.ContainsKey("DiagnosticLog"))
DiagnosticLog = (ObservableCollection<DiagnosticLogEntry>)
PhoneApplicationService.Current.State["DiagnosticLog"];
However I get this error:
A first chance exception of type
'System.Runtime.Serialization.InvalidDataContractException' occurred
in System.Runtime.Serialization.dll
Any suggestions please?
Usually, when this happens, it means you do not have a default public constructor on your Diagnostic class (or one of it's contained classes).

Windows Service Webbrowser object invalid cast exception error

I'm having a bit of trouble with a Windows Service webbrowser object. It's attempting to load in values of username and password to a site but keeps failing and throwing the following error:
System.InvalidCastException: Specified cast is not valid.
at System.Windows.Forms.UnsafeNativeMethods.IHTMLDocument2.GetLocation()
at System.Windows.Forms.WebBrowser.get_Document()
at MyWindowsService.MyDataProcessor.login()
The code that I'm using to make this call is:
MyWebBrowser.Document.All["Login"].SetAttribute("Value", username);
MyWebBrowser.Document.All["Password"].SetAttribute("Value", password);
MyWebBrowser.Document.All["submit"].InvokeMember("Click");
Any ideas as to why it keeps failing? Thanks in advance for the help.
I'm not sure if this solves the problem, but you can check InvokeRequired property on the current object, or WebBrowser.InvokeRequired, and use something like MethodInvoker to call your function or a helper function to access WebBrowser.Document.
http://www.megasolutions.net/cSharp/(WebBrowser_Document-==-null)-throws-InvalidCastException-43126.aspx
I had a similar problem using SHDocVW.WebBrowserClass. I got an InvalidCastException when I tried to access Document.all from an instance of SHDocVW.WebBrowserClass (from the main thread) and I was able to fix it by casting to IHTMLDocument2 instead of HTMLDocument. This took me a long time to figure out because casting to HTMLDocument works most of the time.
SHDocVW.WebBrowserClass Explorer = [instance of IE];
((IHTMLDocument2)Explorer.Document).all // works all the time
((HTMLDocument)Explorer.Document).all // works some times
I hope this helps someone.

Categories

Resources