More in this section
Forums / Bugs & Issues / System.Reflection.TargetInvocationException caught on creating new Project

System.Reflection.TargetInvocationException caught on creating new Project

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
6 posts, 0 answered
  1. tim
    tim avatar
    8 posts
    Registered:
    30 Nov 2015
    02 Feb 2016
    Link to this post

    private Product MakeProduct2()
    {
    Product product = new Product();
    product.Title.SetString(CultureInfo.CurrentCulture, "title");
    return product;
    }

    Crash at SetString (trace at end of this).

    VS2015 SP1

    Sitefinity 8.2.5910.0

     

    System.Reflection.TargetInvocationException was unhandled by user code
      HResult=-2146232828
      Message=Exception has been thrown by the target of an invocation.
      Source=mscorlib
      StackTrace:
           at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
           at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
           at System.Activator.CreateInstance(Type type, Boolean nonPublic)
           at System.Activator.CreateInstance(Type type)
           at Telerik.Sitefinity.Model.DataExtensions.get_AppSettings()
           at Telerik.Sitefinity.Model.DataExtensions.GetString(IDynamicFieldsContainer dataItem, String fieldName)
           at Telerik.Sitefinity.Ecommerce.Catalog.Model.Product.get_Title()
           at Certas.Sitefinity.Application.SitefinityCms.Tests.SitefinityProductRepositoryTests.MakeProduct2() in C:\Workspaces\GitHub\Certas\Certas.Sitefinity.Application.SitefinityCms.Tests\SitefinityProductRepositoryTests.cs:line 86
           at Certas.Sitefinity.Application.SitefinityCms.Tests.SitefinityProductRepositoryTests.CreateProduct_Returns_Guid() in C:\Workspaces\GitHub\Certas\Certas.Sitefinity.Application.SitefinityCms.Tests\SitefinityProductRepositoryTests.cs:line 31
      InnerException: 
           HResult=-2147467261
           Message=Object reference not set to an instance of an object.
           Source=Telerik.Sitefinity
           StackTrace:
                at Telerik.Sitefinity.Abstractions.ObjectFactory.GetArgsByName(String name, Type baseType)
                at Telerik.Sitefinity.Configuration.Config.VerifySectionRegistered(Type sectionType, String sectionName)
                at Telerik.Sitefinity.Configuration.Config.GetSectionInternal(Type sectionType, Boolean safeMode, String sectionName)
                at Telerik.Sitefinity.Configuration.Config.GetSectionPrivate(Type sectionType, Boolean safeMode, String sectionName)
                at Telerik.Sitefinity.Configuration.Config.GetSectionPrivate[TSection](Boolean safeMode)
                at Telerik.Sitefinity.Configuration.Config.Get[TSection](Boolean safeMode)
                at Telerik.Sitefinity.Configuration.Config.Get[TSection]()
                at Telerik.Sitefinity.Abstractions.AppSettings..ctor()
           InnerException: 

  2. tim
    tim avatar
    8 posts
    Registered:
    30 Nov 2015
    02 Feb 2016
    Link to this post
    Additional: This is in a Nunit testing session and I am using DI/IoC in the main project.
  3. Svetoslav Manchev
    Svetoslav Manchev avatar
    735 posts
    Registered:
    06 Sep 2017
    05 Feb 2016
    Link to this post
    Hi Tim,

    Can you try to create a product/product depending on your needs as described in the respective article:
    http://docs.sitefinity.com/for-developers-create-products
    http://docs.sitefinity.com/for-developers-create-product-types

    I hope this helps.

    Regards,
    Svetoslav Manchev
    Telerik
     
    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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  4. tim
    tim avatar
    8 posts
    Registered:
    30 Nov 2015
    05 Feb 2016 in reply to Svetoslav Manchev
    Link to this post

    I started from that example.

    In-house we use dependency-injection extensively and need to Mock classes to support testing, we follow TDD as a standard development paradigm.

  5. Arno
    Arno avatar
    249 posts
    Registered:
    08 Sep 2010
    04 Dec 2016
    Link to this post
    Did you ever solve this Tim? Unit tests in a Sitefinity project seem to be pretty problematic. I'm getting the same exception on Telerik.Sitefinity.Taxonomies.TaxonomyManager.GetManager().
  6. tim
    tim avatar
    8 posts
    Registered:
    30 Nov 2015
    09 Dec 2016 in reply to Arno
    Link to this post

    Hi Arno,

    For some managers we managed to use the constructor that took a parameter which we had mocked, we use Moq normally. However in not all cases was this successful/possible.

6 posts, 0 answered