问题描述
我正在尝试从F#编译代码以在Silverlight中使用.我编译:
I'm trying to compile code from F# to use in Silverlight. I compile with:
-noframework --cliroot"C:\ program Files \ Microsoft Silverlight \ 2.0.31005.0"-独立
--noframework --cliroot "C:\program Files\Microsoft Silverlight\2.0.31005.0" --standalone
这将生成引用SL框架的独立程序集.但是,当我尝试添加对生成的程序集的引用时,出现此错误:
This generates a standalone assembly that references the SL framework. But when I try to add a reference to the generated assembly, I get this error:
VS插件如何确定这不是Silverlight程序集?这是清单:
What is the VS plugin doing to determine that this isn't a Silverlight assembly? Here's the manifest:
// Metadata version: v2.0.50727
.assembly extern mscorlib
{
.publickeytoken = (7C EC 85 D7 BE A7 79 8E ) // |.....y.
.ver 2:0:5:0
}
.assembly FSSLLibrary1
{
// --- The following custom attribute is added automatically, do not uncomment -------
// .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 01 01 00 00 00 00 )
.hash algorithm 0x00008004
.ver 0:0:0:0
}
.module 'F#-Module-FSSLLibrary1'
// MVID: {49038883-5D18-7281-A745-038383880349}
.imagebase 0x00400000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY
// Image base: 0x04120000
我不明白自己不喜欢的发现;它是纯可验证的IL.我将它与SL的类库"程序集进行了比较,并且外观相同.唯一的区别是一些属性,但是我删除了那些属性,而VS仍然让我引用了DLL.我什至将无法验证的IL添加到"SL库" DLL中,并且仍在加载.
I don't understand what it's finding that it doesn't like; it's pure verifiable IL. I compared to a SL "class library" assembly, and it looks the same. The only difference was some attributes, but I deleted those and VS still let me reference the DLL. I even added unverifiable IL to the "SL library" DLL and it still loaded.
有什么建议吗?
更新:我已经四处寻找,似乎并不重要.它不喜欢FSharp库中的IL.它们是可辩护的,但其中的某些因素会引发拒绝.
Update: I've done some poking around, and it doesn't seem to be the manifest that matters. It doesn't like something in the IL from the FSharp libraries. They are peverifiable, but something in there is triggering the rejection.
推荐答案
答案!
显然,问题在于,当您添加对bin \ Release或bin \ Debug的引用时,Visual Studio(或Silverlight项目系统)决定尝试引用该项目.无论出于何种原因,该操作都会失败.
Apparently the problem is that when you add a reference to the bin\Release or bin\Debug, Visual Studio (or the Silverlight project system) decides to try to reference the project. This fails for whatever reason.
如果将F#输出DLL复制到另一个位置,则引用可以正常进行. (当然,这将是文件参考,而不是项目参考.)
If you copy the F# output DLL to another location, then the reference goes through just fine. (This will be a file reference, not a project reference, of course.)
然后设置依赖项,以便首先构建F#库,然后可以使用文件引用来获取F#生成的二进制文件.
Then setup dependencies so the F# library builds first, then you can use a file reference to get the F#-generated binary.
更新:一个明显的问题.如果我打开优化代码,则会收到此错误:
Update: One more apparent issue. If I turn optimize code on, then I get this error:
C:\test\SilverlightApplication1\FSC(0,0): error FS0193: internal error: the module/namespace 'System' from compilation unit 'mscorlib' did not contain the namespace, module or type 'MarshalByRefObject'
如果我不执行优化代码,则此操作将消失并且一切正常.
If I keep optimized code off, this goes away and everything works fine.
这篇关于Silverlight如何确定组件为"Silverlight"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!