question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NullReferenceException when using Power operator

See original GitHub issue

When raising a Variable to a power, using the overloaded XOR operator (^) I get a NullReferenceException.

This is minimal working example to reproduce:

using System;
using Microsoft.ML.Probabilistic.Models;

internal static class Program
{
    private static void Main()
    {
        var a = Variable.Observed(3.14);
        var b = Variable.Observed(2.0);

        var c = a ^ b;
        
        var engine = new InferenceEngine();
        var res = engine.Infer(c);
        
        Console.WriteLine(res.ToString());
    }
}

And this is the stack trace:

Compiling model...
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.ML.Probabilistic.Compiler.Transforms.StocAnalysisTransform.InferMarginalPrototype(IMethodInvokeExpression imie, IExpression target, Object targetDecl)
   at Microsoft.ML.Probabilistic.Compiler.Transforms.StocAnalysisTransform.InferMarginalPrototype(IAssignExpression iae, Boolean targetHasLiteralIndices)
   at Microsoft.ML.Probabilistic.Compiler.Transforms.StocAnalysisTransform.ConvertAssign(IAssignExpression iae)
   at Microsoft.ML.Probabilistic.Compiler.Transforms.ShallowCopyTransform.ConvertExpression(IExpression expr)
   at Microsoft.ML.Probabilistic.Compiler.Transforms.ShallowCopyTransform.ConvertExpressionStatement(IExpressionStatement ies)
   at Microsoft.ML.Probabilistic.Compiler.Transforms.ShallowCopyTransform.ConvertStatement(IStatement ist)
   at Microsoft.ML.Probabilistic.Compiler.Transforms.ShallowCopyTransform.ConvertStatements(IList`1 outputs, IEnumerable`1 inputs)
   at Microsoft.ML.Probabilistic.Compiler.Transforms.ShallowCopyTransform.DoConvertMethod(IMethodDeclaration md, IMethodDeclaration imd)
   at Microsoft.ML.Probabilistic.Compiler.Transforms.ShallowCopyTransform.ConvertMethod(IMethodDeclaration imd)
   at Microsoft.ML.Probabilistic.Compiler.Transforms.ShallowCopyTransform.ConvertMethods(ITypeDeclaration td, ITypeDeclaration itd)
   at Microsoft.ML.Probabilistic.Compiler.Transforms.ShallowCopyTransform.ConvertType(ITypeDeclaration itd)
   at Microsoft.ML.Probabilistic.Compiler.CodeTransformer.TransformToDeclaration(ITypeDeclaration typeDecl)
   at Microsoft.ML.Probabilistic.Compiler.TransformerChain.TransformToDeclaration(ITypeDeclaration itd, AttributeRegistry`2 inputAttributes, Boolean trackTransform, Boolean showProgress, List`1& warnings, Boolean catchExceptions, Boolean treatWarningsAsErrors)
   at Microsoft.ML.Probabilistic.Compiler.ModelCompiler.GetTransformedDeclaration(ITypeDeclaration itd, MethodBase method, AttributeRegistry`2 inputAttributes)
   at Microsoft.ML.Probabilistic.Compiler.ModelCompiler.CompileWithoutParams(ITypeDeclaration itd, MethodBase method, AttributeRegistry`2 inputAttributes)
   at Microsoft.ML.Probabilistic.Models.InferenceEngine.Compile()
   at Microsoft.ML.Probabilistic.Models.InferenceEngine.GetCompiledInferenceAlgorithm(Boolean inferOnlySpecifiedVars, IVariable var)
   at Microsoft.ML.Probabilistic.Models.InferenceEngine.Infer(IVariable var)
   at Program.Main()

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
tminkacommented, Jan 3, 2023

The new packages are up.

0reactions
tminkacommented, Feb 20, 2023

Can you create a new issue for this problem, and include repro steps?

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - How do I avoid NullReferenceException when ...
I can't put if (lhs != null) in operator== because that causes infinite recursion (as the book warns). So in order to avoid...
Read more >
Getting errors with null fields - Power Automate
If you're still getting a runtime error, it may be caused by reference null properties in an object. You should use the question...
Read more >
Expression.Error: We cannot apply operator .. to types Null ...
I'm getting the following error when trying expand table when merging two tables in Power Query in Power BI. The problem persist with...
Read more >
Checking for null in C#, using the null-conditional and ...
The null-conditional operator allows you to call a deeply-nested class member, where anything in the chain of objects might be null, and it ......
Read more >
Object Reference Not Set to an Instance of an Object
1. Initialize variables with valid values. · 2. If a variable can be null, then check for null and handle it appropriately ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found