Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jimmy 19 posts 118 karma points
    May 17, 2024 @ 15:49
    Jimmy
    0

    The type initializer for 'Umbraco.Extensions.FriendlyPublishedContentExtensions' threw an exception.

    Hi

    I am trying to build some test for my Umbraco site.

    I created a document type with 5 new properties. All is running as i would expect it to run.

    I now add the below code for testing

     var pp = new Mock<IPublishedProperty>();
     var pub = new Mock<IPublishedContent>();
    
     pub.Setup(x => x.Name).Returns("Test");
     pub.Setup(x => x.Id).Returns(1234);
    
     pp.Setup(x => x.Alias).Returns("CustomerName");
     pp.Setup(x => x.Alias).Returns("Age");
     pp.Setup(x => x.GetValue(It.IsAny<string>(), It.IsAny<string>())).Returns("My Customer");
     pub.Setup(x => x.GetProperty("customerName")).Returns(pp.Object);
     pub.Setup(x => x.GetProperty("age")).Returns(pp.Object);
    
     var cust = new Customer(pub.Object, _publishedFallbackValue.Object);
    

    myService.CallMethod(cust);

    When it goes into the CallMethod in myService (which expects an IPublishedContent which is then casted), it throws the error

    System.TypeInitializationException: 'The type initializer for 'Umbraco.Extensions.FriendlyPublishedContentExtensions' threw an exception.' ArgumentNullException: Value cannot be null. ArgParamNameName

    Ive tried various changes and have seen some threads here but non work. Any pointers on what im missing?

Please Sign in or register to post replies

Write your reply to:

Draft