My application is a WinUI desktop application using .Net 6.
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
<UseWinUI>true</UseWinUI>
I thought I could use the EmailManager from UWP (which supports email attachments) but I get the following error when I do.
System.Runtime.InteropServices.COMException (0x80070032): The request is not supported. (0x80070032)
at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|20_0(Int32 hr)
at WinRT.ExceptionHelpers.ThrowExceptionForHR(Int32 hr)
at ABI.Windows.ApplicationModel.Email.IEmailManagerStaticsMethods.ShowComposeNewEmailAsync(IObjectReference _obj, EmailMessage message)
at Windows.ApplicationModel.Email.EmailManager.ShowComposeNewEmailAsync(EmailMessage message)
at WinUIApp.MainWindow.ComposeEmail(String subject, String messageBody)
What is the correct API to use to send emails from a WinUI application?
Code
I made the application using the default WinUI template and simply added the following code in MainWindows.xaml.cs to test.
private void myButton_Click(object sender, RoutedEventArgs e)
{
myButton.Content = "Clicked";
ComposeEmail("Bob", "Hello Bob.");
}
private async Task ComposeEmail(string subject, string messageBody)
{
try
{
var emailMessage = new Windows.ApplicationModel.Email.EmailMessage();
await Windows.ApplicationModel.Email.EmailManager.ShowComposeNewEmailAsync(emailMessage);
}
catch (Exception e)
{
Debug.WriteLine(e);
}
}
Note that the previous code works fine in a UWP app. It launches the Mail app. I was expecting it to do the same in my WinUI app, but it doesn't.
The EmailManager API is only supported with UWP apps, because it depends on Windows.UI.Core.CoreWindow Class's GetForCurrentThread method which always get backs null for non-UWP apps.
You can check this dependency if you disassemble the ShowComposeNewEmailAsync function, as shown in this screenshot here:
Some of these WinRT classes have been modified to support the IInitializeWindow trick to support classical HWNDs, but it seems it's not the case here. Maybe you can report that to Microsoft so they can improve it.
So you'll have to find other non-WinRT/UWP ways to send email.
Related
I am trying to communicate with my chatbot via a Windows Form App (using C#). I have installed the SDK into Visual Studio, but I am having trouble using it. I have read through all the documentation, including on GitHub, however, because this is my first time using the SDK, I am quite confused about how to get it to work. At this point, I simply want to be able to send a "Message" and read the chatbot's response.
Which namespaces do I have to include (i.e. "using IBM.Watson...")? Because I have tried authenticating but am getting the error: "namespace AssistantService could not be found", as per the IAM authentication in dotnet guide on GitHub. Also, what is an "_assistant" object and how to I create one, the docs don't explain this so I keep getting the error "_assistant does not exist in the current context..."
This is the link that to the SDK I am following: https://github.com/watson-developer-cloud/dotnet-standard-sdk
I am trying to authenticate with the instructions at that link but am not succeeding. I am trying to use these instructions to call the Watson Assistant: https://github.com/watson-developer-cloud/dotnet-standard-sdk/tree/development/src/IBM.WatsonDeveloperCloud.Assistant.v1
****************UPDATE*****************
using System.Windows.Forms;
using IBM.WatsonDeveloperCloud.Assistant.v1.Model;
using IBM.WatsonDeveloperCloud.Assistant.v1;
using IBM.WatsonDeveloperCloud.Util;
namespace Watson_Assistant_Test
{
public partial class Form1 : Form
{
AssistantService _assistant;
string[] _questionArray = { "Hello there" };
public Form1()
{
TokenOptions iamAssistantTokenOptions = new TokenOptions()
{
IamApiKey = "Y....H",
IamUrl = "https://gateway-syd.watsonplatform.net/assistant/api"
};
_assistant = new AssistantService(iamAssistantTokenOptions, "2018-07-10");
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MessageRequest messageRequest = new MessageRequest()
{
Input = new InputData()
{
Text = _questionArray[0]
}
};
var result = _assistant.Message("d...5", messageRequest);
label1.Text = result.ResponseJson.ToString();
}
}
}
I think I am still not creating the AssistantObject correctly. I am getting this error: ServiceResponseException: The API query failed with status code NotFound: Not Found.
Thanks, Harry
[I am not a C# developer and have not used that SDK, but... :)]
There is a small sample as part of the SDK that works with the car dashboard example. Because of the renaming of Watson Conversation to Watson Assistant it is still using the old object names (both work).
The code uses this namespace:
using IBM.WatsonDeveloperCloud.Assistant.v1.Model
Based on the code itself it checks for the following parts of TokenOptions:
IamApiKey
IamAccessToken
ServiceUrl
My guess is that you have to rename IamUrl to ServiceUrl in your code.
I’m trying to use an embedded browser into my WinForms application. I used CefSharp ChromiumWebBrowser, it work perfectly. However, CEFSharp requires the Visual C++ 2013, or the Visual C++ 2008….I think it is a complicated dependency. I'm creating a portable application without the dependency envirenment.
I have found another library, similar CefSharp, also use Chrominum, called ChromiumFX (visit: https://bitbucket.org/chromiumfx/chromiumfx ). The library uses the .Net Framework 3.5 (Default available in Windows 7) , no need to install Visual C++. And it is suitable for my application.
But I don’t find any way to create multi tabs application with this library. Here is what I tried to do:
private void LifeSpanHandler_OnBeforePopup(object sender, CfxOnBeforePopupEventArgs e)
{
e.SetReturnValue(true);
tabPage2.InvokeOnUiThreadIfRequired(() =>
{
ChromiumWebBrowser b = new ChromiumWebBrowser(e.TargetUrl);
b.Dock = DockStyle.Fill;
tabPage2.Controls.Add(b);
});
}
InvokeOnUiThreadIfRequired is an extension method:
public static void InvokeOnUiThreadIfRequired(this Control control, Action action)
{
if (control.InvokeRequired)
{
control.BeginInvoke(action);
}
else
{
action.Invoke();
}
}
But the application error and the program has crashed.
Another thing, when I created a new instance of ChromiumWebBrowser, I want it isolated with another instance, it means do not use the same cookies, sessions with any instance (private browser). In CefSharp, just create a new RequestContext for new instance:
webbrowser.RequestContext = new RequestContext();
But in ChromiumFX, I dont find any way to do that!
Somebody help me? Thank for you help!
I am trying to build an application to grab syslog from ios device.
I am completely new to C# and have no idea on where to start.
I have found library called Manzana, a C# library to obtain device control of ios device.
My problem is I do not know how to load this library or how the calling conventions are.
Is there anyone kind enough to explain what steps i need to take ?
thanks
First of all, I'd recommend you to use a working iTunesMobileDevice C# API.
There are hundred versions of Manzana that are either out of date or include crap code (Non-working DllImports or obsolete methods).
Do not use Manzana, it's outdated and contains crap-code.
I recommend a powerful MobileDevice-Version: (Chinese comments but clean & working code):
Working iTunesMobileDevice C# API
Once you downloaded the source-files (All .cs files), drag them into your IDE's project. Open your main class and make an instance of iPhone.
You need to create 2 event-handlers, Connect & Disconnect
public static void Main(String[] args)
{
iPhone my_device_instance = new iPhone();
my_device_instance.Connect += new ConnectEventHandler(onConnect);
my_device_instance.Disconnect += new ConnectEventHandler(onDisconnect);
Console.WriteLine("Waiting for device...");
System.Threading.Thread.Sleep(-1)
}
static void onConnect(object sender, ConnectEventArgs e)
{
// Do stuff...
}
static void onDisconnect(object sender, ConnectEventArgs e)
{
// Do stuff...
}
Learn the basics of C# and analyse the given source-code.
One more thing: If you want to grab syslog, you need to make use of the class iPhoneFile.
I'm currently following a tutorial from the MSDN which isn't very clear on somethings the issue that i am having is that the method that they are suggesting that i use is apparently not available to that class
Here is the link to the tutorial : http://msdn.microsoft.com/en-us/library/windows/apps/dn495655.aspx
Here is the code that i am using
In my App.Xaml.cs not my Main page i have an event handler
public App()
{
this.InitializeComponent();
Window.Current.SizeChanged += Current_SizeChanged;
this.Suspending += OnSuspending;
}
Underneath this the stub method
void Current_SizeChanged(object sender, Windows.UI.Core.WindowSizeChangedEventArgs e)
{
// Get the new view state but its not allowing me to use getforcurrent state
// almost like it doesn't exist
string CurrentViewState = ApplicationView.GetForCurrentView().Orientation.ToString();
// Trigger the Visual State Manager
VisualStateManager.GoToState(this, CurrentViewState, true);
}
If anyone else has followed this tutorial can they tell me what is going wrong ?
Have i put the code in the wrong page
Am i missing a library
I am following this microsoft tutorial word for word and it giving me the error which is the title of my post i have done research and i am using the latest version of visual studio and it's still not letting me use this method because it do not exist apparently
Try using Windows.UI.ViewManagement; at the top of the program.
The minimum supported version of this API is Windows 8.1. So you can't use it with the Windows 8 API.
MSDN reference
My windows 8 app is failing the Certification test:
The app should call the Trim API on its IDXGIDevice3 interface anytime it is about to be suspended.
The link takes me to a C++ page, but I'm using SharpDX. I can only find one example of this mentioned on a post in a book here https://www.packtpub.com/article/integrating-direct3d-xaml-windows81#more
Unfortunately it mentioned a DeviceManager class (from the book I think?) and my SharpDX.DXGI.Device3 is missing. There is a Device1 and Device2 but no 3. Perhaps different version of the library or I'm missing a reference to something else?
So I'm looking for an example of how to call Trim so that the Certification app is happy and it cleans up any graphics objects etc on suspending the app.
void App::OnSuspending(
_In_ Platform::Object^ sender,
_In_ Windows::ApplicationModel::SuspendingEventArgs^ args
)
{
Windows::ApplicationModel::SuspendingDeferral^ deferral = args->SuspendingOperation->GetDeferral();
// Save application data
m_exampleDxgiAdapter->Trim();
deferral->Complete();
}
The following example shows how to call Trim() in order to pass the Certification process:
async void OnSuspending(object sender, Windows.ApplicationModel.SuspendingEventArgs e)
{
var Deferral = e.SuspendingOperation.GetDeferral();
using (var Device = new SharpDX.Direct3D11.Device(SharpDX.Direct3D.DriverType.Hardware, SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport, new[] { SharpDX.Direct3D.FeatureLevel.Level_11_1, SharpDX.Direct3D.FeatureLevel.Level_11_0 }))
using (var Direct3DDevice = Device.QueryInterface<SharpDX.Direct3D11.Device1>())
using (var DxgiDevice3 = Direct3DDevice.QueryInterface<SharpDX.DXGI.Device3>())
DxgiDevice3.Trim();
Deferral.Complete();
}
You must download and use SharpDX Latest Dev Package (which is currently 2.5.1) for SharpDX.DXGI.Device3
SharpDX.DXGI.Device3 is available from latest SharpDX dev package (2.5.1) from the DirectX11_2-winrt assemblies.
This DeviceManager is not part of DirectX API but looks like it is part of the sample from the book. You need to retrieve the Device3 device by "COM-querying" the interface on the original DXGI device (something like deviceManager.Device1.QueryInterface<Device3>();)