简体   繁体   English

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

[英]Error creating instance of C# class in F# script file

I have the following C# class that I would like to make use of in 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;
    }
}

I would like to create an instance of it in F#. 我想在F#中创建它的一个实例。 The code I am using to do this is in an f# script file 我用来执行此操作的代码位于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 )

The error I get is: 我得到的错误是:

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.

I have checked the file paths and they seem to be correct. 我检查了文件路径,它们似乎是正确的。 I can mouse over the 'type tick' and it gives me the structure of the C# object. 我可以将鼠标悬停在'type tick'上,它为我提供了C#对象的结构。 So It seems to be finding the C# code. 因此,似乎正在查找C#代码。 Can anyone tell me what I am doing wrong here? 谁能告诉我这里做错了什么? Syntax? 句法? Still very new to C# -> F# introp 对C#来说还是一个新手 - > F#introp

There are several things to check here: 这里有几件事要检查:

  1. Make sure that fsi.exe is running in a bit mode that is compatible with your WranglerDataStructures.dll. 确保fsi.exe以与WranglerDataStructures.dll兼容的位模式运行。 You run fsi.exe as a 64, or 32 bit process by setting a flag in the Visual Studio Options, under F# Tools -> F# Interactive -> 64-bit F# Interactive. 通过在Visual Studio选项中的F#工具-> F#Interactive-> 64位F#Interactive下设置一个标志,可以将fsi.exe作为64位或32位进程运行。 You can usually avoid these types of problems by setting your C# assembly to compile as Any CPU. 通常,可以通过将C#程序集设置为“编译为任何CPU”来避免这些类型的问题。

  2. Make sure that WranglerDataStructures.dll doesn't depend on other libraries that you are not referencing from F#. 确保WranglerDataStructures.dll不依赖您未从F#引用的其他库。 Either add the references in F#, or remove them from WranglerDataStructures.dll. 在F#中添加引用,或从WranglerDataStructures.dll中将其删除。

If these steps don't yield success try using the fuslogview.exe tool http://msdn.microsoft.com/en-us/library/e74a18c4.aspx to see exactly what reference is not being loaded. 如果这些步骤没有成功,请尝试使用fuslogview.exe工具http://msdn.microsoft.com/en-us/library/e74a18c4.aspx查看未正确加载的引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM