iT邦幫忙

0

C# 加個簡單dll就錯誤??

  • 分享至 

  • xImage

類別庫部分

namespace library1
{
    public class Class1
    {
        public string getx()
        {
            return "123";
        }
    }
}

winform部分

using library1;


namespace testdll1
{
    public partial class Form1 : Form
    {
        library1.Class1 cc=new library1.Class1();
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show(cc.getx());
        }
    }
}

我有在testdll1專案加入參考.重建方案也沒錯誤.但是就一直跳出這個.
System.IO.FileNotFoundException: '無法載入檔案或組件 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' 或其相依性的其中之一。 系統找不到指定的檔案。'

w4560000 iT邦研究生 5 級 ‧ 2022-05-14 16:03:00 檢舉
要先確認一下 類別庫 和windorm 是甚麼.Net 版本
我曾經在.Net framwork專案 參考 .Net Core 的類別庫,編譯專案沒問題,但在runtime時發生錯誤過
rabbit iT邦新手 4 級 ‧ 2022-05-14 19:19:11 檢舉
類別庫是.net6.0 winform是.netframework4.7.2算是都預設的沒調過...winform是開.netframework專案類型
w4560000 iT邦研究生 5 級 ‧ 2022-05-14 19:41:35 檢舉
那就有可能是這個原因了,類別庫版本為.Net Standard 比較安全
MSDN可以參考 .Net Standard 支援的 .Net Framework 和 .Net Core 版本

https://docs.microsoft.com/zh-tw/dotnet/standard/net-standard?tabs=net-standard-2-0
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
I code so I am
iT邦高手 1 級 ‧ 2022-05-15 08:37:24

如果兩專案.netframework版本相符,檢查windows form專案的bin\debug目錄是否有library1.dll。

我要發表回答

立即登入回答