In the .Net Framework there is an event that, when handled, you could log was lock/unlock events on an account. It is this one:
Microsoft.Win32.SystemEvents.SessionSwitch
I can't find this in .Net core. Does anyone know what the equivalent in .Net Core is?
As this event is platform specific, it probably wouldn't the part of .Net Standard, so you can't find it in .Net Core. According the APIs of .Net, they do not have plans for introducing this class.
So, you may try to create a platform-specific library with SessionSwitch code, but that wouldn't run on other platforms rather than Windows, and put your general logic into .Net Standard library so you can use that either from .Net Core app and .Net Framework app.
Other way is to use Mono, which contain such events in it.
Related
How come visual studio allow me to create a new .net standard project on Linux platform?
Isn't Linux is only in .net core?
Thanks
It seems to be some confusion about the differences between .NET Core and .NET Standard. It's true that only .NET Core runs on Linux (and not the normal .NET Framework), but .NET Standard means a different thing.
It only dictates the base standard library for any .NET implementation, not a specific one. As .NET Core complies with .NET Standard, this is the runtime that'll run your code on Linux, and that's because the option appears there.
In more programmers words, consider .NET Standard an interface, while .NET Core being the concrete implementation for it. The interface knows nothing about the implementation, hence it's platform-agnostic.
We currently have a web api targeting .NET 4 framework which is hosted within IIS using an application pool which is using .NET 4 CLR.
We are investigating migrating the web api from .NET 4 to .NET Core 2.1 (for performance improvements). The web api has other DLL references which have been built using .NET 4 framework. I have a simple proof of concept up and running using .NET Core 2.1 and the references which had been built using .NET 4 framework appear to have imported fine as I can reference them and the project builds.
If I have the new .NET Core 2.1 web api referencing the 3rd party DLLs using .NET framework 4 which is then going to be hosted in IIS using the CLR 4... how would we see any performance increase? If everything is being run using the CLR 4, is that not the bottleneck for performance? Or is it the binaries that the CLR reads being more performant where you will see better performance?
Any guidance would be greatly appreciated as I'm very confused at the moment!
Thanks
It depends on how you're handling things. .NET Core 2.0+ fully supports .NET Standard 2.0, which has an API footprint large enough to cover most .NET Framework functionality. As a result, the compiler will let you add a .NET Framework library reference to a project that's actually targeting .NET Core 2.0+. There's no guarantee that the library will actually work (and you get a warning to that effect), but unless it's using Windows-specific APIs, there's a very good chance it will function fine.
Assuming this is the case with your .NET Framework libraries and you're actually targeting something like .NET Core 2.1, then you are not in fact using .NET Framework, and you don't even need .NET Framework installed on the server you're deploying to. All the requisite framework dependencies will come from the .NET Core runtime, or can even be packaged along with your app if you opt for a self-contained deployment. In that case, once compiled, it's virtually inconsequential that the libraries you referenced actually targeted .NET Framework.
If however the libraries do not work without full .NET Framework, you can still build a .NET Core app, but you'll be forced to continue to target .NET Framework, rather than .NET Core. In that case, you will of course be reliant on the .NET Framework CLR, with the performance drain that entails. That said, an ASP.NET Core app, for example, is still generally more performant than something like an ASP.NET MVC app, so you will get some gains - just not as much as if you were actually targeting .NET Core.
Regardless of what you ultimately end up targeting, your app is actually served via Kestrel. IIS acts merely as a reverse proxy.
I make a UWP program and I have to get data from a Oracle database of my customer. My customer gave me a dll which he made. I tried and found that made by .net framework of 4.6.2 so that UWP do not support it. I suggested him rewrite the dll by UWP, but he refused that. So I have to find a way to make it works in UWP.
I googled and found that if I make a .net standard dll for the bridge between UWP and .net framework that I can make it works in UWP.
Finally, I made a .net standard dll, in the .net standard I reference the dll my customer gave.
But after I debugged my .net standard dll, all code I wrote works without error, but the dll my customer gave threw an error:
"The type initializer for 'OracleInternal.Common.ProviderConfig' threw an exception."
I wonder if there is something wrong with the dll of my customer. However,it is so strange that if I reference his dll in winform, all is OK, but only in .net standard it crashed. What's more, the code what I wrote in winform/.net standard is the same, only declare a class and run a void, just two-line code.
My customer knows nothing about UWP and I also know nothing about Oracle.I don't want rewrite whole project by WPF just for this, that's such a huge work!
Would you please teach me what's wrong with that and how to solve my problem. Thank you.
I wonder if there is something wrong with the dll of my customer.
In short, there's no wrong in your customer's .net framework dll. You just misunderstood the .NET Standard. Your .NET Standard library worked in winform, that's because your .NET Standard library adds reference to your customer's .net framework dll. This .net framewrok dll works well in .net framework applications, but it doesn't mean that the APIs in the .net framework dll are supported in UWP, even if you've used your .NET Standard library to wrap it. I suggested that you could read Introducing .NET Standard for more detailed information.
For your question, if your customer does not want to rewrite their dll and you're also not able to write a library to make it work in UWP. You could make a WCF. In WCF, you could directly add reference to your customer's dll. Then, you could use this WCF service in your UWP directly.
I have a Xamarin Forms application that uses shared code. It has three projects, shared, iOS and Android. These are very similar to those which are created when I create a sample application from the Xamarin new project menu.
I am looking to have the application updated and published by a company that has experience in doing this but I am not sure I understand a couple of the work items that have been suggested to me:
Currently, architecture is PCL which is becoming
obsolete.
Move to .NET standards
Could someone explain to me what these work items might mean?
Yes, it will become obsolete at some point. .NET Standard is the evolvement of the PCL libraries.
With PCL libraries you could target a number of platforms and only the functionality that was supported for all targeted platforms were available to you. Associated with each combination of platforms were the profiles. A profile was identified by two or three digits. Notable ones for Xamarin were 111 or 259. Read more on PCLs here: https://learn.microsoft.com/en-us/xamarin/cross-platform/app-fundamentals/pcl
.NET Standard is a specification of the APIs associated to it. If a platform supports a certain version of the .NET Standard, you are guaranteed that all APIs are available. This way, you can simply target a specific .NET Standard version and each platform that supports it will support your application. The .NET Standard specification has gained a lot of traction and is already more cross-platform than a PCL ever was. Most of the creators of NuGet packages are supporting it already and also Xamarin/Microsoft has replaced the PCL with a .NET Standard library in their templates. Read more on .NET Standard as a concept here: https://learn.microsoft.com/en-us/dotnet/standard/net-standard
So, if you have the possibility it might be wise to start moving to the .NET Standard library. That is, if you want to keep supporting your app and need new libraries coming in. If your app is fine the way it is, you can probably keep going with the PCL for a while. Converting is basically: change the csproj structure to the new structure. Retarget your library to netstandard and reinstall all the libraries you have installed, this time to download the .NET Standard compatible version. The last step might be a bit of a pain.
A good resource on converting might be this by Adam Pedley: https://xamarinhelp.com/upgrade-pcl-net-standard-class-library/
There is also a solution to do it automatically: https://smellyc0de.wordpress.com/2018/03/23/automatically-converting-pcl-to-net-standard-2-0-project/
.Net Standard is a specification for a set of APIs. and is the way things are going. With it, comes a higher level of range of .Net SDK APIs you can use, plus most 3rd party Nuget packages will support it. They can support a wider range of platforms. by targeting .Net Standard. Thus you will get access to a larger number of nuget packages. See https://learn.microsoft.com/en-us/dotnet/standard/net-standard
I put my Forms Apps into a .Net Standard library, because it easier to unit test. There is a Xamarin Forms nuget package you can use for testing, which means a lot of UI paths can be verified in code, where previously you had to do it on a device, perhaps with automated testing. https://github.com/jonathanpeppers/Xamarin.Forms.Mocks
Upgrading an existing PCL project to .net standard is a pain. Any more, I just create a new Xamarin Forms solution with the same name/root namespace, with the app as .Net Standard, then copy files over.
I've created a Cross platform Application for Xamarin in Visual Studio. The application is running on .NET Standard 2.0 and it's not possible to select a higher version.
Isn't possible to run a Xamarin project on a newer .NET version? The problem is that a want to install nuget packages that requires at least .NET 4.5.
Thanks in advance.
You are confusing .net and .net standard. .net standard gathers many other .net platform (for example .net core, uwp, windows phone etc...) including the classical .net (from 4.5 to 4.6.1). Take a look at this table to have a better understanding.
This means that you should be able to include your library that targets .net 4.5.
Now that you know that, you can define a fallback version if the library does not target .net standard. To do so add this line in your .net standard .csproj in the PropertyGroup node
<PackageTargetFallback>$(PackageTargetFallback);portable-win+net45+wp8+win81+wpa8</PackageTargetFallback>
.NET Standard is a standard, official documentation is nicely covering it. Beside that must read, here is a compatibility table.
So please, read the official documentation. Setup your mind and come back with a proper question. Currently it does not make sense.
Good luck!
P.S.: Currently you are trying to use an outdated library that does not support .NET Standard, you might want to look for alternatives.