F#, problems with IntelliSense and Office - f#

I'm trying to write some Office automation code and I cannot get IntelliSense help for the PIA Office types. The strange thing is that it works fine in C# and also in the Tutorial.vs2010 F# Solution with some of the same code.
I'm using VS10 and PIA for Office 14.
VS
Any ideas?

I forgot to include a reference to Office.dll. That appeared to fix the issue.

For anyone finding this later, but can't figure out where office.dll is, like I did. I faced the same Issue with F# 4.0, Office 2013, and VS Community 2015 Update 2.0
I typed this in the beginning of the file to get Intellisense working, no need to search for office.dll in your machine:
#r "office, Version = 15.0.0.0"
This is the same text it gives you with <Note>, but without the Culture=neutral and PublicKey=w/e. Seems to work flawlessly.
For context, this is how my file starts:
#r "Microsoft.Office.Interop.Excel"
#r "office, Version = 15.0.0.0"
open System
open System.IO
open System.Reflection
open Microsoft.Office.Interop.Excel
let app = ApplicationClass(Visible = true)
let sheet = app.Workbooks
.Add()
.Worksheets.[1] :?> _Worksheet

Related

F# Interactive with nuget reference: namespace not defined

I am trying to use the Select.HtmlToPdf library https://www.nuget.org/packages/Select.HtmlToPdf/20.2.0
#r "nuget: Select.HtmlToPdf, 20.2.0"
open Select.HtmlToPdf
After sending the reference to the FSI, it returns a path to ...\Project.fsproj.fsx and namespace FSI_0004.Project
After sending the open statement to FSI, I get
The namespace or module "Select" is not defined.
I am pretty new to F#, hope somebody can explain how I have to do this.
Thanks
EDIT: I use Visual Studio Code and/or Jupyter lab
The library is called Select.HtmlToPdf, but the namespace it uses is SelectPdf, so this should work:
#r "nuget: Select.HtmlToPdf, 20.2.0"
open SelectPdf

Meaning of CsvProvider error "The given key was not present in the dictionary" when trying to load sample file?

I am having trouble loading the csv files with FSharp.Data csv provider provided by fslab, including the sample adwords.csv file.
What does this error below mean? Also, when I hover over the code in the Visual studio editor it mentions that "The given key was not present in the dictionary"
Problem example:
#load "packages/FsLab/FsLab.fsx"
open System.IO
open FSharp.Data
"adwords.csv"
|> File.ReadAllLines
let test = CsvProvider<"adwords.csv">.GetSample()
The output:
>
val it : string [] =
[|"Criteria ID,Name,Canonical Name,Parent ID,Country Code,Target Type,Status";
"1000010,Abu Dhabi,"Abu Dhabi,Abu Dhabi,United Arab Emirates",9041082,AE,City,Active";
"1000011,Ajman,"Ajman,Ajman,United Arab Emirates",9047096,AE,City,Active";
"1000012,Al Ain,"Al Ain,Abu Dhabi,United Arab Emirates",9041082,AE,City,Active";
"1000013,Dubai,"Dubai,Dubai,United Arab Emirates",9041083,AE,City,Active";
"2004,Afghanistan,Afghanistan,,AF,Country,Active"|]
>
>System.MethodAccessException: Attempt by method '<StartupCode$FSI_0007>.$FSI_0007.main#()' to access method 'FSharp.Data.Runtime.CsvFile`1<System.__Canon>.Create(System.Func`3<System.Object,System.String[],System.__Canon>,
at <StartupCode$FSI_0007>.$FSI_0007.main#() in C:\test.fsx:line 11
Stopped due to error
I ran into this problem with my own files, so I grabbed this sample file from here: https://raw.githubusercontent.com/fsharp/FSharp.Data/master/tests/FSharp.Data.Tests/Data/Adwords.csv
Debug info:
If I delete the FSharp.Data library folder (v 2.3.0) and replace with version 2.2.5 it works correctly with no error.
If I don't use the FsLab.fsx script and instead use
#I "packages/FSharp.Data/lib/net40
#r "FSharp.Data.dll"
then everything works.
The path to the FsLab.fsx script is correct, it runs when I send the line to fsi.
The F# version is 14.0.23413.0.
The version of FSharp.Data downloaded by FSlab is FSharp.Data.2.3.0.
I have no other references in the .fsx script.
I am using Visual Studio Community edition 14.0.24720.00 Update 1.
.NET version 4.6.01038
I am realizing now that I am not getting the popup asking if I want to allow the .dll like I think I used to get when I used this before.
There is nothing wrong with the file. This for example works:
#load #"..\..\FSLAB\packages\FsLab\FsLab.fsx"
open System.IO
open FSharp.Data
[<Literal>]
let csvFile = #"C:\tmp\adwords.csv"
File.Exists csvFile
type Csv = CsvProvider<csvFile>
let csv = Csv.Load(csvFile)
csv.Rows
There is something wrong with your FsLab of FSharp.Data installation or type providers security maybe. Try the following, specify the path to the file directly. If it still doesn't work just nuget FSharp.Data and try using the csv type provider directly in a new project.
Other info is also helpful. VS version, FSLab version, wha other references you have. etc.
EDIT: Thanks for the debug info. That's actually quite helpful. VS2015 Update 1 broke two things, the Binding Redirect for Fsharp and the type providers (that might have been FSharp Tools, I forgot). I would upgrade to Update 2. If that's not possible please check if your FSharp.Data.TypeProviders.dll is in C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\4.3.0.0\Type Providers.
As referencing the dlls directly works, it's probably a version mismatch issue. My FsLab install predates VS2015 Update 1 and 2, so will see if it behaves differently with a new download.
There is some issue with the installation of FSharp.Data currently bundled with FsLab (as of June 2016). This issue is with version 2.3.0. If you instead use FSharp.Data 2.2.5 the code works as expected.
Delete the packages/FSharp.Data folder and replace with version 2.2.5. I did it from an old installation but you could do it from Nuget

How can I use FSharp.Data with VS 2015?

I'm trying to using FSharp.Data in a script file on a FSharp project, and the error that I'm receiving is:
Warning '..\packages\FSharp.Data.2.2.5\lib\net40\FSharp.Data.dll' is
not a valid assembly name.
FSharp.Data from https://www.nuget.org/packages/FSharp.Data/
It's the same problem if I try with a F# project for .NET 4.0, .NET 4.5 or .NET 4.6.
EDIT: It works fine with '..\packages\FSharp.Data.2.2.5\lib\portable-net40+sl5+wp8+win8\FSharp.Data.dll' but in this portable version only web locations are supported.
I think the problem is string escaping. In the following:
#r "..\packages\FSharp.Data.2.2.5\lib\net40\FSharp.Data.dll"
The \n is interpreted as a new-line character and so it is invalid. But in the following:
#r "..\packages\FSharp.Data.2.2.5\lib\portable-net40+sl5+wp8+win8\FSharp.Data.dll"
.. there are no special escape sequences in the string. Both of the following should work:
#r #"..\packages\FSharp.Data.2.2.5\lib\net40\FSharp.Data.dll"
#r "..\\packages\\FSharp.Data.2.2.5\\lib\\net40\\FSharp.Data.dll"

Can an XNA Game use IsolatedStorageSettings for WP7?

I've been trying to port some Windows Phone 7 code between Silverlight to XNA which relies on IsolatedStorageSettings but I can't get Visual Studio to resolve it. When I have a look at what Intellisense is resolving under System.IO.IsolatedStorage & it lists IsolatedStorageFile, IsolatedStorageException & IsolatedStorageStream.
The documentation says that the supported version is for Silverlight but I don't understand why I am seeing the difference because of the project types.
http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k(SYSTEM.IO.ISOLATEDSTORAGE.ISOLATEDSTORAGESETTINGS);k(ISOLATEDSTORAGESETTINGS);k(TargetFrameworkMoniker-%22SILVERLIGHT,VERSION%3dV4.0%22);k(DevLang-CSHARP)&rd=true
Thanks
The following work for me in an XNA project with no extra project references:
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
store.CreateFile("folder/file.ext");
}
After adding a reference to System.Windows.dll I can then do:
var settings = IsolatedStorageSettings.ApplicationSettings;
settings.Add("something", "myValue");
settings.Save();
If you can't get the above working, can you post an example of what you're trying.

How do you SetMaxAttachmentSize in TFS 2010?

I want to set the maximum work item attachment size. From old blogs I have found that it is possible by calling SetMaxAttachmentSize, but the blogs are for older versions of TFS. I have found the new webservice path for TFS 2010.
http://localhost:8080/tfs/_tfs_resources/WorkItemTracking/v1.0/ConfigurationSettingsService.asmx/SetMaxAttachmentSize
Unfortunately when I call it like that I receive this error: This request can only be made against a project collection. The (.asmx) file should be located in the project directory (usually _tfs_resources under the application root).
I don't know how to format the call via a browser to target a specific project collection. Any thoughts?
Apparently SetMaxAttachmentSize web service was not leveraged on TFS 2010 therefore you need to do this programmatically, try running the following code:
TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(#"http://yourtfsserver:8080/tfs/DefaultCollection");
ITeamFoundationRegistry rw = tfs.GetService<ITeamFoundationRegistry>();
RegistryEntryCollection rc = rw.ReadEntries(#"/Service/WorkItemTracking/Settings/MaxAttachmentSize");
RegistryEntry re = new RegistryEntry(#"/Service/WorkItemTracking/Settings/MaxAttachmentSize", "20971520"); //20MB
if (rc.Count != 0)
{
re = rc.First();
re.Value = "20971520";
}
rw.WriteEntries(new List<RegistryEntry>() { re });
I hope it works for you
Regards,
Randall Rosales
I have found that this works. It is easier than writing code.
Go to this url replacing <Collection> with your project collection: http://localhost:8080/tfs/<Collection>/WorkItemTracking/v1.0/ConfigurationSettingsService.asmx
Choose SetMaxAttachmentSize
You can test to make sure you set it correctly by going to the same url above and then selecting GetMaxAttachmentSize.

Resources