Windows Forms Designer Crashes Visual Studio, can't find System.ComponentModel.Annotations

Viewed 252

I have a solution structured as such:

MyDataAccessLibrary.csproj (.NET Standard 2.0)
Nuget packages include
Microsoft.EntityFrameworkCore 3.1.3
System.ComponentModel.Annotations 4.7.0

MyApplication.csproj: Windows Forms app (.NET Framework 4.8), uses Package References for dependencies
System.ComponentModel.Annotation 4.7.0

In the Windows Forms application, there is a form (MySuperForm) with a property defined in MyDataAccessLibrary (that type is also an entity type referenced through the DbContext with a DbSet) that serves as a super class to a dozen or so other forms in the project. MySuperForm opens without issue in the forms designer.

The project compiles and runs without problems.

However, attempting to open any of the forms subclassed from MySuperForm gives a designer error:

Could not load File or Assembly System.ComponentModel.Annotations version 4.2.0.0.

Forms Designer Error

And Visual Studio 2019 subsequently crashes and restarts (Version 4.8.03752).

My app.config file contains the following Binding Redirect:

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
        </dependentAssembly>
    </assemblyBinding>

Which is what was generated by using the Auto-generate binding redirect option in the project properties. Note that confusingly, the 4.7.0 version of the Nuget package includes 4.2.1.0 of the actual file, and the dll copied into the bin folder shows version 4.7.26515.06.

I have tried adding the Microsoft.EntityFrameworkCore 3.1.3 package to the application even though no code in that app directly references it (package references bubble up the transitive dependency).

The same version of System.ComponentModel.Annotations is used by all referenced projects in my solution.

I have cleaned, rebuilt, cleared cache, deleted bin and obj folders repeatedly. How can I get these forms to open in the designer?

0 Answers
Related