3

I am encountering a "Could not load file or assembly... ... The system could not find the file specified" error when trying to consume my type provider.

The error appears on building the consuming application but does not show up as a 'red squiggly' in visual studio prior to the build.

I have copied my TP below but the issue occurs inside the Database.listDbs call and I strongly suspect the issue is not the code below but how I am packaging the dependencies.

I call into the Microsoft.Azure.DocumentDB package which, in turn, depends on Newtonsoft.Json. It is the Newtonsoft.Json package which cannot be found. I am using Paket to manage dependencies and have redirects on.

The full code (including all the paket files) is on github here: https://github.com/stewart-r/AzureDocumentDbTypeProvider/tree/dependency-issue

I found this question which seems very similar but the solution did not make any difference.

My TP code is as follows:

namespace ProviderImplementation

open ProviderImplementation.ProvidedTypes
open Microsoft.FSharp.Core.CompilerServices
open System.Reflection
open System
open Config
open Database

[<TypeProvider>]
type public DocumentDbTypeProvider(config: TypeProviderConfig) as this = 
    inherit TypeProviderForNamespaces()

    let thisAssembly = Assembly.GetExecutingAssembly()
    let docDbType = ProvidedTypeDefinition(thisAssembly,namespaceName,"DocumentDbTypeProvider", baseType = Some typeof<obj>)

    let initFn (typeName : string) (args : obj []) = 
        let acProvidedType = ProvidedTypeDefinition(thisAssembly, namespaceName, typeName, baseType = Some typeof<obj>)
        acProvidedType.AddMember(ProvidedConstructor(parameters = [], InvokeCode = (fun args -> <@@ null @@>)))

        let getDbProperties () = 
            Database.listDbs (args.[0] :?> string) (args.[1]:?> string)
            |> List.map(fun d -> new ProvidedProperty(d.Name, typeof<string>, IsStatic = true, GetterCode = (fun _ -> <@@ "Test db name" @@>)))
        acProvidedType.AddMembers(getDbProperties())
        acProvidedType

    let parameters = 
        [ ProvidedStaticParameter("accountEndPointUri", typeof<string>, String.Empty)
          ProvidedStaticParameter("accountKey", typeof<string>, String.Empty)]

    do
        docDbType.DefineStaticParameters(parameters,initFn)
        this.AddNamespace(namespaceName,[docDbType])

[<TypeProviderAssembly>]
do ()
Community
  • 1
  • 1
Stewart_R
  • 13,764
  • 11
  • 60
  • 106

2 Answers2

2

This is a binding redirect issue - you need to handle the BR inside the type provider. Alternatively, you can restrict the dependencies to the minimum version needed by your direct dependency e.g. DocumentDB.

Isaac Abraham
  • 3,422
  • 2
  • 23
  • 26
0

Have you tried making sure that your "TP dependencies are located in the same folder that the TP itself resides in"?

It sounds like you have the same issue as described in this answer: https://stackoverflow.com/a/33889287/371698 (quote from this answer)

Community
  • 1
  • 1
Isak
  • 1,591
  • 1
  • 17
  • 23
  • 1
    I think I am missing the point with this - lot's of people suggesting that I need to ensure the dependency dlls are in the same folder as the DLL but isn't this the default behaviour anyway? Without doing anything special, if I build the TP the TP dll and all the nuget package dlls all get copied to /bin/debug by default. If I reference the TP in that folder I still get the above error. Am I missing the point here? – Stewart_R Jul 18 '16 at 06:28