Is there any equivalent to System.ComponentModel.Composition library in .Net Standard? - .net-standard-2.0

.Net has System.ComponentModle.Composition.dll for MEF. Is there any equivalent library present in .Net Standard?

With .net standard 2.0 you need to use this nuget package:
This namespace provides classes that constitute the core of the
Managed Extensibility Framework, or MEF.
Commonly Used Types:
System.ComponentModel.Composition.CompositionContractMismatchException
System.ComponentModel.Composition.CompositionError
System.ComponentModel.Composition.CompositionException
System.ComponentModel.Composition.ExportAttribute
System.ComponentModel.Composition.ImportAttribute
System.ComponentModel.Composition.ImportCardinalityMismatchException
System.ComponentModel.Composition.Hosting.AggregateCatalog
System.ComponentModel.Composition.Hosting.ApplicationCatalog
System.ComponentModel.Composition.Hosting.AssemblyCatalog
System.ComponentModel.Composition.Hosting.CompositionContainer
System.ComponentModel.Composition.Primitives.ComposablePartException
System.ComponentModel.Composition.Primitives.ExportDefinition
System.ComponentModel.Composition.Primitives.ImportDefinition
System.ComponentModel.Composition.ReflectionModel.ReflectionModelServices

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

Reference library targeting .NET Standard from a Windows Store app or Profile7 PCL?

The doc page says a library targeting .NET Standard can reference a "profile-based PCL". But what about the reverse? Can a Profile 7 PCL reference a library targeting .NET Standard (any version)?
Also, can a Windows Store (Windows 8.1) app reference a library that only targets .NET Standard?
Can a Profile 7 PCL reference a library targeting .NET Standard (any
version)?
You may refer to this article written by #Adam Pedly Microsoft MVP (Xamarin):
" Remember that once you have a .NET Standard Library a Profile Based PCL can’t reference it, hence you need to convert everything up the chain to .NET Standard."
Update:
Check the doc, see the complete set of .NET runtimes that support the .NET Standard Library. So if you want to reference it in Windows 8.1 project, you can target .NET Standard 1.2, which provides less functions than .NET Standard 1.6 version(e.g. no System.Net.Sockets).

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

JSON for .NET Framework 1.1

I can see that JSON used a lot for .NET 2.0 and higher.
Is there a JSON library I can use for .NET Framework v1.1 ?
There have been a few attempts to bring JSON to .NET 1.1. Given such an old Framework version you are on, most of those attempts have been abandoned by people moving on with the next version of the .NET Framework (which I encourage you to do).
Barring that, you could try JSON Object Serializer. I'm sure it isn't perfect, but it is open source - allowing you to make contributions and bug fixes for it yourself.