Question

I have the following C# class that I would like to make use of in F#

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#. The code I am using to do this is in an f# script file

#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. So It seems to be finding the C# code. Can anyone tell me what I am doing wrong here? Syntax? Still very new to C# -> F# introp

Était-ce utile?

La solution

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. 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. You can usually avoid these types of problems by setting your C# assembly to compile as Any CPU.

  2. Make sure that WranglerDataStructures.dll doesn't depend on other libraries that you are not referencing from F#. Either add the references in F#, or remove them from 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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top