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.

Eric Bole-Feysot
  • 13,949
  • 7
  • 47
  • 53
  • 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? – ALFA Oct 09 '19 at 06:19
  • No, and if I use the full path 'System.ComponentModel.', I get no ICollectionView class available in the list. – Eric Bole-Feysot Oct 09 '19 at 06:27

3 Answers3

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.

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.

ALFA
  • 1,726
  • 1
  • 10
  • 19
  • Any idea why componentModel doesn't have the ICollecionView interface ? – Eric Bole-Feysot Oct 09 '19 at 07:43
  • Microsoft.Windows.SDK.Contracts is not widely used. I'm asking if this is the right package to include... – Eric Bole-Feysot Oct 09 '19 at 07:44
  • 1
    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. – ALFA Oct 09 '19 at 07:51
  • Yes, thanks, I found it. I saw there is a package windows.runtime.windowsruntime.ui.xaml, but it doesn't have the ICollectionView interface. – Eric Bole-Feysot Oct 09 '19 at 07:57
  • 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. – ALFA Oct 09 '19 at 08:00
  • The ui.xaml icollectionview doesn't have the 'Filter' property, and I can't find any replacement... – Eric Bole-Feysot Oct 09 '19 at 08:22
  • Well that's unlucky, I cannot find any other solutions. Let me know if you find some, I'll try to search a bit more deeply. – ALFA Oct 10 '19 at 10:56
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

Ahmed Msaouri
  • 316
  • 1
  • 10
  • 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 ? – Eric Bole-Feysot Oct 09 '19 at 14:32
  • 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 https://stackoverflow.com/questions/37866997/referencing-standard-dlls-from-a-net-core-xunit-project/37867569#37867569 Add .NETFramework 4.5 dll to .NETCore project https://stackoverflow.com/questions/38731567/add-netframework-4-5-dll-to-netcore-project – Ahmed Msaouri Oct 09 '19 at 14:52
  • This project also helps to migrate classic .Net code to .Net Core https://github.com/hvanbakel/CsprojToVs2017 – Ahmed Msaouri Oct 09 '19 at 14:55
  • 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. – Eric Bole-Feysot Oct 09 '19 at 15:07