Custom module class issue

Tomasz Czado asked on June 14, 2017 19:37

Hi,

I have some weird issue and I don't know what exactly happens. In my solution I have defined additional console application. This project imports some datas from xml files into Kentico. To map datas from xmls I've defined custom module with custom class. Let's sey module name is Test and custom class name is Test.BlogComment. I've generated info and info provider class and then I've copied them into my console application project. C# code looks good, intellisense see all namespaces but during runtime I'm getting below error:

Object type 'Test.BlogComment' not found.

What I've already did is: - assigning custom module to site - checking custom module permissions - checking if that code works directly on Kentico project under solution

Here you have the code, that I used in my project:

var test = BlogCommentInfoProvider.GetBlogComments().FirstObject;
if (blogCommentInfo == null)
{
    blogCommentInfo = new BlogCommentInfo();
}

Stack trace doesn't explain what exactly happens:

Exception type: System.InvalidOperationException
Stack trace:
    w CMS.DataEngine.ObjectQueryBase`2.get_Object()
    w CMS.DataEngine.ObjectQueryBase`2.get_TypeInfo()
    w CMS.DataEngine.ObjectQueryBase`2.GetData()
    w CMS.DataEngine.DataQueryBase`1.get_Result()
    w CMS.DataEngine.ObjectQueryBase`2.EnsureTypedResult()
    w CMS.DataEngine.ObjectQueryBase`2.get_FirstObject()
    w TEST.BlogImporter.Program.ProcessCommentsPerParent(XmlNodeList commentNodes, TreeNode blogPostDocument, BlogCommentInfo parentBlogCommentInfo) w C:\inetpub\wwwroot\test\TEST.BlogImporter\Program.cs:wiersz 169
    w TEST.BlogImporter.Program.ProcessComments(XmlDocument xmlDocument, String fileName) w C:\inetpub\wwwroot\test\.BlogImporter\Program.cs:wiersz 118

Anyone have an idea how to resolve it?

Recent Answers


Prashant Verma answered on June 14, 2017 19:53

Hi Tomasz,

I also faced such kind of problem it mainly caused due to additional application sperate from kentico which leads in missing kentico core feature and core DLLs.

To over come such problem I mainly added the reference​ of all the kentico core ffeatures and DLL in external application.

Then completely build the solution and it works.

If this approach not resolve your issue external application code source into single kentico application it will work.

Thanks

Happy to help you

0 votesVote for this answer Mark as a Correct answer

Tomasz Czado answered on June 15, 2017 08:01

Thanks for quick reply. However it didn't help. I made some additional tests and here is what I found.

I can create and add new object to Kentico:

BlogCommentInfo b = new BlogCommentInfo { CommentID = 1, ParentCommentID = 1 };
b.Insert();

But then when I'm trying to get objects from this module, I'm getting exception (exception is in second line):

var bc = BlogCommentInfoProvider.GetBlogComments().Where("CommentID=1");
var first = bc.FirstObject;

So it looks that issue is related with ObjectQuery - but how and why?

0 votesVote for this answer Mark as a Correct answer

Prashant Verma answered on June 15, 2017 12:32

Tomasz issue occur due to class object type not bind properly kindly check with class binding documentation Custom bindings

0 votesVote for this answer Mark as a Correct answer

Tomasz Czado answered on June 15, 2017 21:54

Why do I need binding class here - it's just a custom class didn't associated with any other object? Kentico support didn't told me that.

0 votesVote for this answer Mark as a Correct answer

Suneel Jhangiani answered on June 15, 2017 22:40

Since you say you copied the Info and InfoProvider into your Console App I am guessing that your issue is that the Info and InfoProvider are not found during the Kentico initialization phase due to the missing AssemblyDiscoverable attribute.

What I would recommend is you put you Info and InfoProvider in a standalone class with the AssemblyDiscoverable attribute specified and then add a reference to it in your console application.

2 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.