Visual Studio 2019 Designer errors

Georgius 25 Reputation points
2024-12-01T08:40:05.94+00:00

Hello,

In Visual Studio 2019 I have big solution with lots of forms and controls, when open one of the WinForm Designer, it is shown with errors, about 5-10 items.

Looks something is related to design time calls in code and if some object is not created in constructors or some reference not exists in current context, then showing of designer controls fails.

It does not make sense to go through lots of code and make changes for design-time calls,

So, does it exists any setting for VS to disable design time calls in code ?

Or is any other bypass for this issue ?

Thank you in advanced

Windows Server 2019
Windows Server 2019
A Microsoft server operating system that supports enterprise-level management updated to data storage.
3,869 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Wesley Li 10,905 Reputation points
    2024-12-29T16:10:24.03+00:00

    Hello

    Here are a few approaches you can try to resolve or bypass these issues:

     

    Use the DesignMode Property: You can use the DesignMode property to prevent certain code from running at design time. This property checks if the control is being used in the designer and skips the problematic code. Here's an example:

     

    if (!this.DesignMode)

    {

        // Code that should only run at runtime

    }

     

    Disable Code Analysis: Visual Studio allows you to control whether source code analyzers run at build time and design time. You can disable these to see if it helps with your issue:

    Right-click the project node in Solution Explorer and select Properties.

    Go to the Code Analysis tab.

    Uncheck Run on live analysis to disable live source analysis.

     

    Clean and Rebuild: Sometimes, simply cleaning and rebuilding the project can resolve design-time errors:

    Right-click on the solution or project in Solution Explorer.

    Select Clean.

    After cleaning, select Rebuild.

     

    Check for Missing References: Ensure that all necessary references are included in your project. Missing references can often cause design-time errors.

     

    Use a Separate Class for Design-Time Code: If certain code is causing issues at design time, you can move it to a separate class and only instantiate it at runtime.

     

    Update Visual Studio: Make sure you are using the latest version of Visual Studio 2019, as updates often include fixes for known issues.

     

    If these steps don't resolve your issue, you might want to check out more detailed troubleshooting guides on the Microsoft Learn site.

    0 comments No comments

  2. Georgius 25 Reputation points
    2025-01-10T10:56:38.4766667+00:00

    Hi Wesley Li,

    Currently in all places this.DesignMode is used, but looks it does not works by some reason - always returns False.

    but as investigation shows, works following approach: if replace this property by this check in IF statement:

    System.ComponentModel.LicenseManager.UsageMode = System.ComponentModel.LicenseUsageMode.Designtime

    Thank you.

    With regards.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.