Property InvalidDataException on instantiation

2

I'm using the Rustici Scorm Cloud API to generate a URL to preview some learning material:

The code creates a LaunchLinkRequestSchema object with the string field RedirectOnExitUrl populated. However, I get an InvalidDataException at the point of instantiation:

Code

var l = new LaunchLinkRequestSchema() 
{
    RedirectOnExitUrl = "https://www.example.com"
};

Exception

System.IO.InvalidDataException   HResult=0x80131501  
Message=RedirectOnExitUrl is a required property for  LaunchLinkRequestSchema and cannot be null  
Source=Com.RusticiSoftware.Cloud.V2   
StackTrace:
at Com.RusticiSoftware.Cloud.V2.Model.LaunchLinkRequestSchema..ctor(Nullable`1 Expiry, String RedirectOnExitUrl, Nullable`1 Tracking, String StartSco, String Culture, String CssUrl, List`1 LearnerTags, List`1 CourseTags, List`1 RegistrationTags, List`1 Additionalvalues)     
at ScormAPI_Tests.Program.Main() in
C:\...\Program.cs:line 26

enter image description here

enter image description here

I don't understand why I see this error, when the property is being given a value. Can anybody please explain what's happening here?

c#
instantiation
scorm-cloud-api
asked on Stack Overflow Mar 17, 2020 by EvilDr

1 Answer

2

The error is being thrown by the constructor

at Com.RusticiSoftware.Cloud.V2.Model.LaunchLinkRequestSchema..ctor

But you are supplying the value after construction via C#'s object initializers.

Object initializers are just syntactic sugar. The object is constructed first, and then they are set. It's exactly the same as doing:

var l = new LaunchLinkRequestSchema();
l.RedirectOnExitUrl = "https://www.example.com";

You need to supply the parameter in the constructor itself, it looks to be the second parameter from the exception.

eg

var l = new LaunchLinkRequestSchema(null, "https://www.example.com");
answered on Stack Overflow Mar 17, 2020 by GazTheDestroyer • edited Mar 17, 2020 by GazTheDestroyer

User contributions licensed under CC BY-SA 3.0