More in this section

Forums / Bugs & Issues / TypeInitializer exception with Libraries.GetManager()

TypeInitializer exception with Libraries.GetManager()

14 posts, 0 answered
  1. G S S
    G S S avatar
    71 posts
    Registered:
    16 Mar 2008
    27 Mar 2011
    Link to this post

    Hi,

    I have the following code in a console application to work with Sitefinity 4.0 RC:

                    LibrariesManager libManager = LibrariesManager.GetManager();

    When I step through the above line of code, I get the exception below:

    {"The type initializer for 'Telerik.Sitefinity.Modules.Libraries.LibrariesManager' threw an exception."}

    In particular, the InnerException is:

    {"Value cannot be null.\r\nParameter name: path1"}

    Am I doing something wrong or is this a Sitefinity bug? I have not posted the remaining code as this line of code doesn't use other fields I have in my class.

     

    Thanks

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    30 Mar 2011
    Link to this post
    Hello G S S,

    Use a web service call from the console application. The our API is supposed to work in web environment, since you are trying to use it for desktop.

    Regards,
    Ivan Dimitrov
    the Telerik team
  3. G S S
    G S S avatar
    71 posts
    Registered:
    16 Mar 2008
    03 Apr 2011
    Link to this post
    Hi,

    What do you mean by console application? The Sitefinity UI?

    Also, I am supposed to save the content through the Content object, so how do I do this then?

    Is it not possible to see a code sample of the process to upload content in an automated fashion? I've been trying for ages to upload content but with no help/examples!
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    05 Apr 2011
    Link to this post
    Hello G S S,

    "I have the following code in a console application .. "

    http://en.wikipedia.org/wiki/Console_application

    You can take a look at our SDK, Jobs module where you will find a sample that shows how to create /upload document item.

    You can use LibrariesManager.Upload(MediaContent content, Stream source, string extension) method.

    Regards,
    Ivan Dimitrov
    the Telerik team

  5. G S S
    G S S avatar
    71 posts
    Registered:
    16 Mar 2008
    06 Apr 2011
    Link to this post
    Hi,

    Sorry, I forgot that I mentioned console. Anyway, I looked at the job module and found this code:

                   using (var sf = App.Prepare().SetTransactionName("UploadTransaction").WorkWith())
                {
                
                         sf.Document().CreateNew().Do(item =>
                        {
                            item.Parent = sf.DocumentLibraries().Where(l => l.Title == "Default Library").Get().FirstOrDefault();
                            item.Title = "test";
                            item.SetValue("FirstName""s");
                       
                            item.SetValue("LastName""S");
                            item.SetValue("Phone""s");
                            item.SetValue("HowDidYouHear""s");
                        }).CheckOut().UploadContent(GetStream(new FileInfo(@"C:\Test\test.rar")), ".rar").CheckInAndPublish();
                }


    Even so, this throws an exception at the second line (same type). This doesn't work either?
  6. G S S
    G S S avatar
    71 posts
    Registered:
    16 Mar 2008
    08 May 2011
    Link to this post
    Is there a fix for the above?
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    09 May 2011
    Link to this post
    Hi G S S,

    You do not have a reference to the LibrariesManager in the console application.
    You can also use our wcf services to make a requests to Sitefinity

    http://www.sitefinity.com/40/help/developers-guide/deep-dive-client-side-programming-restful-wcf-services-in-sitefinity.html

    You can use WebRequest or Sys.Net.WebRequest();

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. G S S
    G S S avatar
    71 posts
    Registered:
    16 Mar 2008
    01 Jun 2011
    Link to this post
    Hi,

    I will try WCF to do what I need, or add the missing reference to my console project (I'll see what that needs).

    Can you provide a C# sample of how the code would look to upload a document via WCF to Sitefinity?

    Thanks
  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    02 Jun 2011
    Link to this post
    Hi G S S,

    1. You need to authenticate yourself, because you cannot use our service with an anonymous account
    2. You can check the service methods typing

    Sitefinity/Services/Content/ImageService.svc/help

    after the website host.

    3. You would not be able to call the service using ClientManager or jQuery ajax. You need to use WebRequest from console application or some control.



    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  10. G S S
    G S S avatar
    71 posts
    Registered:
    16 Mar 2008
    08 Jun 2011
    Link to this post
    Hi,

    I will use the Credentials class to authenticate.
    I will try webrequest.

    I will save content and get the GUID and use that in the querystring.
  11. G S S
    G S S avatar
    71 posts
    Registered:
    16 Mar 2008
    08 Jun 2011
    Link to this post
    BTW, I also saw this in the jobs starter site:

     

     

    App.WorkWith().Pages().Where(p => p.Id == pageId).Count(out count);

     

     

     

     

    if (count == 0)

     

     

    {

     

     

     

    var templateId = SampleUtilities.RegisterDefaultSamplesThemeAndTemplate();

     

     

     

     

    App.WorkWith().Page()

     

     

    .CreateNewStandardPage(

    .CreateNewStandardPage

     

    PageLocation.Frontend, pageId, pageDataId)

     

     

    .Do(p =>

    .Dop=>

    {

     

    p.Title = pageName;

    p.Name = pageName;

    p.UrlName = pageName;

    p.ShowInNavigation =

    p.Title=pageNamep.Name=pageNamep.UrlName=pageNamep.ShowInNavigation=

     

    true;

     

     

    p.DateCreated =

     

    DateTime.UtcNow;

     

     

    p.LastModified =

    p.LastModified=

     

    DateTime.UtcNow;

     

     

    p.Page.HtmlTitle = pageName;

    p.Page.Title = pageName;

    p.Description =

    p.Page.HtmlTitle=pageNamep.Page.Title=pageNamep.Description=

     

    "This is a home page created for a specific Sitefinity Sample.";

     

     

    })

     

    .CheckOut()

    .SetTemplateTo(templateId)

    .Control()

    .CreateNew(widget,

     

    "Content")

     

     

    .SaveChanges()

     

    .Done()

     

    .Publish()

     

    .SaveChanges();



    I am looking to do the same thing (maybe with another content type), isn't the above exactly what I need?
  12. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    13 Jun 2011
    Link to this post
    Hi G S S,

    If you are not authenticated you cannot use our WCF services. For each content items we have difference facade that you can use. You can check this by typing App.WorkWith() in VS.

    Creating and editing objects also requires that you should authenticate a valid user with the proper permissions. Another option is using RPC - create a standard web service in Sitefinity 4.x website with the api methods where you use the managers or fluent API and access this service from your other application.

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  13. G S S
    G S S avatar
    71 posts
    Registered:
    16 Mar 2008
    13 Jun 2011
    Link to this post
    Maybe I'll try the RPC approach. The service in IIS will be RPC but I will invoke this from outside, correct?

    RE authentication - is this done programatically via the Sitefinity API?
  14. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    13 Jun 2011
    Link to this post
    Hello G S S,

    If you use RPC you don't need to authenticate the user, since the code will execute inside Sitefinity application and you can call Provider.SuppressSecurityChecks = true for the provider you are going to use. After you complete the operation you use set the security checks back to false which is the default value.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
14 posts, 0 answered