I'm trying to follow UWP with Desktop Extension – Part 2 of UWP and WinForms desktop-bridge calling the processes and passing parameters. This example Console Program.cs code includes parameters string:
string parameters = ApplicationData.Current.LocalSettings.Values["parameters"] as string;
But the name ApplicationData does not exists in the current context, I'm trying to find out, if I've missed some reference or it is different version of C#
I'm not sure even if it is what it requires, but adding of reference Windows.Foundation.UniversalApiContract.windmd throws another error with Values:
Error CS0012 The type 'IPropertySet' is defined in an assembly that is
not referenced. You must add a reference to assembly
'Windows.Foundation.FoundationContract
#Nico Zhu - MSFT is correct, but I would also suggest alternative approach, which may make your life easier in the long run - the UWP APIs for desktop apps are now also distributed via NuGet as a package which takes care of referencing the right libraries for you.
It is in preview at the time of writing, so you can install as follows:
Install-Package Microsoft.Windows.SDK.Contracts -Version 10.0.18362.2002-preview
See the NuGet page for more info.
If you want to use ApplicationData class, please add Windows.winmd where in the C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.17134.0\Windows.winmd. Then add Windows.Storage namespace.
Detail steps
Right click project References -> Add References -> Browse(file type all file)-> select Windows.winmd
Related
I am trying to open a pdf file on the browser, acrobat or any other default pdf program. For this I need to call LaunchFileAsync() and I need to reference Windows.System to be able to use it. However, this is not working and I can't call any reference.
I tried looking for a specific library or nuget package but I couldn't find anything. The documentation just tells me to use that namespace but it doesn't say anything about how to add the reference. I also tried using a different approach by calling System.Diagnostics.Process.Start(path) and some variations but it doesnt't work using Xamarin apparently.
This is basically what I am trying to implement but there's no namespace found event though I did try implementing it.
string uriToLaunch = #"file://" + #file;
var uri = new Uri(uriToLaunch);
var success = await Windows.System.Launcher.LaunchUriAsync(uri);
Any help would be appreciated.
Have you tried adding an assembly reference in the Reference menu?
In the Solution Explorer, right click your project and go to:
Add -> Reference -> Assemblies -> System.*
Also, make sure not to use platform specific libraries for a mobile project, since this will probably cause compatibility issues. .NET Standard is the way to go.
Use Xamarin.Essentials as it defines the various OS dependancies for you and on UWP uses the native Windows.System.Launcher.LaunchUriAsync:
Xamarin.Essentials.Launcher.OpenAsync
re: Xamarin Docs
Note: Opening file://-based URIs is very restricted in UWP.
If you are not targeting .NET Standard yet, make sure you do that if you want to use System libraries. There are some tutorials on this, but i highly suggest you backup your project before changing from PCL to .NET Standard
I can't find the class StoredProfileAWSCredentials. I've got AWSSDK.Core and AWSSDK.APIGateway added via NuGet in Visual Studio 2015 (both are v3). I'm trying to new up an instance of StoredProfileAWSCredentials so that I can specify the credential I'm looking for (as defined in my credentials file). From the docs, this class is in the "Amazon.Runtime" namespace, and I'm doing a "using Amazon.Runtime;". But the compiler keeps telling me that the class doesn't exist.
If I type the fully qualified name to browse the list, starting with Amazon.Runtime and filtering by the word "credentials", I see its parent class, AWSCredentials, but I can't find the actual class, StoredProfileAWSCredentials.
There must be something super obvious that I'm missing here, where does this class exist and what do I need to do to access it?
UPDATE:
I have the following packages added via NuGet:
AWSSDK.APIGateway v3.3.4 and AWSSDK.Core v3.3.7.1.
Its In the Amazon.Runtime.StoredProfileAWSCredentials. The assembly is in ASWSDK.Core.DLL.
I've used it in conjunction with the S3 sdk. That seems to work. Based on what I understand about the docs. Apparently, Core is bundled with other assemblies when ref'd for a specific reason.
Update
After looking at the source I found that it does live in the Core assembly.
https://github.com/aws/aws-sdk-net/blob/5ddd7712e982ef81b3fb5ba446dde834955a679d/sdk/src/Core/Amazon.Runtime/AWSCredentials.cs
Nuget acts weird sometimes. Perhaps you should try uninstalling and re-installing the nuget lib. Also, could you tell me exactly what is the nuget package name and version?
Update
You should not have to install both the core and the APIGateway. Try Just installing the 1 package AWSSDK.APIGateway v3.3.4 and let the dependency management handle the core.
Semi-important Background
I am attempting to change a UWP project to a Windows desktop application so that I can make use of the full .NET Framework 4.5.2. My solution also contains a second project--a Windows Runtime Component--which operates the background tasks. These background tasks write to the ApplicationData so that the primary project with the GUI can use the information. I've made the primary project a Windows application rather than a UWP, but one issue remains:
The Issue
Any reference to ApplicationData.Current.LocalSettings.Values such as
ApplicationData.Current.LocalSettings.Values.Keys.Contains(myDataIndex)
results in the following error:
Error CS0012 The type 'IPropertySet' is defined in an assembly that is not referenced. You must add a reference to assembly
'Windows.Foundation.FoundationContract, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'. ProjectName C:\Users\MyUserName\Documents\Visual Studio 2015\Projects\ProjectName\ProjectName\MainWindow.xaml.cs
So, for some reason, VS is confused on what IPropertySet is.
I've Tried...
Unfortunately, there's nothing starting with Windows.Foundation in the list of namespaces under Assemblies->Framework in the Reference Manager.
Ok, so it's probably already in there somewhere, right...? I'll just try using the required namespace. However, my project cannot find this Windows.Foundation.FoundationContract because my project does not allow
using Windows.Foundation.FoundationContract
though it does find Windows.Foundation.Diagnostics and Windows.Foundation.Metadata.
When I tried this in the original UWP version of the project, it was able to find Metadata, Diagnostics, and Windows.Foundation.Collections. (Curiously enough, the IPropertySet interface my Windows app can't find is actually located in Windows.Foundation.Collections).
This leads me to think that Windows.Foundation.Collections is not available in the .NET Framework used by the Windows app, and only in the UWP .NET Core...? But if that's the case, why does VS still know about ApplicationData.Current.LocalSettings.Values if it couldn't be used? It seems as if I'm missing something else here.
Update
It looks like I just needed to import
C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Windows.winmd
per this answer to fix the reference issues.
(Strangely, I also had to remove a reference to another Windows.winmd file that was at another path. I think that was somehow a result of my attempts to import other things.)
Real Question
Ok, I made it work, but it seems like I'm cheating by importing UWP library stuff. But surely there's a better way?
TL;DR
How am I supposed to use ApplicationData for cross-thread data-sharing in a WPF desktop application without other imports? (And how is it different than a UWP application?
I have an iOS/Android Xamarin project that share a PCL project.
I have added a web reference to the PCL via ASMX as per Xamarin's Tutorial. The tutorial doesn't say how to get to the "Add Web Reference" window, but we found it by right-clicking our PCL project and going to Add->Web Reference.
On adding the web reference I get a roughly 500 line Reference.cs file that is added to the PCL.
However, on compilation, either iOS or Android, I am given several of these errors:
Reference.cs(74,74): Error CS0234: The type or namespace name IExtensibleDataObject' does not exist in the namespaceSystem.Runtime.Serialization'. Are you missing an assembly reference? (CS0234) (MyProject)
It is clear that I need to add the System.Runtime.Serialization assembly reference. However I cannot figure out how to do this and I have spent hours looking for documentation or any relevant solution. Most posts questions appear tangental at best.
This forum post references this issue, but give no solution other than it was supposedly “fixed” three years ago.
Now the aforementioned tutorial references an "Add References…" dialog box for adding the System.Web.Services.dll if you use "Add files" to add the proxy. However, I cannot find this dialog anywhere in the IDE.
I did find "Edit References" when right-clicking on references. This produced a window with these tabs:
Guessing that the assembly needs to be added here I search for it, but find nothing. Apparently there is no way to add assemblies that are packaged with the IDE, you're expected to "just know" where to find them. Searching for documentation proves fruitless.
Via one of the sample project, I was able to locate the .dll file at /Library/Frameworks/Mono.framework/Versions/4.4.2/lib/mono/xbuild-frameworks/.NETPortable/v4.5/Profile/Profile78/System.Runtime.Serialization.dll and manually add it via the .NET Assembly tab.
A colleague tried adding the reference via NuGet as well.
Unfortunately the compile errors remain after attempting either approach.
Also, of note, it appears that the ToDoASMX example project nor the folder containing the System.Runtime.Serialization.dll have any references to the System.Web.Services.dll that the tutorial mentions.
I believe these docs are referring to using them in Xamarin.iOS and Xamarin.Android(At least for the .asmx docs). You can get to System.Runtime.Serializationvia right clicking References in your Xamarin.iOS/ Xamarin.Android project, Going to Edit References, then going to the All tab which it should be listed under the BCL (Base Class LIbrary). You may need to go the route of using an Interface based pattern within your PCL to call the respective native web service instead. You could also try wrapping your .asmx into a REST service and using HttpClient as well.
Seeing this sample project(https://developer.xamarin.com/samples/xamarin-forms/WebServices/TodoASMX/) shows the Interface based pattern described above using ISoapService in the PCL and implementing in the native projects. You will see each project (Droid/iOS) have the Web Reference in them. The PCL is purely invoking the code.
It's more of a limitation of using .asmx given the framework built around them. Using WCF or REST have better options for consuming directly from a PCL. However note that PCLs are going to be replaced by NetStandard library flavor.
I need to add dll files (The XNA Framework) to a C# project and then be able to use them properly. This is so that I can send my solution to another person who doesn't have XNA installed and still have the project compile and run.
I'm trying to do this as part of a test, I need to program a game and then send the code to a person who will mark it. I am allowed to use public libraries but the project must compile without any additional steps on the marker's part.
Any additional information required don't hesitate to ask.
Thanks!
It's a best practice to create a folder solution called "lib" and add all libraries used in your project to that folder. And yes, if you redistribute your solution paths will match.
You can also use NuGet (if you've got VS 2010+). You will need to modify the location for where the 'packages' folder gets stored.
To do this, take a look at this link : Is it possible to change the location of packages for NuGet?
The advantage to this is that you will be told when an update is available for the package.