- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个与 this question 的答案中提供的代码相关的问题.
我遇到的问题是在运行时找不到传递给 CompilerParameters
的三个引用组件(System.dll、FSharp.Core.dll、FSharp.Powerpack.dll)。我得到的错误是:
unknown-file(0,0) : error 0: error FS0218: Unable to read assembly 'c:\user s\utente\documents\visual studio 2010\Projects\TrashSolution\TrashSolution\bin\D ebug\FSharp.Core.dll'
我如何告诉编译器在 GAC 中搜索这些程序集,而不是在项目的 bin 目录中?如果我在以字符串形式提供的代码中打开命名空间,我如何知道要添加哪些程序集?我在哪里可以获得这些信息?
最佳答案
在您链接的答案的代码中,底部有一行:
let asm = Reflection.Assembly.LoadFrom(fileinfo.Value.FullName)
如果您调用 Reflection.Load
而是将完全限定程序集名称传递给它,它将尝试从 GAC(以及其他一些地方,如果程序集不在 GAC 中)加载程序集。
let asm =
Assembly.Load "SampleAssembly, Version=1.0.2004.0, Culture=neutral, PublicKeyToken=8744b20f8da049e3"
如果您不知道完全限定的程序集名称,您必须使用程序集的简单名称创建一个 AssemblyName
,然后调用 Reflection.Load
采用 AssemblyName
而不是 string
的重载。
let asmName = AssemblyName "Your.Assembly.Name"
let asm = Assembly.Load asmName
至于知道要加载哪些程序集——我认为没有一种简单的方法可以通过编程来确定它。我现在能想到的仅有的两个解决方案:
FSharpCodeProvider
解析它并查看哪些命名空间/模块已打开以及使用了哪些类型。如果您要查看是否使用了某些特定的命名空间或类型(即,您需要在编译代码时包含一个程序集引用),您可以创建一个映射(在您的 .fsx
正在将 namespace 和/或类型名称编译)为程序集名称,并使用它来引用适当的程序集。Assembly.ReflectionOnlyLoad
方法来加载程序集!这允许程序集在您完成检查后被卸载——如果您使用普通反射,则程序集无法被卸载,您的程序可能会因 OutOfMemoryException
或类似错误而崩溃。编辑: 结果表明,通过简单名称加载程序集在 fsi
中成功,但在普通 F# 代码中却失败,因为 fsi
会自动安装一个AppDomain.AssemblyResolve 的处理程序事件。当您尝试加载程序集但无法解析时,CLR 会触发此事件;该事件为您提供了一种“手动”解析程序集和/或动态生成程序集并返回它的方法。
如果您查看尝试在 F# 项目中运行代码时引发的 FileNotFoundException
,您会在异常的 Fusion Log 属性中看到类似以下内容:
=== Pre-bind state information ===
LOG: User = Jack-Laptop\Jack
LOG: DisplayName = System
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: System | Domain ID: 1
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Users/Jack/Documents/Visual Studio 2010/Projects/StackOverflow1/StackOverflow1/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : StackOverflow1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Users/Jack/Documents/Visual Studio 2010/Projects/StackOverflow1/StackOverflow1/bin/Debug/System.DLL.
LOG: Attempting download of new URL file:///C:/Users/Jack/Documents/Visual Studio 2010/Projects/StackOverflow1/StackOverflow1/bin/Debug/System/System.DLL.
LOG: Attempting download of new URL file:///C:/Users/Jack/Documents/Visual Studio 2010/Projects/StackOverflow1/StackOverflow1/bin/Debug/System.EXE.
LOG: Attempting download of new URL file:///C:/Users/Jack/Documents/Visual Studio 2010/Projects/StackOverflow1/StackOverflow1/bin/Debug/System/System.EXE.
查看该日志的底部,您会看到 CLR 在放弃之前搜索程序集的位置。
这是一个简单的处理程序,可让您了解如何使用 AppDomain.AssemblyResolve 处理程序手动解析程序集。 (注意:需要在尝试加载程序集的代码之前添加处理程序!)
System.AppDomain.CurrentDomain.add_AssemblyResolve (
System.ResolveEventHandler (fun _ args ->
let resolvedAssembly =
System.AppDomain.CurrentDomain.GetAssemblies ()
|> Array.tryFind (fun loadedAssembly ->
// If this assembly has the same name as the one we're looking for,
// assume it's correct and load it. NOTE : It may not be the _exact_
// assembly we're looking for -- then you'll need to adjust the critera below.
args.Name = loadedAssembly.FullName
|| args.Name = loadedAssembly.GetName().Name)
// Return null if the assembly couldn't be resolved.
defaultArg resolvedAssembly null))
如果您将该代码添加到新的 F# 控制台项目,然后添加使用 AssemblyName
和 Assembly.Load 的代码,您应该能够加载 System
程序集因为它在 F# 项目中默认引用,并且会在您运行项目时加载。如果您尝试解析 System.Drawing
,它将失败,因为我们的自定义事件处理程序找不到程序集。显然,如果您需要一些更复杂的程序集解析逻辑,您应该以对您的应用程序有意义的任何方式将其构建到事件处理程序中。
最后,这是异常消息中提到的 MSDN 白皮书的链接:Best Practices for Assembly Loading .如果您遇到困难并且无法弄清楚如何解决所需的程序集,那么值得一读。
关于F# 编译代码在运行时以缺少程序集结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14578665/
C#内部访问修饰符的定义是内部:只能在包含程序集或友元程序集内访问。所以我的问题是什么是 C# 程序集?在包含程序集或 friend 程序集之内是什么意思?它是否意味着在同一个命名空间或项目中? 最佳
任何人都可以回答以下问题。我正在使用 c# 语言。 我可以将程序集调用为 .ddl 或 .exe 文件吗? 我可以将 Assembly Manifest 称为程序集吗? 程序集、元数据和程序集 lis
我正在从 Python 运行一个 .NET COM 程序集,只有当我将程序集 dll 和依赖项复制到我的 Python 根路径 c:\Python27 时才能使它正常工作。 这是不整洁的,所以我想将
作为世界上任何一名程序员,他/她一生中至少有一次,我正在尝试创建我的“革命性”,新的且唯一的操作系统。 :D 好吧,我正在使用虚拟模拟器(Oracle VM Virtual Box),为此我创建了一个
我创建了以下程序来读取 5 个数字,然后 dumpreg查看输入的数字... INCLUDE Irvine32.inc .data count = 5 scor
如何在保护模式下执行 IN 和 OUT 等受限指令? 我发现它需要足够高的特权级别(CPL)才能执行 IO 指令。我怎样才能在内核模式下运行,拥有 IO 权限或任何其他可能对我有帮助的东西? - 我希
目录 C# 程序集、模块和类型概念及关系 概述 程序集 模块 类型 程序集、模块和类型的关系 总结 引用
构建 maven assembly ,我留下了这样的东西: ${project.basedir} / LICENS
我的应用程序由几个核心程序集和几个扩展/插件程序集组成。为了让 MEF 知道插件必须提供的所有部件,即使我永远不会使用它们的任何部件,我也必须加载这些程序集。这使得应用程序需要更多时间来启动(如果我要
我对我们的构建基础结构有一个非常具体的要求,即将另一个 JAR 依赖项的一些内容复制到我的 Web 应用程序的特定子文件夹中。我们正在使用 maven-assembly-plugin,一个自然的方法是
为什么下面的指令会设置符号标志? mov al,0FEh sub al,2 据我了解,AL寄存器可以保存2^8 - 1或255。0FEh = 254(十进制)。减去 2 叶 252。这似乎是正数。 (
我以前使用过 NUnit,但已经有一段时间了,而且从来没有在这台机器上使用过。我在 Program Files 下解压了 2.4.8 版本,并且在尝试加载测试时不断收到此错误。 Could not l
我说的是一个使用 C# 进行游戏编程的小型游戏引擎。所以,我有一个嵌入单声道运行时的 C++ 应用程序(我称之为“启动器”)。我有一个用 C# 编写的程序集,它是我的游戏引擎类库。启动器按照 Embe
我对汇编相当陌生,并尝试从标准输入读取值(从 C 调用 scanf 函数)并将其打印回标准输出(使用 printf)。 .text readstr: .asciz "%d" #strin
谢谢帮助,我的问题是关于从下面的代码中收到的 ax 值? mov al,22h mov cl,0fdh imul cl 真机结果:ff9a 我的预期:00:9a(通过二进制相乘) 第一个数字是 22h
我正在开发一个汇编程序,该程序将整个文本文件读入缓冲区,然后将其显示在控制台中。它立即显示 24 行(每行的最大长度为 80,因为我使用 80 宽 * 25 高的 dossbox )然后等待用户输入,
我正在使用一个简单的程序集片段,使用 BIOS 作为引导加载程序的一部分将字符打印到屏幕上。这是引导加载程序代码。 [org 0x7c00] [bits 16] %include "a20_check
我只是想知道这段代码是什么意思: XOR EAX,EBX XOR EBX,EAX XOR EAX,EBX 最佳答案 那是 xor swapping . 在寄存器上执行它不会遇到常见的难看的失败案例。
我在新电脑上的 XNA 项目开始出现奇怪的错误。我有两个关于解决方案的项目和一个由它们使用的库。其中一个项目,一个 XNA 游戏项目,运行完美。另一个项目是 WindowsForm 和 XNA 的混合
是的,我正在努力实现类似的目标 __asm__(jmp label;); 其中 label 应替换为内存中保存的字符串值(结构体的字段)。 有没有办法做到这一点(或类似的方法可以让我跳转到运行时确定的
我是一名优秀的程序员,十分优秀!