在F#脚本文件中创建C#类实例时出错

时间:2013-07-29 13:38:59

标签: syntax f# f#-interactive c#-to-f#

我有以下要在F#

中使用的C#类
using System;
using System.Collections.Generic;
using System.Text;

namespace DataWrangler.Structures
{
    public enum Type { Trade = 0, Ask = 1, Bid = 2 }

    public class TickData
    {
        public string Security = String.Empty;
        public uint SecurityID = 0;
        public object SecurityObj = null;
        public DateTime TimeStamp = DateTime.MinValue;
        public Type Type;
        public double Price = 0;
        public uint Size = 0;
        public Dictionary<string, string> Codes;
    }
}

我想在F#中创建它的一个实例。我用来执行此操作的代码位于f#脚本文件

#r @"C:\Users\Chris\Documents\Visual Studio 2012\Projects\WranglerDataStructures\bin\Debug\WranglerDataStructures.dll"

open System
open System.Collections.Generic;
open System.Text;
open DataWrangler.Structures

type tick = TickData // <- mouse over the "tick" gives me a tooltip with the class structure

// it bombs out on this line 
let tickDataTest = tick(Security = "test", TimeStamp = DateTime(2013,7,1,0,0,0), Type = Type.Trade, Price = float 123, Size = uint32 10 )

我得到的错误是:

error FS0193: internal error: Could not load file or assembly 'file:///C:\Users\Chris\Documents\Visual Studio 2012\Projects\WranglerDataStructures\bin\Debug\WranglerDataStructures.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.

我检查了文件路径,它们似乎是正确的。我可以将鼠标悬停在'type tick'上,它为我提供了C#对象的结构。所以似乎找到了C#代码。谁能告诉我这里做错了什么?句法?对C#来说还是一个新手 - &gt; F#introp

1 个答案:

答案 0 :(得分:7)

这里有几件事要检查:

  1. 确保fsi.exe以与WranglerDataStructures.dll兼容的位模式运行。通过在F#Tools - &gt;下的Visual Studio选项中设置标志,可以将fsi.exe作为64位或32位进程运行。 F#Interactive - &gt; 64位F#Interactive。通常可以通过将C#程序集设置为编译为任何CPU来避免这些类型的问题。

  2. 确保WranglerDataStructures.dll不依赖于您未从F#引用的其他库。在F#中添加引用,或从WranglerDataStructures.dll中删除它们。

  3. 如果这些步骤没有成功,请尝试使用fuslogview.exe工具http://msdn.microsoft.com/en-us/library/e74a18c4.aspx来确切地查看未加载的引用。

相关问题