FsBlog icon indicating copy to clipboard operation
FsBlog copied to clipboard

TypeLoadException when generating from NuGet package

Open GradientVector opened this issue 10 years ago • 7 comments

After grabbing the NuGet package, I call

fake generate

but get the following exceptions:

Building project with version: LocalBuild
Shortened DependencyGraph for Target Generate:
<== Generate
<== Clean

The resulting target order is:
 - Clean
 - Generate
Starting Target: Clean
Deleting contents of C:\FsBlog\content\output/
Finished Target: Clean
Starting Target: Generate (==> Clean)
Running build failed.
Error:
System.TypeLoadException: Could not load type 'Microsoft.FSharp.Compiler.SourceCodeServices.InteractiveChecker'
 from assembly 'FSharp.Compiler.Service, Version=0.0.82.0, Culture=neutral, PublicKeyToken=null'.
   at FSharp.CodeFormat.CodeFormatAgent..ctor()
   at FSharp.Literate.Literate.parsingContext[a](FSharpOption`1 formatAgent, FSharpOption`1 evaluator, FSharpOp
tion`1 compilerOptions, FSharpOption`1 definedSymbols)
   at FSharp.Literate.Literate.ParseMarkdownFile[b](String path, FSharpOption`1 formatAgent, FSharpOption`1 com
pilerOptions, FSharpOption`1 definedSymbols, FSharpOption`1 references, FSharpOption`1 fsiEvaluator)
   at FSharp.Literate.Literate.ProcessMarkdown(String input, FSharpOption`1 templateFile, FSharpOption`1 output
, FSharpOption`1 format, FSharpOption`1 formatAgent, FSharpOption`1 prefix, FSharpOption`1 compilerOptions, FSh
arpOption`1 lineNumbers, FSharpOption`1 references, FSharpOption`1 replacements, FSharpOption`1 includeSource,
FSharpOption`1 layoutRoots)
   at FsBlogLib.BlogPosts.GetBlogHeaderAndAbstract[a,b](a transformer, b prefix, String file)
   at [email protected](Int32 i, String v)
   at [email protected](b& )
   at Microsoft.FSharp.Collections.IEnumerator.MapEnumerator`1.System-Collections-IEnumerator-MoveNext()
   at Microsoft.FSharp.Collections.SeqModule.ToArray[T](IEnumerable`1 source)
   at [email protected](Unit unitVar0)
   at [email protected](Unit unitVar0)
   at Microsoft.FSharp.Collections.SeqModule.ToArray[T](IEnumerable`1 source)
   at Microsoft.FSharp.Collections.ArrayModule.OfSeq[T](IEnumerable`1 source)
   at FsBlogLib.BlogPosts.LoadBlogPosts[a](IDictionary`2 tagRenames, a transformer, String blog)
   at FsBlogLib.Blog.LoadModel[a](IDictionary`2 tagRenames, a transformer, String root, String blog)
   at [email protected](Unit _arg15) in C:\FsBlog\content\fsblog.fsx:line 68
   at Fake.TargetHelper.runTarget@326(String targetName) in D:\code\fake\src\app\FakeLib\TargetHelper.fs:line 3
40

---------------------------------------------------------------------
Build Time Report
---------------------------------------------------------------------
Target     Duration
------     --------
Clean      00:00:00.0016739
Total:     00:00:00.0658933
Status:    Failure
---------------------------------------------------------------------
  1) System.TypeLoadException: Could not load type 'Microsoft.FSharp.Compiler.SourceCodeServices.InteractiveChe
cker' from assembly 'FSharp.Compiler.Service, Version=0.0.82.0, Culture=neutral, PublicKeyToken=null'.
   at FSharp.CodeFormat.CodeFormatAgent..ctor()
   at FSharp.Literate.Literate.parsingContext[a](FSharpOption`1 formatAgent, FSharpOption`1 evaluator, FSharpOp
tion`1 compilerOptions, FSharpOption`1 definedSymbols)
   at FSharp.Literate.Literate.ParseMarkdownFile[b](String path, FSharpOption`1 formatAgent, FSharpOption`1 com
pilerOptions, FSharpOption`1 definedSymbols, FSharpOption`1 references, FSharpOption`1 fsiEvaluator)
   at FSharp.Literate.Literate.ProcessMarkdown(String input, FSharpOption`1 templateFile, FSharpOption`1 output
, FSharpOption`1 format, FSharpOption`1 formatAgent, FSharpOption`1 prefix, FSharpOption`1 compilerOptions, FSh
arpOption`1 lineNumbers, FSharpOption`1 references, FSharpOption`1 replacements, FSharpOption`1 includeSource,
FSharpOption`1 layoutRoots)
   at FsBlogLib.BlogPosts.GetBlogHeaderAndAbstract[a,b](a transformer, b prefix, String file)
   at [email protected](Int32 i, String v)
   at [email protected](b& )
   at Microsoft.FSharp.Collections.IEnumerator.MapEnumerator`1.System-Collections-IEnumerator-MoveNext()
   at Microsoft.FSharp.Collections.SeqModule.ToArray[T](IEnumerable`1 source)
   at [email protected](Unit unitVar0)
   at [email protected](Unit unitVar0)
   at Microsoft.FSharp.Collections.SeqModule.ToArray[T](IEnumerable`1 source)
   at Microsoft.FSharp.Collections.ArrayModule.OfSeq[T](IEnumerable`1 source)
   at FsBlogLib.BlogPosts.LoadBlogPosts[a](IDictionary`2 tagRenames, a transformer, String blog)
   at FsBlogLib.Blog.LoadModel[a](IDictionary`2 tagRenames, a transformer, String root, String blog)
   at [email protected](Unit _arg15) in C:\FsBlog\content\fsblog.fsx:line 68
   at Fake.TargetHelper.runTarget@326(String targetName) in D:\code\fake\src\app\FakeLib\TargetHelper.fs:line 3
40
---------------------------------------------------------------------

I noticed that InteractiveChecker of FSharp.Compiler.Service.dll has been renamed to FSharpChecker. I think using an older version of FAKE might work. Can anyone help me track down the right version of FAKE to use?

GradientVector avatar Feb 02 '15 06:02 GradientVector

Perhaps we could use paket to lock the FAKE version?

GradientVector avatar Feb 02 '15 06:02 GradientVector

Just realized my previous comment was a bit vague. The FsBlog source code already uses Paket, but the resulting Nuget package does not make use of Paket (it includes NuGet.exe for grabbing the latest version of FAKE when generating).

What I meant to say was that we could consider including Paket in the nuget package with a paket.lock file for the specific version of FAKE to be used for generating.

GradientVector avatar Feb 03 '15 04:02 GradientVector

In the NuGet package, I tried using FAKE version 3.9.0, and got a little further but still ran into an exception:

Building project with version: LocalBuild
Shortened DependencyGraph for Target Preview:
<== Preview
<== Generate
<== Clean

The resulting target order is:
 - Clean
 - Generate
 - Preview
Starting Target: Clean
Deleting contents of C:\FsBlog\content\output/
Finished Target: Clean
Starting Target: Generate (==> Clean)
Generating archive: 2014 March
Generating archive: 2013 November
Processing file: index.cshtml
Processing file: blog\index.cshtml
Processing file: blog\2013\11-08-hello-fsblog.md
Processing file: blog\2013\11-09-getting-started.md
Running build failed.
Error:
System.MissingMethodException: Method not found: 'Microsoft.FSharp.Compiler.SourceCodeServices.ProjectOptions Microsoft.FSharp.Compiler.SourceCodeServoft.FSharp.Core.FSharpOption`1<System.DateTime>, Microsoft.FSharp.Core.FSharpOption`1<System.String[]>, Microsoft.FSharp.Core.FSharpOption`1<Boolean>)
   at FSharp.CodeFormat.CodeFormatAgent.ParseSource(String file, String source, FSharpOption`1 options, FSharpOption`1 defines)
   at FSharp.Literate.Transformations.formatCodeSnippets(String path, CompilerContext ctx, LiterateDocument doc)
   at FSharp.Literate.Literate.ProcessMarkdown(String input, FSharpOption`1 templateFile, FSharpOption`1 output, FSharpOption`1 format, FSharpOption`1Numbers, FSharpOption`1 references, FSharpOption`1 replacements, FSharpOption`1 includeSource, FSharpOption`1 layoutRoots)
   at FsBlogLib.Blog.html$cont@55(String template, Boolean hasHeader, Razor razor, FSharpOption`1 prefix, String current, String target, String ext, U
   at FsBlogLib.Blog.TransformFile(String template, Boolean hasHeader, Razor razor, FSharpOption`1 prefix, String current, String target)
   at [email protected](Unit _arg15) in C:\FsBlog\content\fsblog.fsx:line 100
   at Fake.TargetHelper.runTarget@317(String targetName) in D:\code\fake\src\app\FakeLib\TargetHelper.fs:line 331

---------------------------------------------------------------------
Build Time Report
---------------------------------------------------------------------
Target     Duration
------     --------
Clean      00:00:00.0221281
Total:     00:00:03.6207041
Status:    Failure
---------------------------------------------------------------------
  1) System.MissingMethodException: Method not found: 'Microsoft.FSharp.Compiler.SourceCodeServices.ProjectOptions Microsoft.FSharp.Compiler.SourceCodicrosoft.FSharp.Core.FSharpOption`1<System.DateTime>, Microsoft.FSharp.Core.FSharpOption`1<System.String[]>, Microsoft.FSharp.Core.FSharpOption`1<Bool
   at FSharp.CodeFormat.CodeFormatAgent.ParseSource(String file, String source, FSharpOption`1 options, FSharpOption`1 defines)
   at FSharp.Literate.Transformations.formatCodeSnippets(String path, CompilerContext ctx, LiterateDocument doc)
   at FSharp.Literate.Literate.ProcessMarkdown(String input, FSharpOption`1 templateFile, FSharpOption`1 output, FSharpOption`1 format, FSharpOption`1Numbers, FSharpOption`1 references, FSharpOption`1 replacements, FSharpOption`1 includeSource, FSharpOption`1 layoutRoots)
   at FsBlogLib.Blog.html$cont@55(String template, Boolean hasHeader, Razor razor, FSharpOption`1 prefix, String current, String target, String ext, U
   at FsBlogLib.Blog.TransformFile(String template, Boolean hasHeader, Razor razor, FSharpOption`1 prefix, String current, String target)
   at [email protected](Unit _arg15) in C:\FsBlog\content\fsblog.fsx:line 100
   at Fake.TargetHelper.runTarget@317(String targetName) in D:\code\fake\src\app\FakeLib\TargetHelper.fs:line 331
---------------------------------------------------------------------

GradientVector avatar Feb 03 '15 04:02 GradientVector

This often happens when there are multiple versions of FSharp.Core.dll around (and one library loads one version while another library loads another version).

Does the NuGet package include FSharp.Core.dll anywhere?

tpetricek avatar Feb 03 '15 12:02 tpetricek

Since the official NuGet package is relatively old (2014-03-07), I decided to see what happens when I created a new NuGet package from latest source. Everything works great, except that paket is not included in the nuget package (I copied it in manually in order to get the fake.cmd script to work).

I tried modifying the nuspec file so that the .paket\ directory would be included, but it seems that the default behavior for nuget pack is to ignore any file or directory with a dot at the beginning of the name. This happen even if you specifically include the file or directory. Apparently you can use the -NoDefaultExcludes option, but then various other files are included unnecessarily.

So, here are some options:

  • Include paket in the NuGet by some other means; perhaps including the paket NuGet package in paket.dependies so it will be downloaded to packages, then copying from there to output NuGet package.
  • Rename the .paket directory to not have a dot at the beginning, although this seems to be the standard naming in other F# projects.
  • Use - NoDefaultExcludes option when running nuget pack (and perhaps adding explicit exclusions into FsBlog.nuspec to exclude the other files which should normally be excluded). This is probably more trouble than it is worth.
  • Request a change the upstream behavior of NuGet pack when explicitly including files or directories with a dot at the beginning of the name. Could be a breaking change for some other projects?

I will draft up a pull request for option 1.

GradientVector avatar Feb 06 '15 06:02 GradientVector

Note that paket does not necessarily have to be in the .paket directory even though it is the default - quite a few projects have the bootstrapper in the tools/paket directory.

cdrnet avatar Feb 06 '15 07:02 cdrnet

I moved paket.bootstrapper.exe and paket.targets from tools directory to tools/paket directory. There are copies still in the .paket directory too. I might take a stab at changing references in the build scripts and removing that directory as well.

GradientVector avatar Feb 11 '15 02:02 GradientVector