0

I'm migrating my project from classic .net to .net core 3.0. I use in my viewmodel ICollectionView interface and it is not recognized in .net core 3.0 framework.

I added several nuget packages to attempt to make it work, but with no luck.

Microsoft claims System.ComponentModel defines icollectionview (https://learn.microsoft.com/en-us/dotnet/api/system.componentmodel.icollectionview?view=netcore-3.0), but it is not found. I also tried to include windowsbase, but it's not found either.

Is my environment faulty ? Did I miss something ?

Thanks for your help.

Here is a small class to compile under a .netcore3 project:

class Program { static void Main(string[] args) { Console.WriteLine("Hello World!"); ICollectionView col =new CollectionViewSource().View; col.Filter = null; col.Refresh(); } } 

Edit:

Thanks to ALFA for Microsoft.Windows.SDK.Contracts which offer an ICollectionView interface on .net core, but unfortunatly, it is not complete: Filter and refresh are not implemented.

2
  • If you create a brand new project on .NET Core 3.0 and you add System.ComponentModel as a reference, will you see the interface? Commented Oct 9, 2019 at 6:19
  • No, and if I use the full path 'System.ComponentModel.', I get no ICollectionView class available in the list. Commented Oct 9, 2019 at 6:27

3 Answers 3

3

You need to edit your project file YourProjectName.csproj from this:

<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netcoreapp3.0</TargetFramework> </PropertyGroup> 

To this:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop"> <PropertyGroup> <TargetFramework>netcoreapp3.0</TargetFramework> <UseWPF>true</UseWPF> </PropertyGroup> 

It helps to me.

Sign up to request clarification or add additional context in comments.

2 Comments

Bingo ! It works ! Thank you for sharing this tip !
That doesn't work for .netcore3.1. <UseWPF>true</UseWPF> only. <Project Sdk="Microsoft.NET.Sdk.WindowsDesktop"> creates issues. just leave it as it was <Project Sdk="Microsoft.NET.Sdk">
0

On .NET Core 3.0+ you can install the Microsoft.Windows.SDK.Contracts package which includes all the supported Windows Runtime APIs up to Windows 10 version 1903, and will let you use ICollectionView.

The Windows 10 WinRT API Pack enables you to add the latest Windows Runtime APIs support to your .NET Framework 4.5+ and .NET Core 3.0+ libraries and apps.

7 Comments

Any idea why componentModel doesn't have the ICollecionView interface ?
Microsoft.Windows.SDK.Contracts is not widely used. I'm asking if this is the right package to include...
Check out under Windows.UI.Xaml.Data.ICollectionView once you installed the package. Also I think WindowsBase.dll includes windows-specific libraries, so it should not allow you to reference it anyway.
Yes, thanks, I found it. I saw there is a package windows.runtime.windowsruntime.ui.xaml, but it doesn't have the ICollectionView interface.
Yup you're right. I think on .NET Core 3.0 this package is the way to go to get access to those libraries. Hope this ICollectionView fits your needs since, as you said, this package isn't widely used yet and it has been on preview for a long time.
|
0

have tried importing the DLL into your .Core project ?

 https://learn.microsoft.com/es-es/dotnet/api/system.windows.data.collectionview?view=netframework-4.8 

You can find the PresentationFramework.dll DLL in the .Net folder,In my case I have it in

 C:\Windows\Microsoft.NET\Framework\v4.0.30319\WPF 

4 Comments

Vs let me import this dll, but it does nothing and ICollectionView is still unknown. Tried also the PresentationFramework-SystemCore.dll. Maybe because it is not a .net core lib ?
principally .Net Core > 2 supports a direct reference to external .dll, may have problems with DLLs that have dependencies on 32-bit DLLs ?. other posts that can help you: Referencing standard dlls from a .NET Core XUnit project stackoverflow.com/questions/37866997/… Add .NETFramework 4.5 dll to .NETCore project stackoverflow.com/questions/38731567/…
This project also helps to migrate classic .Net code to .Net Core github.com/hvanbakel/CsprojToVs2017
These questions seems utdated, as they use json csproj. I'm on vs2019 and I get xml csproj. I tried multitargets projects, but can't make it work either.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.