gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 07:10:14 25 4
gpt4 key购买 nike

我想在 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# 还是很陌生 -> F# introp

最佳答案

这里有几件事情要检查:

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

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

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

关于syntax - 在 F# 脚本文件中创建 C# 类的实例时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17925598/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com