【发布时间】:2018-12-15 20:41:16
【问题描述】:
我创建了一个 F# 库 (.NET Standard 2.0) 和一个 WPF 应用程序 (.NET Framework 4.7.2)
这是使用这个库的代码:
let LeResourceFile(resourceName) =
let assembly = System.Reflection.Assembly.GetExecutingAssembly();
//var resourceName = "MyCompany.MyProduct.MyFile.txt";
use stream = assembly.GetManifestResourceStream(resourceName)
use reader = new System.IO.StreamReader(stream)
let result = reader.ReadToEnd();
result
let LogoBanco (CodigoDoBanco:string) =
match CodigoDoBanco with
| "001" -> LeResourceFile("BoletoBancarioFacil.templates.Logos.BB.png")
| _ -> ""
当我尝试从 C# (NET 4.7.2) 访问库函数 (.NET Standard 2.0) 时,我得到了这个异常:
System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Runtime, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'
为什么会发生这种情况以及如何解决它以使其正常工作?
编辑:我试图在那个 F# 库的 NuGet 上找到这个 System.Runtime,但这个特定版本不可用:
这是堆栈跟踪:
System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. O sistema não pode encontrar o arquivo especificado.
File name: 'System.Runtime, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at BoletoBancarioFacil.HTML.LogoBanco(String CodigoDoBanco)
at BoletoBancarioFacil.HTML.GeraBoletoHTML(Decimal amount, String LinhaDigitavel, String CodigoBarras) in C:\Users\tonyv\source\repos\siteApelosUrgentes\socio\cadastro\BoletoBancarioFacil\HTML.fs:line 49
at cadastro.MainWindow.GeraHTMLboleto(Titulo titulo) in C:\Users\tonyv\source\repos\siteApelosUrgentes\socio\cadastro\cadastro\MainWindow.xaml.cs:line 389
at cadastro.MainWindow.ExibeBoleto(Titulo titulo, Boolean Imprime) in C:\Users\tonyv\source\repos\siteApelosUrgentes\socio\cadastro\cadastro\MainWindow.xaml.cs:line 737
at cadastro.MainWindow.ListBoxTitulos_SelectionChanged(Object sender, SelectionChangedEventArgs e) in C:\Users\tonyv\source\repos\siteApelosUrgentes\socio\cadastro\cadastro\MainWindow.xaml.cs:line 987
=== Pre-bind state information ===
LOG: DisplayName = System.Runtime, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
(Fully-specified)
LOG: Appbase = file:///C:/Users/tonyv/source/repos/siteApelosUrgentes/socio/cadastro/cadastro/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : BoletoBancarioFacil, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\tonyv\source\repos\siteApelosUrgentes\socio\cadastro\cadastro\bin\Debug\cadastro.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 4.1.2.0 redirected to 4.1.2.0.
LOG: Post-policy reference: System.Runtime, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: Attempting download of new URL file:///C:/Users/tonyv/source/repos/siteApelosUrgentes/socio/cadastro/cadastro/bin/Debug/System.Runtime.DLL.
LOG: Attempting download of new URL file:///C:/Users/tonyv/source/repos/siteApelosUrgentes/socio/cadastro/cadastro/bin/Debug/System.Runtime/System.Runtime.DLL.
LOG: Attempting download of new URL file:///C:/Users/tonyv/source/repos/siteApelosUrgentes/socio/cadastro/cadastro/bin/Debug/System.Runtime.EXE.
LOG: Attempting download of new URL file:///C:/Users/tonyv/source/repos/siteApelosUrgentes/socio/cadastro/cadastro/bin/Debug/System.Runtime/System.Runtime.EXE.
【问题讨论】:
-
可以添加异常的堆栈跟踪吗?
-
好的,我添加了堆栈跟踪信息。
-
在这种情况下,当我将 C# WPF 应用程序降级到 .NET 4.7.0 时。并且它没有那个例外。 github.com/dotnet/standard/issues/481#issuecomment-429653699
-
您是否尝试将 .dll 复制到与应用程序相同的文件夹中?
-
不,我使用 Visual Studio 添加了 F# 项目作为参考。所以它会构建并自动复制文件。
标签: f# .net-standard-2.0 .net-4.7.2