Tan Woods
Tan Woods

Reputation: 1

Using Kentico API from LINQPad is throwing an exception

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.

Upvotes: 0

Views: 241

Answers (1)

rocky
rocky

Reputation: 7696

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.

Upvotes: 3

Related Questions