Does LinqPad support libraries using MEF?

edited May 2012
Hi!

I'd like to use the Simple.Data library but it doesn't work in LinqPad (but it does in VS). I tried manually add all the references and even with NuGet but I get the same result.

To reproduce:
- NuGet the package Simple.Data.SqlCompact40
- Code: var db = Database.OpenFile("Test.sdf");

Take a look at the exception's call stack -> Simple.Data.MefHelper.Compose[T](String contractName)

Comments

  • What's happening is that the Simple.Data NuGet package comprises a primary assembly + two dependencies, so LINQPad ends up referencing three assemblies, each in different folders. This would normally work, except that Simple.Data uses a discovery machanism which relies on the assemblies being in the same folder. (I presume this discovery mechanism is related to MEF.)

    The reason it works in Visual Studio is that Visual Studio copies all referenced assemblies into bin\debug. I could make LINQPad do the same, although it would incur a small performance hit. This is one of the reasons that creating & running a LINQPad query is faster than creating and running a VS project.

    A simple workaround for now is to reference the three assemblies from a single folder (such as your VS project's bin\debug folder).

    I'm not sure how best to solve this properly. Obviously LINQPad could treat all NuGet references as "copy local", but this would be a waste in the majority of cases where the referenced assemblies need not be in the same folder. Or I can make it a query-level option, but then how would users know when to use it?

    Another option is to copy local if any of the assemblies reference System.ComponentModel.Composition.dll. I don't know whether this problem is largely isolated to when MEF is in use.
  • I came to the same conclusion of the discovery mechanism of MEF and the fact that I had doubts LinqPad was copying references to a bin\Debug like folder.

    I was thinking of a work around. Merging all three packages into one and serving it from the file system in a private NuGet feed. I just need to find a tool or write my own if possible. Maybe this work around could be a real solution in LinqPad to this problem in the future if you start to get more feedback on this issue.
  • The next beta will enable copy-local shadowing if any of the packages reference System.ComponentModel.Composition.dll, so there won't be issues with MEF. Stay posted.
  • I have been trying to use MEF & LinqPad. When I start LinqPad and run my query it works the first time.
    If I then change the code it compiles to the same output folder with a set of new c# files but it is also leaving the previous query code there. Now when I run the query MEF will fail as it finds the same plugins defined more than once.
    Is there a way to tell LinqPad to clear the folder each time?
  • You could try enabling "Always use fresh application domains" in Edit | Preferences | Advanced. This will allow LINQPad to clean up faster, although it won't delete assemblies that you explicitly create (as it doesn't know about them).
Sign In or Register to comment.