NullReferenceException when using Power operator
See original GitHub issueWhen 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:
- Created 9 months ago
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The new packages are up.
Can you create a new issue for this problem, and include repro steps?