0

I am trying to call Kentico API from LINQPad, but getting the following exception:

[AbstractProvider.GetProvider]: The object type 'cms.document' is missing the provider type configuration

My code is:

void Main()
{    
  var pages = DocumentHelper.GetDocuments("CMS.MenuItem").Path("/", PathTypeEnum.Children);
  pages.Dump();    
}

Note: I tested the code from Visual Studio, it works, but not from LINQPad.

1 Answer 1

3

The problem is that during the initial discovery Kentico looks only at the following paths:

  • AppDomain.CurrentDomain.BaseDirectory
  • AppDomain.CurrentDomain.RelativeSearchPath

Which in case of LINQPad are C:\Program Files (x86)\LINQPad4\ and null. Therefore the providers do not get resolved.

I've tried running the code in a new AppDomain but it doesn't seem to work in LINQPad. I suggest submitting this to Kentico as an idea or an issue.

A workaround to this would be copying the LINQPad executable to a location of Kentico DLLs - e.g. C:\inetpub\wwwroot\Kentico82\Lib. That works just fine.

Update (thx to Joe Albahari):

If you wrap your code in this:

var appDomain = Util.CreateAppDomain ("AD", null, new AppDomainSetup
{
    PrivateBinPath = @"C:\inetpub\wwwroot\Kentico82\CMS\bin",
});

appDomain.DoCallBack(() => { /* your code */ }); 

you'll be able to execute it. However, you can't Dump() it to the output window. But you can write it to a text file for example. If you experience the following error:

FileNotFoundException: Could not load file or assembly 'LINQPad, Version=1.0.0.0, Culture=neutral, PublicKeyToken=21353812cd2a2db5' or one of its dependencies. The system cannot find the file specified.

Go to Edit -> Preferences -> Advanced -> Run each query in its own process and turn it off.

1
  • 2
    To create an AppDomain in LINQPad, call Util.CreateAppDomain. This ensures that the newly created domain can find the LINQPad assembly and other resources needed to call methods like Dump and so on. Jul 9, 2015 at 5:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.