'Application' doesn't exist in System.Windows namespace (in library project) - .net-standard-2.0

I'm working on .net standard 2.0 library project for my solution.
It have to include this method:
public Task ShutdownAsync()
{
Application.Current.Shutdown();
}
Problem is it gives me an error:
The name 'Application' does not exist in the current context
It also doesn't exist in System.Windows.
As answers to similar questions suggests I tried to add reference to PresentationFramework. But it isn't on the list.
Looks like it have something to do with the fact I'm doing it in a library project targeted at .net standard 2.0.
Is here any way to add proper reference to this project?

.Net standard 2.0 was the problem.
This class is platform-specific so I should target .Net Platform instead.

Related

Library class doesn't know of ConfigureWebHostDefaults extension method

I'm building a suite of REST micro-services using .Net Core 3.0 Preview 6. All these services will have the same start up logic. So, I'm trying to place all the code in a .Net Standard library.
The goal is to have the IHostBuilder:CreateHostBuilder method, as well as the Startup:Configure and Startup:ConfigureServices class and methods in the library. The library will also contain error handling logic, customized http response messages, etc.
However, I can't seem to find the correct package that contains the ConfigureWebHostDefaults method. I tried adding the Microsoft.AspNetCore package 2.2.0, but that didn't resolve the issue.
I added the Microsoft.Extensions.Hosting (3.0.0-preview-6) package, that also doesn't resolve the issue.
Is what I'm attempting even possible?
Thanks
-marc
I resolved it, not the best way, but it works. I decided to make the library targeted specifically for .NET Core 3.0. So, I changed the targetframework in the project file. That change automatically resolved my other issue.
Import the Microsoft.AspNetCore package, and use WebHost.CreateDefaultBuilder() instead. According to the code it is built from, both CreateDefaultBuilder() and ConfigureWebHostDefaults() call the same internal method: ConfigureWebDefaults().
The only downside of this is that the returned host will be an IWebHost instead of an IHost.

MvvmCross 4 support for UWP, AppShell missing Frame

I have created a new solution for my MvvmCross app that supported Windows Store and I want to support UWP on Windows 10. I have moved over the PCL successfully, but I am having problems getting the basic UWP app working using a sample provided by MS (NavigationMenu) which uses the SplitView and the AppShell pattern they are recommending for the new navigation/command model. I referenced a helpful blog post (http://stephanvs.com/implementing-a-multi-region-presenter-for-windows-10-uwp-and-mvvmcross/), which gave me some guidance on how to integrate mvvmcross into the AppShell, but startup is failing because the AppShell does not have a valid Frame defined. Frame is a read-only property, and I have been unable to see where this is being set up.
I am using the standard AppShell implementation from the NavigationMenu with the following changes as recommended in the blog post:
public sealed partial class AppShell : MvxWindowsPage // was Page
public Frame AppFrame { get { return this.Frame; } } // was this.frame
Except for code after the error, there are no differences in the setup. In looking at the MvxWindowsPage implementation, there doesn't seem to be anything special as it still invokes the Page initialization. Is there something obvious I am missing?
So the link to the blogpost is correct, in other words you'll need to use MultiRegions from MvvmCross to get this working.
But what the blogpost doesn't show is a complete working version...
I've added one on my github here:
https://github.com/Depechie/MvvmCrossUWPSplitView
Some pointers to take away, like I said in the comments.
Your view where the SplitView will be present, needs to have a property to return a valid Frame to look for while injecting new views. This can be returned like this return (Frame)this.WrappedFrame.UnderlyingControl; found in the code here https://github.com/Depechie/MvvmCrossUWPSplitView/blob/master/MvvmCrossUWP.Win/Views/FirstView.xaml.cs#L13
Than all views you want to load up in the SplitView will need to reference to the region you defined in that SplitView, in my case I named it FrameContent as seen here https://github.com/Depechie/MvvmCrossUWPSplitView/blob/master/MvvmCrossUWP.Win/Views/FirstView.xaml#L48
So use that name for the region attribute in all to be loaded views like so [MvxRegion("FrameContent")] example here https://github.com/Depechie/MvvmCrossUWPSplitView/blob/master/MvvmCrossUWP.Win/Views/SecondView.xaml.cs#L7
I see what you're trying to do with the SplitView template that's provided by Microsoft. There is however a mismatch between things managed by MvvmCross and UWP.
By default MvvmCross maps ViewModels to Views based on naming conventions. What you are trying to do is use a view 'AppShell' (which is derived of Windows.UI.Xaml.Controls.Page) that doesn't adhere to the default MvvmCross convention.
The way I choose to implement this SplitView (Hamburger) functionality is by deleting the provided AppShell class entirely. I then created a new view named HomeView (since I have a ViewModel with the name HomeViewModel) and added the SplitView control there as described in the post you mentioned above.
For completeness I've created a Gist with the App.xaml.cs and HomeView.xaml as you requested. You can find them here: https://gist.github.com/Stephanvs/7bb2cdc9dbf15cb7a90f

getWindowHandle function doesn't exist for driver in Selenium

I need to implement switch from one window to another in IE. However, element driver doesn't support getWindowHandle function.
I assume it might be just configuration problem or settings, though I don't know how to fix it.
Please, any suggestions.
I'm working with c# - Visual Studio
You haven't said which language bindings you're using, but based on a comment you posted, it looks like you're using C#. The method names are slightly different for each language binding. From this answer:
The object, method, and property names in the .NET language bindings
do not exactly correspond to those in the Java bindings. One of the
principles of the project is that each language binding should "feel
natural" to those comfortable coding in that language.
So you have to do a little translation if you're trying to copy-paste Java code. In this case, you want the combination of the WindowHandles property (to look for the new window handle) and the CurrentWindowHandle property of the driver. You can find full API documentation for the .NET bindings at the project's Google code site.
I am going to make wild guess:
Try to initialize your driver like this:
WebDriver driver = new FirefoxDriver(); //assume you use firefox
The interface WebDriver supports that method. Do not forget to store the handle somewhere ;)
String myWindow = driver.getWindowHandle();
BTW that method should return you actual window If you need all windows you probably should use getWindowHandles() method
If this does not work, please provide more info:
what error exactly are you getting?
How do you initialize WebDriver?
What version of selenium are you using?|
What type of driver are you using?

Json does not exist in the namespace System

In this tutorial: http://www.asp.net/web-api/videos/getting-started/custom-validation Jon uses
dynamic error = new JsonObject();
with
using System.Json;
I guess it's the JsonObject here: http://msdn.microsoft.com/en-us/library/system.json.jsonobject(v=vs.110).aspx located in:
Namespace: System.Json
Assembly: System.Runtime.Serialization (in System.Runtime.Serialization.dll)
I've added System.Runtime.Serialization a reference but still cannot find System.Json.
Am I reading the Microsoft docs wrong? (I'm using .NET 4.5)
Try this:
PM> Install-Package System.Json -Version 4.0.20126.16343
Per: http://nuget.org/packages/System.Json
It worked!
If you have questions on how to add enter nuget code, please follow the link below:
http://docs.nuget.org/docs/start-here/using-the-package-manager-console
http://www.webcosmoforums.com/asp/32551-type-namespace-name-json-does-not-exist-namespace-system-runtime-serialization.html
Most likely you are missing a reference to System.ServiceModel.Web
Make sure your application is targeting the .Net 4.5 framework in the project properties.
The System.Json objects are only available in 4.5
Edit:
Use Nuget to install system.json : 'Install-Package System.Json'
How to parse JSON without JSON.NET library?
The Json object works only from Controller class and not outside. Even if we refer System.Web.MVC outside controller, we have access only to JsonResult and not to Json as Json object is protected object of JsonResult. Please refer the below documentation which explains that,
http://msdn.microsoft.com/en-us/library/dd504936(v=vs.118).aspx
If you want to use other .Net json serializer, you can use the following:
go to manage nuget package.
search json.net.
click install.
for more details, follow - http://netfx.codeplex.com/
Using System.json will not work for .Net 4 framework. The library is deprecated.
To check it try:
Go Add reference... to project.
On .Net Tab, Search System.json, you will not find any.
That means, it is deprecated.

Windsor Fluent Registration - All types in an assembly

I wanted to use the fluent interface in Castle Windsor. Since this isn't available in the "release" binaries for .NET 2.0 I compiled from trunk, which is reported to be fairly stable. I compiled just:
Castle.Core.dll
Castle.DynamicProxy.dll
Castle.MicroKernel.dll
Castle.Windsor.dll
This should be all that is necessary for what I need it for but things aren't working as expected. I have an assembly collection which I iterate through and attempt to load all types contained within each assembly using the following code:
var container= new WindsorContainer();
foreach (var assembly in _assemblies)
{
container.Register(AllTypes.FromAssembly(assembly));
}
I stepped through the code with a debugger. _assemblies has 2 assemblies in it. Each assembly has numerous types defined in it. The loop iterates twice without error but when it completes container is still empty.
Update:
A little clarification. The latest binaries do have the fluent interface, however they target the .NET 3.5 framework. I am working with .NET 2.0. The latest binary release to support .NET 2.0 was RC3.
The Register(AllTypes... syntax is only the start - you have to tell Windsor what it is that you want to register.
For example to get all Controllers:
container.Register(AllTypes
.FromAssemblyContaining(representativeControllerType)
.BasedOn<Controller>()
.Configure(reg => reg
.LifeStyle.PerWebRequest));
Here's another example that registers by following the convention that all classes whose name ends in 'Service' should be registered:
container.Register(AllTypes
.FromAssemblyContaining<ConfigurationService>()
.Where(t => t.Name.EndsWith("Service", StringComparison.Ordinal))
.WithService.FirstInterface()
.Configure(reg => reg.LifeStyle.PerWebRequest));
If you truly want to register all types, you could write a Where clause that always returns true.
By default, Windsor doesn't auto-resolve concrete types.
For more information about fluent registration API read the documentation.