.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 中
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)
发现,就是他抛出的异常,
在 .net framework 中 ( 可正常使用 ),代码如下,
解决办法:https://www.yesdotnet.com/archive/post/1627641098.html
版权声明:本文为YES开发框架网发布内容,转载请附上原文出处连接
post YES开发框架