This is a migrated thread and some comments may be shown as answers.

FunctionManager.RegisterFunction exception in .NET 5.0

1 Answer 86 Views
SpreadProcessing
This is a migrated thread and some comments may be shown as answers.
Dmitry
Top achievements
Rank 1
Dmitry asked on 21 Jan 2021, 07:52 AM

While evaluating Telerik.Documents.Spreadsheet.Trial (2021.1.118) I've encountered a bug with registering custom functions in .NET 5.

 

I'm using a console application, and trying to register a couple of functions right at the start of the Main() method. It works like a charm with target framework netcoreapp3.1.

But as soon as I bump the version to net5.0, registering a function throws an exception (I've copied the full stack below).

Perhaps you can guide me what happens? We're currently evaluating on upgrading our license for the latest features, but this thing could be crucial to us, since we need to use .NET 5 for a couple of reasons.

 

I'm calling them right at the start of the applicaption

public static void Main(string[] args)
{
  FunctionManager.RegisterFunction(new AAA());
  FunctionManager.RegisterFunction(new BBB());
  ...
}

 

Here's the exception stack:

Unhandled exception. System.TypeInitializationException: The type initializer for 'Telerik.Windows.Documents.Spreadsheet.Expressions.Functions.FunctionManager' threw an exception.
 ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.TypeInitializationException: The type initializer for 'Telerik.Windows.Documents.Spreadsheet.Expressions.Functions.Db' threw an exception.
 ---> System.ArgumentOutOfRangeException: Index and count must refer to a location within the string. (Parameter 'count')
   at System.String.Remove(Int32 startIndex, Int32 count)
   at Telerik.Windows.Documents.Spreadsheet.Formatting.FormatHelper.FindAllOccurrences(String value, String part)
   at Telerik.Windows.Documents.Spreadsheet.Formatting.FormatHelper.ReplaceSeparators(String formatString, Predicate`1 shouldReplaceWithGroupSeparator, Predicate`1 shouldReplaceWithDecimalSeparator, String newGroupSeparat
or, String newDecimalSeparator)
   at Telerik.Windows.Documents.Spreadsheet.Formatting.FormatHelper.ReplaceCultureSpecificSeparatorsWithDefaults(String formatString, Nullable`1 formatStringCategory)
   at Telerik.Windows.Documents.Spreadsheet.Model.CellValueFormat..ctor(String formatString, Boolean convertToInvariant, Nullable`1 formatStringCategory)
   at Telerik.Windows.Documents.Spreadsheet.Model.CellValueFormat..ctor(String formatString)
   at Telerik.Windows.Documents.Spreadsheet.Expressions.Functions.Db..cctor()
   --- End of inner exception stack trace ---
   at Telerik.Windows.Documents.Spreadsheet.Expressions.Functions.Db..ctor()
   --- End of inner exception stack trace ---
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean wrapExceptions, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& hasNoDefaultCtor)
   at System.RuntimeType.CreateInstanceDefaultCtorSlow(Boolean publicOnly, Boolean wrapExceptions, Boolean fillCache)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type)
   at Telerik.Windows.Documents.Spreadsheet.Expressions.Functions.FunctionManager..cctor()
   --- End of inner exception stack trace ---
   at Telerik.Windows.Documents.Spreadsheet.Expressions.Functions.FunctionManager.RegisterFunction(FunctionBase function)
   at Iface.Oik.ScriptEngine.Program.Main(String[] args) in C:\Users\alexeid\Rider\Iface.Oik.ScriptEngine\src\Program.cs:line 20

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 25 Jan 2021, 11:01 AM

Hello Dmitry,

Since this is a console app that does not include the Windows dependencies (for example desktop apps contain the Windows API by default), you should use the assemblies for .NET Standard because they do not depend on the Windows API. Their names are different (does not contain Windows). The easiest way is to get them is as NuGet packages: NuGet packages.

I hope this helps. Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
SpreadProcessing
Asked by
Dmitry
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or