Error: You must add a reference to assembly FSharp.Core

Jul 1, 2011 at 12:08 AM

I am using the following command to create a SubscribeOptions variable:

var subopt = new List.SubscribeOptions {DoubleOptIn = false, EmailType = List.EmailType.Html};

When this is included in my project I receive the following compiler error:

 

Error 1 The type 'Microsoft.FSharp.Core.FSharpOption`1<T0>' is defined in an assembly that is not referenced. You must add a reference to assembly 'FSharp.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. C:\Development\Demo\MailChimpTest\MailChimpTest\Program.cs 32 13 MailChimpTest

This is a C# project. I do not see the FSharp.Core option under my Add Refernces list. Should this actually be required? Is the F# DLL returning a F# type of object?

 

Jul 1, 2011 at 12:25 AM

I was able to find and add the reference to Fsharp.Core, however I still question as to why this was required in the first place.

Coordinator
Jul 1, 2011 at 8:36 AM

Because the dll is written in F# :)

Jun 5, 2012 at 10:23 PM

FYI ... this DLL was stored here on my machine: C:\Program Files\Reference Assemblies\Microsoft\FSharp\2.0\Runtime\v4.0\FSharp.Core.dll

Jun 5, 2012 at 10:36 PM

I'm having some issues which i think are related to this thread. I'm getting this error when trying to build my solution (asp.net web application in c#4.0 written in VS 2010):

Error 1 Could not load file or assembly 'file:///C:\Users\logon\Documents\Businesses\Babble\Web Code Apps\TFS\BabbleBib\Src\BabbleBibWebSites\BabbleBibAdmin\bin\MailChimp.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515) C:\Users\logon\Documents\Businesses\Babble\Web Code Apps\TFS\BabbleBib\Src\BabbleBibWebSites\BabbleBibAdmin\SGEN BabbleBibAdmin

Here is what i have done:

  • Copied MailChimp.dll to my bin folder
  • Added a reference to MailChimp.dll
  • Added a reference to FSharp.Core
  • Added the following code and built the solution:
                string apikey = "<my api key>"; // or default to config
                MailChimp.MCApi mc = new MailChimp.MCApi(apikey, false);
                try
                {
                    Boolean ok = mc.ListSubscribe("<my list id from mail chimp>", "<the email address i want to add>");
                    textBox1.Text = ok.ToString();
                }
                catch (MailChimp.Types.MCException ex)
                {
                    textBox1.Text = ex.Message;
                }
    

 

What have i done wrong or am i missing a step?

PS: The solution looks really awesome ... if i can get this working I'm done! :)

Coordinator
Jun 6, 2012 at 8:50 AM

I've just tried the above code in a "virgin" asp.net project. It works on my machine (I did not have to add FSharp.Core.dll because it's part of .NET 4).
Check if your website is indeed targeted to .NET 4

<compilation debug="true" targetFramework="4.0"/>

 

 

Jun 7, 2012 at 11:08 AM

Hmmmm, interesting. I have just tried the same code in a 'virgin' project and it worked for me too.

However my original project is already targeting .net 4.0 so not sure what is going on ....... any other ideas? Does it matter where the DLL is placed in my project (currently the /bin folder)

Coordinator
Jun 7, 2012 at 11:38 AM
Edited Jun 7, 2012 at 11:49 AM
Hmmm :) Then it must be web.config. Look there and remove all the references to old FSharp.Core version if exists. Anyway, compare 'configs' of these two projects...
Jun 7, 2012 at 11:53 AM

OK, so I have figured out the difference ..... my original project was configured as a 'release' build, but my virgin proejct was 'debug'.

I switched my original project to 'debug' and the code worked (yay!). When I switch back to 'release' it fails again.

Both projects have <compilation debug="true" targetFramework="4.0"/> in the web.config.

I am now a little lost as to how I get the code working in release mode because I'll obviously want to make the code live at some point?

Coordinator
Jun 7, 2012 at 12:17 PM
Try Shift+F4 (Properties pages). Check "references" or "build" options...
Jun 7, 2012 at 2:51 PM

Hi, thanks for getting back to me ... I'm not quite sure what i am looking for in the properties page. Here ares ome of the key settings on eth project that fails in release mode but works in debug:

Application > Target Framework: .NET framework 4

Build > Configuration: Active (Release)

Build > Platform: Active (Any CPU)

Platform Target: Any CPU

 

Are there any specific settings I shodul check other than the above?

Coordinator
Jun 7, 2012 at 3:43 PM
Check the difference between Debug and Release settings.
It's really hard to find the problem in remote...

On Thu, Jun 7, 2012 at 4:51 PM, martinkearn_msft <notifications@codeplex.com> wrote:

From: martinkearn_msft

Hi, thanks for getting back to me ... I'm not quite sure what i am looking for in the properties page. Here ares ome of the key settings on eth project that fails in release mode but works in debug:

Application > Target Framework: .NET framework 4

Build > Configuration: Active (Release)

Build > Platform: Active (Any CPU)

Platform Target: Any CPU

Are there any specific settings I shodul check other than the above?

Read the full discussion online.

To add a post to this discussion, reply to this email (mcapinet@discussions.codeplex.com)

To start a new discussion for this project, email mcapinet@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com




--
Denis K
Jun 9, 2012 at 12:05 PM

I'm happy to report that i now have this working in both the release and debug modes.

I had to disable (turn off) the 'Generate serialization assembly' option from the project properties build tab.

This defaulted to 'auto', but when i set it to 'off' it worked ... I have no idea what this is or why it works but it does work so I'm a happy bunny! :)

Thanks for your help Denis K :)

Dec 20, 2012 at 10:12 AM

Hi Denisk,

I am getting the same error.

Error Details:

Error 4 The type 'Microsoft.FSharp.Core.FSharpOption`1<T0>' is defined in an assembly that is not referenced. You must add a reference to assembly 'FSharp.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. 

 

Is it compulsory to add the required FSharp reference? I have already disableed (turn off) the 'Generate serialization assembly' option from the project properties build tab.

 

Are there any other alternative?

Dec 20, 2012 at 10:15 AM
Edited Dec 20, 2012 at 10:17 AM

Here is my code for your reference:

MailChimp.Types.Opt<MailChimp.Types.List.Merges> mergeTags = new MailChimp.Types.List.Merges(email, MailChimp.Types.List.EmailType.Html)
{
	{ "FULLNAME", fullName.Value }
};

return _objMCApi.ListSubscribe(MailchimpSongbackerNewsLetterListId, email, options: options, merges: mergeTags);
Coordinator
Dec 20, 2012 at 11:59 AM
Edited Dec 20, 2012 at 11:59 AM

Try this on a fresh project. It should be targeted on .NET 4.0 (general, not client profile).
In general, there is no need to add reference to FSharp.Core.

Dec 20, 2012 at 3:58 PM
denisk1981 wrote:

Try this on a fresh project. It should be targeted on .NET 4.0 (general, not client profile).
In general, there is no need to add reference to FSharp.Core.


Hi Denisk,

Thanks for the reply. Just to let you know I am using your released dll v1.3.1 in my project having .Net framework 4.5 (general). But still I am getting this error.

Please let me know what to try out further.

Coordinator
Dec 20, 2012 at 4:35 PM

The dll is compiled under .Net 4.0. So it uses F# 2.0.
 .Net 4.5 comes with F# 3.0. That's why U have to reference FSharp.Core 4.0 or recompile the project under .Net 4.5.

 

Dec 21, 2012 at 4:47 AM

I have chnged the FW to 4.0 from 4.5 and recompiled the project but still I am getting the same error.

Error	1	The type 'Microsoft.FSharp.Core.FSharpOption`1' is defined in an assembly that is not referenced. You must add a reference to assembly 'FSharp.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

Dec 21, 2012 at 6:01 AM
martinkearn_msft wrote:

FYI ... this DLL was stored here on my machine: C:\Program Files\Reference Assemblies\Microsoft\FSharp\2.0\Runtime\v4.0\FSharp.Core.dll

Thanks Martin,

Finally I have added the reference from your specified path and got resolved my issue.

 

Thanks a lot denisk for your quick assistance.

Jun 25, 2013 at 8:26 AM
Hi,
       please give me any example how to add in mail-chimp list email..
using asp .net with c# , form contains multiple text box and single button, on button click text box value added in mail chimp list, after send mail on added email in list..