Can I use the ContactPicker contract when the app is snapped?
var picker = new Windows.ApplicationModel.Contacts.ContactPicker();
picker.CommitButtonText = "Select";
picker.SelectionMode = Windows.ApplicationModel.Contacts.ContactSelectionMode.Fields;
picker.DesiredFields.Add(Windows.ApplicationModel.Contacts.KnownContactField.Email);
var contactInformation = await picker.PickSingleContactAsync();
The above code works when in fullscreen but throws the following exception on the call to PickSingleContactAsync() when snapped to the side of the screen:
System.Runtime.InteropServices.COMException was unhandled by user code
HResult=-2147467259
Message=Error HRESULT E_FAIL has been returned from a call to a COM component.
Source=mscorlib
ErrorCode=-2147467259
StackTrace:
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at TouchToneDtmf.MainPage.d__e.MoveNext()
in
d:\Users\Foo\MainPage.xaml.cs:line
556 InnerException:
It's not working when the app is snapped - you should check the visual state of the app before calling the ContactPicker.
In the official C# sample there is also method EnsureUnsnapped() you might find helpful when implementing this contract.
Every time you call a file[/contact] picker you must first make sure that your
app can show the file[/contact] picker by verifying that your app in not snapped
or, if your app is snapped, that it can be unsnapped in order to show
the file picker. Source - How to save files through file pickers
using Windows.UI.ViewManagement;
//...
internal bool EnsureUnsnapped()
{
bool unsnapped = ((ApplicationView.Value != ApplicationViewState.Snapped) || ApplicationView.TryUnsnap());
return unsnapped;
}
Related
I'm running into an exception in C# code intended to set the contents of a WinUI3 Image object. I don't know how to interpret the exception message.
Here's the code:
using var responseStream = await response.Content.ReadAsInputStreamAsync();
var memStream = new InMemoryRandomAccessStream();
await RandomAccessStream.CopyAsync(responseStream, memStream);
memStream.Seek(0);
var retVal = new Image();
var source = new BitmapImage();
// the exception is thrown on the next line
await source.SetSourceAsync( outStream );
retVal.Source = source;
The exception message is
Unspecified error (Error HRESULT E_FAIL has been returned from a call to a COM component.)
What's weird is that calls to this code sometimes succeed and sometimes don't, even when the exact same parameters (which define the Uri that the response stream is derived from) are specified and the exact same response is received.
That suggests there's something in the context of the call that's the problem. The cases that succeed are when the code is called from a viewmodel in a WinUI3 test app. The cases that fail are when the code is called from a custom WinUI3 control I've written.
I thought there might be a "called from the wrong thread" problem but in both the success and failure cases the code is being called from the main UI thread.
Another odd thing is that the code throwing the exception is contained within a try/catch block (not shown for simplicity)...but the catch block doesn't catch the exception. Instead, it gets caught by the unhandled exception handler generated by WinUI3.
Advice on how to proceed with researching what's going wrong -- or potential solutions! -- would be appreciated, thanx.
I can't resolve ILogger instance in my console application...
I'm using Unity IoC and Serilog.
The registration is done like this:
container = new UnityContainer();
container.RegisterFactory<ILogger>(factory =>
{
ILogger log = new LoggerConfiguration()
.WriteTo.Console()
.CreateLogger();
return log;
}, new ContainerControlledLifetimeManager());
And then when I try this:
var logger = container.Resolve<ILogger>();
I get an exception:
Unity.ResolutionFailedException HResult=0x80131500 Message=Failed
to select a constructor for Serilog.Core.Logger
_____________________________________________________ Exception occurred while:
•resolving type: 'ILogger' mapped to 'Logger'
Source=Unity.Container StackTrace: at
Unity.UnityContainer.ExecuteValidatingPlan(BuilderContext& context)
at Unity.UnityContainer.Unity.IUnityContainer.Resolve(Type type,
String name, ResolverOverride[] overrides) at
Unity.UnityContainerExtensions.Resolve[T](IUnityContainer container,
ResolverOverride[] overrides)
Inner Exception 1: InvalidOperationException: Failed to select a
constructor for Serilog.Core.Logger
Inner Exception 2: InvalidRegistrationException: Exception of type
'Unity.Exceptions.InvalidRegistrationException' was thrown.
I even tried registering it like this:
container = new UnityContainer();
ILogger log = new LoggerConfiguration()
.WriteTo.Console()
.CreateLogger();
container.RegisterInstance<ILogger>(log);
but with the same resulting exception thrown.
Please help
Found the problem...
The problem was this line of code down the road, overriding my configuration:
container.RegisterTypes(AllClasses.FromAssembliesInBasePath(), WithMappings.FromMatchingInterface, WithName.Default);
How to get the languageCode in the method getData()? Or just outside the getConfig() method? I read that languageCode is passed in the request parameter of the getData() method. I have other properties of the config. But languageCode not. This is the output of the requestparameter:
{dateRange={endDate=2018-12-17, startDate=2018-11-20}, fields=[{name=Field_1}, {name=Field2}]}
This is my getConfig method:
function getConfig(params) {
var cc = DataStudioApp.createCommunityConnector();
var config = cc.getConfig();
var lang = params['languageCode'];
config
.newInfo()
.setId('id_1')
.setText(i18n('SomeText'))
config.setDateRangeRequired(true);
return config.build();
}
And one more question. When I throw an exception in a message, along with the text of the exception, a string is also displayed on which I threw an exception. Is there any way to hide this information? And just display the text of the thrown exception? Without the string on which the exception was thrown?
And one more question. When I throw an exception in a message, along with the text of the exception, a string is also displayed on which I threw an exception. Is there any way to hide this information? And just display the text of the thrown exception? Without the string on which the exception was thrown?
The debug information is only shown when isAdminUser() returns True. To omit this information, set this to return false.
I am creating an app which need to add In app Purchasing option to purchase selected video, and when purchased send request to download it on other server with Receipt;
I am trying to achieve list of available option to purchase with the fallowing code--
try
{
ListingInformation ProdList = await CurrentApp.LoadListingInformationAsync();
lbProductsList.Items.Clear();
string t = "";
foreach (var item in ProdList.ProductListings)
{
t = string.Format("{0}, {1}, {2},{3}, {4}",
item.Key,
item.Value.Name,
item.Value.FormattedPrice,
item.Value.ProductType,
item.Value.Description);
lbProductsList.Items.Insert(0, t);
}
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
code line-
ListingInformation ProdList = await CurrentApp.LoadListingInformationAsync();
its creating problem and control goes to catch block showing error message --
The explicit transaction has been forcibly cancelled. (Exception from
HRESULT: 0x8032000F)
and when using registered Product Id it show the fallowing error--
System.Exception: Exception from HRESULT: 0x805A0194
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at IAP.MainPage.d__1.MoveNext()
Would any one please tell what is the problem with it.
I am using registed App Id to load information but can't
any help is good for me.
Thanks.
can you check your app guid in the WMAppManifest.xml file with guid in DevCenter published app guid? If not, make sure you should update your WMAppManifest.xml with guid from devcenter.
Have you created any in-app products in Dev Center associated with your app? Make sure the product id matches the product id in Dev Center for your main app that references these in-app products.
0x805A0194 is one of the exception errors you will get if the app could not get the products associated with the app and you have an internet connection.
I'm building an application in C# that has a static class which initiate a COM class and handles some event handlers of another class that hooks keyboard.
When I call a method of the COM class from a button event handler in my WPF window, the method works without any problems but when I call it in one of the event callbacks within my static class it throws following exception:
Unable to cast COM object of type 'BLAHBLAH' to interface type
'BLAHBLAH'. This operation failed because the QueryInterface call on
the COM component for the interface with IID
'{9DD6680B-3EDC-40DB-A771-E6FE4832E34A}' failed due to the following
error: An outgoing call cannot be made since the application is
dispatching an input-synchronous call. (Exception from HRESULT:
0x8001010D (RPC_E_CANTCALLOUT_ININPUTSYNCCALL)).
Can you please tell me, what this exception means and how can I solve it?
Wrap your code in a new thread:
Thread thread = new Thread(() =>
{
ManagementObjectSearcher theSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");
foreach (ManagementObject currentObject in theSearcher.Get())
{
Debug.WriteLine("Device present: " + currentObject);
ManagementObject theSerialNumberObjectQuery = new ManagementObject("Win32_PhysicalMedia.Tag='" + currentObject["DeviceID"] + "'");
serial = theSerialNumberObjectQuery["SerialNumber"].ToString();
}
});
thread.Start();
thread.Join(); //wait for the thread to finish
Refer this KB http://support.microsoft.com/kb/198996
Looks like it is because of threads(May not be user defined threads)