编程语言
首页 > 编程语言> > C# dotnet 提示找不到 CompositionContainer 类的解决方法

C# dotnet 提示找不到 CompositionContainer 类的解决方法

作者:互联网

在构建提示 Error CS0012 和 Error CS0246 说找不到 CompositionContainer 类,原因是没有引用 System.ComponentModel.Composition 库

在构建的时候有如下提示

0>MainWindow.xaml.cs(51,59): Error CS0246: The type or namespace name 'CompositionContainer' could not be found (are you missing a using directive or an assembly reference?)
0>MainWindow.xaml.cs(51,35): Error CS0012: The type 'CompositionContainer' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.ComponentModel.Composition, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

原因是没有引用 System.ComponentModel.Composition 库,双击项目编辑 csproj 项目,添加下面代码

    <ItemGroup>
        <Reference Include="System.ComponentModel.Composition"/>
    </ItemGroup>

要求 csproj 是 sdk 风格的,如果不是,请右击引用,添加引用,找到 System.ComponentModel.Composition 勾选

我搭建了自己的博客 https://blog.lindexi.com/ 欢迎大家访问,里面有很多新的博客。

如果在博客看到有任何不懂的,欢迎交流

标签:assembly,C#,ComponentModel,System,Error,dotnet,Composition,CompositionContainer
来源: https://blog.51cto.com/u_11283245/2956841