无法加载 System.Resources.Extensions - 在 .Net Framework 中
Can't load System.Resources.Extensions - in .Net Framework
我的代码突然出现错误,这是为 .Net Framework 4.6.1 编译的表单应用程序。当我去创建一个继承自 TreeView 对象的对象时发生。
它在 TreeView 之上做的很少。
例外情况是:
System.IO.FileNotFoundException
HResult=0x80070002
Message=Could not load file or assembly 'System.Resources.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.
Source=<Cannot evaluate the exception source>
StackTrace:
<Cannot evaluate the exception stack trace>
它有这个代码:
protected override void OnHandleCreated(EventArgs e)
{
SendMessage(this.Handle, TVM_SETEXTENDEDSTYLE, (IntPtr)TVS_EX_DOUBLEBUFFER, (IntPtr)TVS_EX_DOUBLEBUFFER);
base.OnHandleCreated(e);
}
并在设置中执行以下操作:
private void InitializeComponent()
{
this.SuspendLayout();
//
// LinkTreeView
//
this.DrawMode = System.Windows.Forms.TreeViewDrawMode.OwnerDrawText;
this.DrawNode += new System.Windows.Forms.DrawTreeNodeEventHandler(this.LinkTreeView_DrawNode);
this.MouseEnter += new System.EventHandler(this.LinkTreeView_MouseEnter);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.LinkTreeView_MouseMove);
this.NodeMouseClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.LinkTreeView_NodeMouseClick);
this.MouseLeave += new System.EventHandler(this.LinkTreeView_MouseLeave);
this.ResumeLayout(false);
}
它有成员变量,但都是标准形式类:
private Brush disabledBrush;
private Brush foregroundBrush;
private Brush linkBrush;
private Brush visitedBrush;
private Brush backGroundBrush;
private Pen activeLinkPen;
private Pen linkPen;
private Pen visitedLinkPen;
private StringFormat format;
// the delete bitmap out at the end.
private static readonly Bitmap deleteActive;
private static readonly Bitmap deleteDisabled;
private static readonly Rectangle rectDeleteBitmap;
知道出了什么问题吗?
这是由于 .net 4.8 中存在的错误,请参阅 https://github.com/dotnet/runtime/issues/39078
我在引用为 .net core 3.1 和 .net framework 4.8 构建的库时得到它。
请注意,在同时针对框架和 .net 核心时,您需要引用 System.Resources.Extensions nuget。添加了一个新项目 属性 <GenerateResourceUsePreserializedResources>True</GenerateResourceUsePreserializedResources>
,因此资源捆绑适用于两者。
解决方法(来自错误评论并为我工作)是将绑定重定向添加到 app.config
<dependentAssembly>
<assemblyIdentity name="System.Resources.Extensions" culture="neutral" publicKeyToken="cc7b13ffcd2ddd51" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
我的代码突然出现错误,这是为 .Net Framework 4.6.1 编译的表单应用程序。当我去创建一个继承自 TreeView 对象的对象时发生。
它在 TreeView 之上做的很少。
例外情况是:
System.IO.FileNotFoundException
HResult=0x80070002
Message=Could not load file or assembly 'System.Resources.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.
Source=<Cannot evaluate the exception source>
StackTrace:
<Cannot evaluate the exception stack trace>
它有这个代码:
protected override void OnHandleCreated(EventArgs e)
{
SendMessage(this.Handle, TVM_SETEXTENDEDSTYLE, (IntPtr)TVS_EX_DOUBLEBUFFER, (IntPtr)TVS_EX_DOUBLEBUFFER);
base.OnHandleCreated(e);
}
并在设置中执行以下操作:
private void InitializeComponent()
{
this.SuspendLayout();
//
// LinkTreeView
//
this.DrawMode = System.Windows.Forms.TreeViewDrawMode.OwnerDrawText;
this.DrawNode += new System.Windows.Forms.DrawTreeNodeEventHandler(this.LinkTreeView_DrawNode);
this.MouseEnter += new System.EventHandler(this.LinkTreeView_MouseEnter);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.LinkTreeView_MouseMove);
this.NodeMouseClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.LinkTreeView_NodeMouseClick);
this.MouseLeave += new System.EventHandler(this.LinkTreeView_MouseLeave);
this.ResumeLayout(false);
}
它有成员变量,但都是标准形式类:
private Brush disabledBrush;
private Brush foregroundBrush;
private Brush linkBrush;
private Brush visitedBrush;
private Brush backGroundBrush;
private Pen activeLinkPen;
private Pen linkPen;
private Pen visitedLinkPen;
private StringFormat format;
// the delete bitmap out at the end.
private static readonly Bitmap deleteActive;
private static readonly Bitmap deleteDisabled;
private static readonly Rectangle rectDeleteBitmap;
知道出了什么问题吗?
这是由于 .net 4.8 中存在的错误,请参阅 https://github.com/dotnet/runtime/issues/39078
我在引用为 .net core 3.1 和 .net framework 4.8 构建的库时得到它。
请注意,在同时针对框架和 .net 核心时,您需要引用 System.Resources.Extensions nuget。添加了一个新项目 属性 <GenerateResourceUsePreserializedResources>True</GenerateResourceUsePreserializedResources>
,因此资源捆绑适用于两者。
解决方法(来自错误评论并为我工作)是将绑定重定向添加到 app.config
<dependentAssembly>
<assemblyIdentity name="System.Resources.Extensions" culture="neutral" publicKeyToken="cc7b13ffcd2ddd51" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>