简体   繁体   中英

Visual Studio Windows Forms Designer Error

I'm working on a .NET Standard class library in Visual Studio 2019 that targets both .NET Standard 2.1 and .NET Framework 4.7.2. I want it to be compatible with WinForms .NET Framework and WPF .NET Core 3.1. One of its dependencies is Entity Framework 6.4—which only works with .NET Standard 2.1 or .NET Framework 4.7.2—so I can't down grade to .NET Standard 2.0 in order to be compatible with .NET Framework. Thus, my class library targets both.

Here's the .NET Standard library's.csproj file:

 <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFrameworks>netstandard2.1;net472</TargetFrameworks> </PropertyGroup> </Project>

In the .NET Standard library, I created a class called “NetStandardClass”. Here's the code:

public class NetStandardClass
{
    private string _member;
    public NetStandardClass(string member)
    {
        _member = member;
    }
}

I've created a WinForms app that targets .NET Framework 4.7.2. and references the .NET Standard library. I created 2 forms: BaseForm that creates an instance of NetStandardClass and Form1 that derives from BaseForm.

Here's BaseForm's code:

public partial class BaseForm : Form
{
    public BaseForm()
    {
        InitializeComponent();

        var netStandardObject = new NetStandardClass("Test");
    }
}

Here's Form1's code:

public partial class Form1 : BaseForm
{
    public Form1()
    {
        InitializeComponent();
    }
}

Everything compiles and runs with no errors. Form1 shows with no errors. I can load BaseForm into the designer with no problems.

However, when I try to load Form1 into the designer, I get the following error:

Could not load file or assembly 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of it's dependencies. The system cannot find the file specified.

What am I doing wrong?

Sean Skelly solved the problem. In order for everything to work, The.csproj file should look like this:

 <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFrameworks>net472;netstandard2.1</TargetFrameworks> </PropertyGroup> </Project>

I also verified that the .NET Standard and .NET Core apps and libraries are compatible with this.csproj file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM