Creating a typed configuration class using MS Enterprise Library 5.0 - configuration

I have a ASP.Net 4.0 web application for which I need to create typed configuration class. What I mean is as follows:
class SettingsClass
{
int count;
string name;
decimal amount;
}
Should map to the configuration file as:
<MyAppSettings>
<xmlSerializationSection type="...">
<SettingsClass>
<count>2<count>
<name>Moiz</name>
<decimal>10.66</decimal>
</SettingsClass>
</xmlSerializationSection>
</MyAppSettings>
The configuration file was identified in the web.config as follows by a configuration section (Read ColorSettings as MyAppSettings)
This was straight forward in ASP.Net 2.0 and Enterprise library 1.0
I am trying to achieve the same thing in ASP.Net 4.0 and Enterprise Library 5.0. However, the Enterprise Library Console of 5.0 does not work the same way as the Enterprise Library Configuration tool of 1.0.
I wanted to know how I should be going about in .Net 4.0 and Ent Lib 5.0 to achieve this same requirement. Is there a better means by which configuration can be handled for typed class in .Net 4.0/ent lib 5.0?

XML configuration changed radically (and not really for the better) in .NET 2.0. You're going to want to look at the System.Configuration namespace and the classes there. This is no longer an enterprise library question, but really one about the framework itself.

Related

Using Avalonia with netstandard

I try to run my Avalonia app on .net framework. However, when I downgrade targetframework to netstandard2.0, AppBuilder becomes unavailable and I just couldn't figure out, how to fix that problem.
I couldn't find any template, that targets .net framework or netstandard. Documentation contains nothing regarding this issue. The only thing I could find is this Github issue. As I understood, AppBuilder is not supposed to be used in netstandard. Then, what is proper replacement for following code?
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToTrace()
.UseReactiveUI();
Edit:
As it was pointed out, netstandard can't be used as a target for Avalonia apps, but we can specify multiple targets. So I replaced
<TargetFramework>net7.0</TargetFramework>
with
<TargetFrameworks>net7.0;net48</TargetFrameworks>
And it worked on .NET core and .NET Framework
netstandard2.0 isn't an actual .NET framework version: it's a specification of the common API beteen .NET framework 4.6.1 and .NET core 2.0 (among others). As such netstandard2.0 only makes sense as the target framework for libraries, not applications.
If you want your app to target .NET framework then you need to use a .NET framework version as the target framework, for example net48 for .NET Framework 4.8.

How to reference .net framework 4.8 nuget package from .net standard 2.0 class library?

I'm trying to use .net framework 4.8 nuget package (which was written by our team) in my .net standard 2.0 class library.
But when I build the solution I see such kind of warning:
Warning NU1701
Package ... was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
At the same time here it is claimed that .net standard and .net framework 4.8 are compatible.
Why do I see this warning? What am I doing wrong?
Is there way to get rid of this warning?
They're compatible in the sense that you can reference netstandard projects from net48 projects, but not the other way round.
The only thing you can reference from a netstandard project is another netstandard project

Entity Framework with IoT Background Application

Visual Studio provides a "Background Application (IoT)" template which i want to use to create a headless webservice. To persist some data i want to use Entity Framework with SQLite as DB-Engine .
After upgrading UWP to 5.2.2 and installing Sqlite and EFCore.Tools and adding a DbContext i wanted to migrate the first version. It fails:
PM> Add-Migration MyFirstMigration
Project 'BackgroundApplication4' is a Windows Runtime component. The Entity Framework Core Package Manager Console Tools don't support this type of project.
I thinks it's not a problem with EF itself, because it worked for me with a simple "Blank App". Now there are some questions coming up: Is a "Background Application" really a WinRT-Component and has a different (unsupported) handling by EF?
I thought UWP is an extension of WinRT so basically each UWP-App must be a WinRT-Component?
EF in a Windows Runtime component is a no-go; but that is not so bad since WinRT component can depend on class libraries. So move all your EF classes to a own class libary and consume that library from your background task in your Windows Runtime component.
By doing this you can also use the same class library also in the foreground app when needed.
P.s. Check the github page of EFCore and UWP. There are lot of issues especially in combination with .net native. so using EF.core in UWP will cause you lot of headache; but it is possible.

Xml serialization/deserialization in WinRT (Store application)

I need to make a Windows Store application that exchanges xml serialized data over a TCP connection with a server. Since I need to use Direct3D rendering in the application I went for the c++/cx store application template however I ran into issues with xml serialization/deserialization.
My usual approach in C# would be to use the XmlSerializer and classes with DataContractAttribute annotations. However as soon as I try to import System.Xml.Serialization assembly I get the C1114 error - WinRT does not support #using of a managed assembly. However there are lots of examples that mention using this approach in a Windows Phone app from C#.
So the question is - is only c++/cx limited in support for .NET in Windows Store applications and C# can use all the standard components on phone as well or is switching to C# in this case also not a solution and I need to use the WinRT classes for xml serialization/deserialization?
Your confusion is understandable, what with the variety of frameworks Microsoft has put out there.
C++/Cx is a native binding to the Windows Runtime (WinRT). It does not use any managed code or the .NET framework in any way, which is why you're getting the C1114 error.
C# provides a managed binding to WinRT. It does leverage the .NET framework, so in a C# Windows Store application, you can make use of some of the base-class library. This subset is referred to as the .NET Profile. This article talks about this more: http://blogs.msdn.com/b/dotnet/archive/2012/04/17/net-for-metro-style-apps.aspx
In your specific case, you are using a C++/Cx application because you want access to Direct3D. This makes sense, although it means that you will not have access to System.Xml.Serialization. Instead, as you surmised, you will need to use APIs that are available to C++/Cx to read XML, specifically Windows.Data.Xml.Dom: https://msdn.microsoft.com/en-us/library/windows/apps/windows.data.xml.dom.aspx

How targeting .NET 4.0 with Mvvmcross?

I want to use Mvvmcross to make application for several platforms.
I use Profile 104 for PCL library like Mvvmcross, but this profile target .NET 4.5.
I want to target .NET 4.0 to use my application on Windows XP.
To do that, I add the xml files
MonoAndroid, Version = v1.6 +. Xml
and
VSMonoTouch, Version = v1.0 +. Xml
in the profile 143 which allows me to target. NET framework 4.0.3.
However, I have a compilation error because it can not find the ICommand interface.
This interface is not in the same library between version 4.0 and 4.5, is it why it doesn't work ?
Or should I recompile all Mvvmcross libraries with profile 143?
thanks,
This is a Portable Class Library limitation.
See the table on: http://msdn.microsoft.com/en-us/library/gg597391.aspx
Model-View-View Model (MVVM)
Only 4.5
This means that if anyone wants to use MvvmCross on earlier .Net platforms then someone has to build and maintain a non-PCL version.
Since the maintainer of Mvx (me!) has decided to only maintain PCL versions of MvvmCross, then any non-PCL support will have to be created by the community.
For WPF this shouldn't be too large or difficult a job - but it might be...
Alternatively, somebody might be able to do something funky to get the ICommand working... I've retagged this question with portable-class-library to try to lure in some of the MS experts.