.NET Core Winform 打开窗体设计器报错


错误描述

使用.NET Core - winform 或 .NET5-Winform 开发过程中,打开winform窗体设计器,报错,提示:

Object reference not set to an instance of an object. Object reference not set to an instance of an object.    
Instances of this error (1)  
1.   Hide Call Stack  
at Microsoft.DotNet.DesignTools.Protocol.Endpoints.Sessions.InitializeRootComponentHandler.HandleRequest(InitializeRootComponentRequest request)
at Microsoft.DotNet.DesignTools.Protocol.Endpoints.RequestHandler`2.Microsoft.DotNet.DesignTools.Protocol.Endpoints.IRequestHandler.HandleRequest(Request request)  

 

错误信息如图所示: 

错误信息

 

解决办法

在 YESWin 开发框架中,出现这个错误的原因是 在窗体的构造函数中使用了 是否设计器的判断

具体代码在,YESWin.UI.Dev.LibForm.frmBaseData 中

 

YESWin.UI.Dev.LibForm.frmBaseData 构造函数

CheckDesingModel 类代码为

 public class CheckDesingModel
    {
        public static bool IsDesingMode()
        {
            bool returnFlag = false;
#if DEBUG      
            if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
            {
                returnFlag = true;
            }
            else if (System.Diagnostics.Process.GetCurrentProcess().ProcessName == "devenv")
            {
                returnFlag = true;
            }
#endif
            return returnFlag;
        }
    }

反编译 LicenseManager.UsageMode  (.NET 5和 .net Core)

反编译 UsageMode

发现,就是他抛出的异常,

 

在 .net framework 中 ( 可正常使用 ),代码如下,

反编译 UsageMode

 

解决办法:https://www.yesdotnet.com/archive/post/1627641098.html

 

 

版权声明:本文为YES开发框架网发布内容,转载请附上原文出处连接
YES开发框架
上一篇:文件加密技术研究
下一篇:.NETCore-winform 判断是否设计模式
评论列表

发表评论

评论内容
昵称:
关联文章

YES-CMS内容管理系统 售价

联系我们
联系电话:15090125178(微信同号)
电子邮箱:garson_zhang@163.com
站长微信二维码
微信二维码