You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Linux下Mono编译C#项目报错:找不到ListCollectionView

Fixing "ListCollectionView could not be found" in Mono on Linux

Alright, let's tackle this issue you're facing with compiling your C# project using Mono on Linux. The error about missing ListCollectionView stems from common gaps in WPF-related assembly handling in Mono, and here are the actionable fixes to get your project compiling:

1. Explicitly reference required WPF assemblies

ListCollectionView lives in the PresentationFramework.dll assembly, which isn't included by default in standard Mono compilations. You need to explicitly reference this (and supporting) assemblies when compiling.

When using mcs (Mono's C# compiler), run your compile command like this:

mcs -r:PresentationFramework.dll -r:WindowsBase.dll -r:System.dll SNAPoolLib.cs
  • PresentationFramework.dll: Contains ListCollectionView and other WPF data binding types
  • WindowsBase.dll: Required for CollectionViewSource and core WPF infrastructure
  • System.dll: Covers basic system types (safe to specify even if auto-included by default)

2. Install Mono's WPF components

If you still get assembly-not-found errors after adding references, you likely don't have the Mono WPF packages installed on your Linux system.

For Debian/Ubuntu-based systems:

sudo apt-get install mono-devel mono-wpf

For RPM-based systems (like Fedora):

sudo dnf install mono-devel mono-wpf

This ensures all WPF-related libraries are present on your machine.

3. Switch to a more portable interface (alternative approach)

If you don't rely on ListCollectionView's specific features, consider using the ICollectionView interface instead. This makes your code more cross-platform compatible (works with .NET Framework, .NET Core, and Mono) and avoids tying to a concrete WPF implementation.

Modify your code like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.Windows.Data;

namespace SNAPoolLib
{
    public class ObservableList<T>: ObservableCollection<T>
    {
        ICollectionView _p_view;
        public ICollectionView _View
        {
            get
            {
                if (_p_view == null)
                {
                    // No casting needed - GetDefaultView returns ICollectionView directly
                    _p_view = CollectionViewSource.GetDefaultView(this);
                }
                return _p_view;
            }
        }

        public ObservableList() : base() { }
        public ObservableList(IEnumerable<T> items) : base(items) { }
    }
}

This change preserves all core collection view functionality (filtering, sorting, etc.) while improving portability.

4. Update to a recent Mono version

Older Mono releases had incomplete WPF support. If you're running an outdated version, upgrade to the latest stable release (6.x or newer) to ensure better compatibility with WPF types.


内容的提问来源于stack exchange,提问作者user5728072

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:39:24