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>();)
Related
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.
I'm currently trying to implement some speech recognition in one of my c# project, and so I found this library :
https://learn.microsoft.com/en-us/dotnet/api/system.speech.recognition.speechrecognitionengine?view=netframework-4.8
Providing this code as an example :
using System;
using System.Speech.Recognition;
namespace SpeechRecognitionApp
{
class Program
{
static void Main(string[] args)
{
// Create an in-process speech recognizer for the en-US locale.
using (
SpeechRecognitionEngine recognizer =
new SpeechRecognitionEngine(
new System.Globalization.CultureInfo("en-US")))
{
// Create and load a dictation grammar.
recognizer.LoadGrammar(new DictationGrammar());
// Add a handler for the speech recognized event.
recognizer.SpeechRecognized +=
new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);
// Configure input to the speech recognizer.
recognizer.SetInputToDefaultAudioDevice();
// Start asynchronous, continuous speech recognition.
recognizer.RecognizeAsync(RecognizeMode.Multiple);
// Keep the console window open.
while (true)
{
Console.ReadLine();
}
}
}
// Handle the SpeechRecognized event.
static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
Console.WriteLine("Recognized text: " + e.Result.Text);
}
}
}
Which should do exactly what I need.
So I created a new project in Visual Studio, copy-pasted the code, and run it.
There is no compilation error, but the constructor of SpeechRecognitionEngine, taking a non-null CultureInfo object as an argument, throws a System.NullReferenceException in System.Speech.dll.
To try to debug this, I made sure
new System.Globalization.CultureInfo("en-US")
returns a non-null object, and that this culture was installed.
I also updated my framework to 4.8, and run the project both as administrator and normal user.
I'm also using a x64 CPU platform, as the build fails with an ANY CPU platform.
It seems to me like I misconfigured something somewhere, as the code itself shouldn't be wrong.
Do you have any idea how to solve my problem ?
Thank you for your help.
EDIT : this may be linked to this problem, though I don't know if it's of any help :
NullReferenceException when starting recognizer with RecognizeAsync
I had the same error, but found the issue on my end. If you have the same issue as me, it may be that your project is using System.Speech.dll from an older framework, which I believe was causing my error. Or it may have been incompatibility between my target framework the dll?
I used NuGet to add System.Speech by Microsoft to my project. It added System.Speech (6.0.0) to the project references. This removed the null exception I was getting.
For information only, I initially added a reference to v3.0 framework, and that was causing my issue.
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 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