Fork me on GitHub
#clr
<
2023-10-09
>
Mark Pebblestream20:10:01

I'm trying to instantiate the https://nodatime.org/ Interval class and run into the following error:

user=> (Interval. (Instant.) (Instant.))
Syntax error (NullReferenceException) compiling new at (REPL:1:2).
The full exception shows:
{:type System.NullReferenceException
   :message "Object reference not set to an instance of an object."
   :at [System.Diagnostics.StackFrame GetTypeConverter "C:\\work\\clojure-clr\\Clojure\\Clojure\\Runtime\\Converter.cs" 186]}]
 :trace
 [[System.Diagnostics.StackFrame GetTypeConverter "C:\\work\\clojure-clr\\Clojure\\Clojure\\Runtime\\Converter.cs" 186]
  [System.Diagnostics.StackFrame CanConvertFrom "C:\\work\\clojure-clr\\Clojure\\Clojure\\Runtime\\Converter.cs" 69]
  [System.Diagnostics.StackFrame CanConvertFrom "NO_FILE" 0]
  [System.Diagnostics.StackFrame GetPreferredParameter "NO_FILE" 0]
  [System.Diagnostics.StackFrame GetPreferredParameters "NO_FILE" 0]
  [System.Diagnostics.StackFrame IsBest "NO_FILE" 0]
  [System.Diagnostics.StackFrame SelectBestCandidate "NO_FILE" 0]
  [System.Diagnostics.StackFrame MakeBindingTarget "NO_FILE" 0]
  [System.Diagnostics.StackFrame ResolveOverload "NO_FILE" 0]
  [System.Diagnostics.StackFrame GetMatchingMethodAux "C:\\work\\clojure-clr\\Clojure\\Clojure\\Runtime\\Reflector.cs" 309]
  [System.Diagnostics.StackFrame GetMatchingConstructor "C:\\work\\clojure-clr\\Clojure\\Clojure\\Runtime\\Reflector.cs" 258]
  [System.Diagnostics.StackFrame ComputeCtor "C:\\work\\clojure-clr\\Clojure\\Clojure\\CljCompiler\\Ast\\NewExpr.cs" 74]
  [System.Diagnostics.StackFrame Parse "C:\\work\\clojure-clr\\Clojure\\Clojure\\CljCompiler\\Ast\\NewExpr.cs" 118]
  [System.Diagnostics.StackFrame AnalyzeSeq "C:\\work\\clojure-clr\\Clojure\\Clojure\\CljCompiler\\Compiler.cs" 2089]]}
Which leads me https://github.com/clojure/clojure-clr/blob/clojure-1.11.0/Clojure/Clojure/Runtime/Converter.cs#L186 (Clojure CLR 1.11.0):
ConstructorInfo ci = Type.GetType(tca.ConverterTypeName).GetConstructor(Type.EmptyTypes);
I modified the source code and found that Type.GetType(tca.ConverterTypeName) is returning null. Printing out tca.ConverterTypeName gives:
NodaTime.Text.InstantTypeConverter, NodaTime, Version=3.1.9.0, Culture=neutral, PublicKeyToken=4226afe0d9b296d1
These are the constructors for https://github.com/nodatime/nodatime/blob/main/src/NodaTime/Interval.cs:
public Interval(Instant start, Instant end)
public Interval(Instant? start, Instant? end)
And the type has this https://github.com/nodatime/nodatime/blob/fa1e9d340743db540394689e2755d87bee027a23/src/NodaTime/Instant.cs#L36C5-L36C50:
[TypeConverter(typeof(InstantTypeConverter))]
Which leads to this https://github.com/nodatime/nodatime/blob/fa1e9d340743db540394689e2755d87bee027a23/src/NodaTime/Text/TypeConverters.cs#L19:
internal sealed class InstantTypeConverter : TypeConverterBase
Any ideas? Could it be because the InstantTypeConverter extends a generic class? Let me know what more information I can provide, or if the jira board is a more appropriate place to post this.