簡體   English   中英

無法加載 System.Resources.Extensions - 在 .Net Framework 中

[英]Can't load System.Resources.Extensions - in .Net Framework

我的代碼突然出現錯誤,這是為 .Net Framework 4.6.1 編譯的 Forms 應用程序。 當我去創建一個繼承自 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);
}

它有成員變量,但它們都是標准的 Forms 類:

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 添加 bindingredirect

  <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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM