microsoft / AL

Home of the Dynamics 365 Business Central AL Language extension for Visual Studio Code. Used to track issues regarding the latest version of the AL compiler and developer tools available in the Visual Studio Code Marketplace or as part of the AL Developer Preview builds for Dynamics 365 Business Central.
MIT License
744 stars 245 forks source link

Error while publishing object: "Object reference not set to an instance of an object." #4002

Closed gntpet closed 5 years ago

gntpet commented 6 years ago

Hey Guys, While publishing extensions i keep getting this error: 'Object reference not set to an instance of an object.'.

I cannot find the source file that it's causing it (i have >1650 files in my project). I'm seeking for advice how to find the file causing the issue.

I thought by enabling CodeAnalyzers will help to find the root cause. It gave some hint, but still not enough to identify the file that it's causing it. CodeAnalyzer shows errors with similar message but it's linked with app.json file, not the file that it's causing it:

Analyzer 'Microsoft.Dynamics.Nav.CodeCop.Readability.Rule005OnlyUseBeginEndForCompoundStatements' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'",

full message:

{
    "resource": "/c:/Users/gps/Documents/Repositories/MV-AL/app.json",
    "owner": "_generated_diagnostic_collection_name_#0",
    "code": "AD0001",
    "severity": 4,
    "message": "Analyzer 'Microsoft.Dynamics.Nav.CodeCop.Readability.Rule005OnlyUseBeginEndForCompoundStatements' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'",
    "source": "AL",
    "startLineNumber": 1,
    "startColumn": 1,
    "endLineNumber": 1,
    "endColumn": 1
}

In addition, I checked event viewer for error messages. There's a very long exception related to evaluate. Not sure if CodeAnalyzer, and EventViewer messages are related to the same issue. But this is all i have for now.

RootException: NullReferenceException
ExceptionStackTrace:
   at Microsoft.Dynamics.Nav.Runtime.NavDateEvaluator.DayMonthYearEvaluate(NavDate& value, String source, Int32 position, Boolean isClosingDate, String originalString)
   at Microsoft.Dynamics.Nav.Runtime.NavDateEvaluator.InternalEvaluate(DataError dataError, NavDate& value, INavValueMetadata metadata, String source, Int32 number)
   at Microsoft.Dynamics.Nav.Runtime.NavValueEvaluator`1.Evaluate(DataError dataError, T& value, INavValueMetadata metadata, String source, Int32 number)
   at Microsoft.Dynamics.Nav.Runtime.NavValueEvaluator`1.Evaluate(DataError dataError, NavValue& value, INavValueMetadata metadata, String source, Int32 number)
   at Microsoft.Dynamics.Nav.Runtime.ALSystemVariable.EvaluateIntoNavValue(DataError dataError, INavValueMetadata metadata, String source, Int32 number)
   at Microsoft.Dynamics.Nav.Runtime.FilterExpressionParser.ValueFilterExpression.TryGetValue(NavValue& parsedValue, NavBaseException& exception, DataError dataError)
   at Microsoft.Dynamics.Nav.Runtime.FilterExpressionParser.ValueFilterExpression.ToExpression(Boolean negated, Boolean useOnlyVariableResolver, DataError dataError)
   at Microsoft.Dynamics.Nav.Runtime.FilterExpressionParser.Parse(Boolean useOnlyVariableResolver, DataError dataError)
   at Microsoft.Dynamics.Nav.Runtime.FilterExpressionParser.ParseFilterTokensWithoutBalancing(List`1 filterTokens, FilterExpressionContext expressionContext, Func`3 customVariableResolver, Int32 unknownVariableResolverDepth, NavValue[] values, Int32& expressionLeafCount, Boolean& hasVariables, Boolean useOnlyVariableResolver, Boolean cultureInvariant, DataError dataError)
   at Microsoft.Dynamics.Nav.Runtime.FilterExpressionParser.ParseWithoutBalancing(String expression, FilterExpressionContext expressionContext, Func`3 customVariableResolver, Int32 unknownVariableResolverDepth, NavValue[] values, Int32& expressionLeafCount, Boolean& hasVariables, Boolean cultureInvariant, DataError dataError)
   at Microsoft.Dynamics.Nav.Runtime.FilterExpressionParser.Parse(String expression, FilterExpressionContext expressionContext, Func`3 customVariableResolver, Int32 unknownVariableResolverDepth, Boolean& hasVariables, NavValue[] values, Boolean cultureInvariant)
   at Microsoft.Dynamics.Nav.Runtime.FilterExpressionParser.Parse(String expression, FilterExpressionContext expressionContext, Boolean allowExpressionEvaluation, Boolean& hasVariables, NavValue[] values)
   at Microsoft.Dynamics.Nav.Runtime.NCLMetaQuery.CreateTableFiltersAndMarksFromDataItemFieldFilters(NCLMetaQueryDataItem dataItemBeingCreated, List`1 fieldFilters, Boolean allowExpressionEvaluation, Boolean& tableFilterHasVariables)
   at Microsoft.Dynamics.Nav.Runtime.NCLMetaQuery.<>c__DisplayClass61_1.<CreateDataItemsFromDesignMetadata>b__1(NCLMetaQueryDataItem dataItemBeingCreated)
   at Microsoft.Dynamics.Nav.Runtime.NCLMetaQueryDataItem..ctor(NCLMetaQueryDefinition parentQueryDefinition, DataItemLinkType dataItemLinkType, Int32 tableNo, DataLockState lockState, String name, Func`2 queryColumnsCreator, Func`2 tableFiltersAndMarksCreator, Func`2 dataItemLinksCreator, List`1 metaQueryFieldFilters, Int32 appGroup)
   at Microsoft.Dynamics.Nav.Runtime.NCLMetaQuery.CreateDataItemsFromDesignMetadata(NCLMetaQueryDefinition parentQueryDefinition, MetaQuery metaQuery, Boolean allowExpressionEvaluation, Boolean& tableFilterHasVariables)
   at Microsoft.Dynamics.Nav.Runtime.NCLMetaQuery.<>c__DisplayClass62_1.<ParseMetadata>b__0(NCLMetaQueryDefinition queryDefinitionBeingCreated)
   at Microsoft.Dynamics.Nav.Runtime.NCLMetaQueryDefinition..ctor(NCLMetaQueryDataItem parentDataItem, Int32 topRows, Func`2 dataItemsCreator, Func`2 orderBysCreator)
   at Microsoft.Dynamics.Nav.Runtime.NCLMetaQuery.ParseMetadata(MetaQuery metaQuery, Boolean allowExpressionEvaluation)
   at Microsoft.Dynamics.Nav.Runtime.NCLMetaQuery.LoadMetadata()
   at Microsoft.Dynamics.Nav.Runtime.NCLMetaApplicationObject.Populate()
   at Microsoft.Dynamics.Nav.Runtime.NCLMetadata.InitializeAppGroupNewObject(NavAppGroup appGroup, NavAppGroupObjectMetadataSummary newObjectSummary)
   at Microsoft.Dynamics.Nav.Runtime.NCLMetadata.InitializeNewAppQueries(NavAppGroup appGroup, InitializeAppGroupProfiler profiler, IReadOnlyList`1 newObjectsFromApps)
   at Microsoft.Dynamics.Nav.Runtime.NCLMetadata.InitializeAppGroup(NavAppGroup appGroup)
   at Microsoft.Dynamics.Nav.Runtime.NavAppSyncManagementTasks.SyncNavApp(SyncNavAppArguments args)
CallerStackTrace:
   at Microsoft.Dynamics.Nav.Diagnostic.NavDiagnostics.ComposeAndSendExceptionTraceTag(String tag, Category category, Exception exception, DiagnosticParameter message, Verbosity verbosity, Guid clientSessionId, Guid clientActivityId, String diagnosticsContext, Boolean forceLog)
   at Microsoft.Dynamics.Nav.Diagnostic.NavDiagnostics.SendExceptionTag(String tag, Category category, Exception exception, Verbosity verbosity, DiagnosticParameter message, String diagnosticsContext, Boolean forceLog)
   at Microsoft.Dynamics.Nav.Runtime.NavAppSyncManagementTasks.SyncNavApp(SyncNavAppArguments args)
   at Microsoft.Dynamics.Nav.Service.NSAdminService.<>c__DisplayClass132_0.<Microsoft.Dynamics.Nav.Types.ITenantDatabaseManagementService.SyncNavApp>b__0()
   at Microsoft.Dynamics.Nav.Runtime.NavSqlTransientErrorHelper.<>c__DisplayClass2_0`1.<RetryOperationWithTransientError>b__0()
   at Microsoft.Dynamics.Nav.Runtime.NavSqlTransientErrorHelper.InternalRetryOperationWithTransientError[T](Action operation, Int32 maxRetryCount, Int32 retryIntervalInSeconds, String callerName, String additionaInfo, Boolean expectedType)
   at Microsoft.Dynamics.Nav.Runtime.NavSqlTransientErrorHelper.RetryOperationWithTransientError[T](Func`1 operation, Int32 maxRetryCount, Int32 retryIntervalInSeconds, String caller, String additionalContext)
   at Microsoft.Dynamics.Nav.Service.NSAdminService.Microsoft.Dynamics.Nav.Types.ITenantDatabaseManagementService.SyncNavApp(SyncNavAppArguments syncNavAppArguments)
   at Microsoft.Dynamics.Nav.Service.Dev.DevService.SyncNavApp(NavAppManifest manifest, String tenantId, NavAppSyncMode mode)
   at Microsoft.Dynamics.Nav.Service.Dev.DevService.<>c__DisplayClass6_1.<PublishAndInstallExtension>b__0()
   at Microsoft.Dynamics.Nav.Service.Dev.DevService.PublishAndInstallExtension(NavSession session, Stream packageStream, PerformanceLog performanceLog, SchemaUpdateMode schemaUpdateMode)
   at Microsoft.Dynamics.Nav.Service.Dev.Web.Controllers.AppsController.<PublishAndInstall>d__0.MoveNext()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.Run()
   at Microsoft.Dynamics.Nav.Runtime.NavSynchronizationContext.<>c__DisplayClass1_0.<ClearThreadLocalStorageDelegate>b__0(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()

Best Regards, Gintautas

StanislawStempin commented 6 years ago

This looks like a bug in the analyzer rule.

AndreyKorepanov commented 5 years ago

@gintuoklis Thank you for reporting the issue. It is not easy to catch it, but it seems to be fixed recently. Could you try to reproduce it with the latest daily build?

gntpet commented 5 years ago

hey @AndreyKorepanov, I started our AL conversion project all other again with the latest AL tools. At the moment I am stuck with another bug #4127, which is showstopper at the moment.

Nevertheless, I tried to enable CodeCop Analyzis for my project to see if I still get Rule005OnlyUseBeginEndForCompoundStatements error. This particular error has disappeared, but instead I got few new ones :) So i am not sure now if you solved the issue, or something changed in other tools that fixed my code (exporttonewsytanx, txt2al...)

Regarding new errors, here they are:

Analyzer 'Microsoft.Dynamics.Nav.CodeCop.Readability.Rule021VariableDeclarationsShouldBeOrderedByType' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'

Analyzer 'Microsoft.Dynamics.Nav.CodeCop.Design.Rule139DoNotAssignToStringWithSmallerCapacity' threw an exception of type 'System.IndexOutOfRangeException' with message 'Index was outside the bounds of the array.'

I cannot identify code line that it is causing these errors.

Should i make new bugs for those two?

Best Regards, Gintautas

AndreyKorepanov commented 5 years ago

Hi @gintuoklis thank you for reply and reporting more bugs. You do not need to create new bugs for those two, but it would be nice if you could provide the exception stack trace for them.

AndreyKorepanov commented 5 years ago

@gintuoklis Thank you for reporting the issues, the fix will be shipped in future update.

ALGitHubBot commented 5 years ago

The fix for this issue has been checked in to the master branch. It will be available in the bcinsider.azurecr.io/bcsandbox-master Docker image starting from build number 25977.

If you don’t have access to these images you need to become part of the Ready2Go program: aka.ms/readytogo

For more details on code branches and docker images please read: https://blogs.msdn.microsoft.com/nav/2018/05/03/al-developer-previews-multiple-releases-and-github/ https://blogs.msdn.microsoft.com/freddyk/2018/04/16/which-docker-image-is-the-right-for-you/

ik3ras commented 5 years ago

Issue with Rule139DoNotAssignToStringWithSmallerCapacity is still not fixed using AL extension 2.1.66478

obtained from latest insider docker image "Labels": { "country": "W1", "created": "201811252233", "cu": "", "eula": "https://go.microsoft.com/fwlink/?linkid=861843", "legal": "http://go.microsoft.com/fwlink/?LinkId=837447", "maintainer": "Dynamics SMB", "nav": "main", "osversion": "10.0.14393.2608", "tag": "0.0.8.0", "version": "14.0.26257.0" }

{ "resource": "/c:/SourceControl/ll/app.json", "owner": "_generated_diagnostic_collectionname#1", "code": "AD0001", "severity": 4, "message": "Analyzer 'Microsoft.Dynamics.Nav.CodeCop.Design.Rule139DoNotAssignToStringWithSmallerCapacity' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'", "source": "AL", "startLineNumber": 1, "startColumn": 1, "endLineNumber": 1, "endColumn": 1 }

JulianTillmann commented 5 years ago

The fix for this issue has been checked in to the master branch. It will be available in the bcinsider.azurecr.io/bcsandbox-master Docker image starting from build number 25977.

I'm sorry, but this seems to be an AL Problem? Why does this Need to be fixed in a docker Image? And how About OnPrem?

We still get this error, when does the fix "ship in the future"?

ALGitHubBot commented 5 years ago

The fix for this issue has been checked in to the master branch. It will be available in the bcinsider.azurecr.io/bcsandbox-master Docker image starting from platform build number 25977.

If you don’t have access to these images you need to become part of the Ready2Go program: aka.ms/readytogo

For more details on code branches and docker images please read: https://blogs.msdn.microsoft.com/nav/2018/05/03/al-developer-previews-multiple-releases-and-github/ https://blogs.msdn.microsoft.com/freddyk/2018/04/16/which-docker-image-is-the-right-for-you/