调整.NET交互式笔记本的运行时标识符

发布于 2025-02-13 16:09:54 字数 1015 浏览 0 评论 0原文

我有一个仍在.NET Framework 4.8和参考System.windows.forms.dll(实际上是出于非UI的原因)上的遗留程序集(实际上)使用assembly.loadfrom进行此组装。

但是,如果我这样做,我最终会得到一个例外无法加载文件或汇编'system.windows.forms,版本= 4.0.0.0,culture =中性,publicKeytoken = b77a5c561934e089'。系统找不到指定的文件。。因此,我认为,从本质上讲,运行时并没有查看.NET 4 GAC,因为它不是.NET 4 CLR,然后期望组件位于同一文件夹中。

在受到控制的应用程序中,我们取得了良好的成功,只需将目标框架绰号更改为net6.0-windows在这种情况下,但是重新编译显然不是交互式笔记本电脑的选择。

我已经看到Nuget Cache文件夹中的dll中有一个RuntimeConfig.json:

{
  "runtimeOptions": {
    "tfm": "net6.0",
    "frameworks": [
      {
        "name": "Microsoft.NETCore.App",
        "version": "6.0.0"
      },
      {
        "name": "Microsoft.AspNetCore.App",
        "version": "6.0.0"
      }
    ],
    "configProperties": {
      "System.GC.Server": true,
      "System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
      "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
    }
  }
}

但是,更改TFM设置似乎也没有起作用。我在做什么错?

I have a legacy assembly that is still on .NET Framework 4.8 and references System.Windows.Forms.dll (for non-UI reasons, actually) and I would like to use it inside a .NET Interactive Notebook through also existing code that loads this assembly using Assembly.LoadFrom.

However, if I do that, I end up getting an exception Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.. So in my opinion, essentially the runtime is not looking into the .NET 4 GAC, because it is not a .NET 4 CLR and then expecting the assembly to be located in the same folder.

In applications that are under control, we had some good success simply changing the target framework moniker to net6.0-windows in that case, but recompile obviously is not an option for interactive notebooks.

I have seen that there is a runtimeconfig.json in the Nuget cache folder for the entry DLL:

{
  "runtimeOptions": {
    "tfm": "net6.0",
    "frameworks": [
      {
        "name": "Microsoft.NETCore.App",
        "version": "6.0.0"
      },
      {
        "name": "Microsoft.AspNetCore.App",
        "version": "6.0.0"
      }
    ],
    "configProperties": {
      "System.GC.Server": true,
      "System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
      "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
    }
  }
}

However, changing the tfm setting there did not seem to work, either. What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

就此别过 2025-02-20 16:09:54

我忘了在这里粘贴解决方案,以防任何人遇到相同的问题。实际上,我只是将组件从GAC复制到应用程序文件夹中,然后.NET Core能够找到组件。

I forgot to paste the solution here in case anybody runs into the same problem. I actually just copied the assembly from the GAC into the application folder and then, .NET Core was able to find the assembly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文