Open sandboxFocusImprove this doc

LAMA0049: Metalama failed with an unexpected exception it could contain

Severity Warning
Reported by Metalama.Framework
Message Unexpected exception occurred in Metalama: <Message> Exception details are in '<File>'. Please report this issue at https://www.postsharp.net/support and attach this file to the ticket. You may want to remove sensitive data from the report.

Cause

LAMA0049 is the warning counterpart of LAMA0001. Metalama reports it when an exception that it didn't anticipate escapes from a part of its pipeline where the failure can be contained, so that the rest of the work continues. This is a bug in Metalama, not in your code, even if a particular construct in your code triggers it.

Currently, Metalama reports LAMA0049 when it generates the source code that makes aspect-introduced declarations visible to your code in the IDE, for instance the members that an aspect introduces into a partial class. Metalama generates one file per type or namespace. When the generation of one file fails, Metalama skips only this file, instead of discarding the generated code of the whole project, and reports the warning. As a consequence, the IDE doesn't see the declarations introduced into the affected type, so your code may show errors where it references them. The build isn't affected.

In the message, <Message> is the message of the exception, and <File> is the path of the crash report that Metalama wrote. The crash report contains the version of Metalama, the .NET runtime and operating system, the exception type, message and stack trace, and, when the exception relates to a specific syntax tree, the full text of this source file.

This diagnostic is caused by a defect in Metalama, so it can't be shown in an example.

Resolution

  1. Open the crash report file given in the message. By default, crash reports are written to the %TEMP%\Metalama\CrashReports directory on Windows and deleted one month after their creation. See LAMA0001 for the other platforms and for the METALAMA_TEMP environment variable.
  2. Check whether the problem is already fixed: update the Metalama packages to the latest version of your release line. Also check the existing issues.
  3. Report the problem, as described in How to file an issue, and attach the crash report. Before you send it, review the file and remove anything confidential: it may contain fragments or whole files of your source code.
  4. Until the bug is fixed, you can keep working, because the build still produces the correct code. If the missing declarations disturb you in the IDE, try to find the construct that triggers the exception, using the stack trace in the report, and rewrite it in another way. Restarting the IDE or running metalama kill sometimes resolves exceptions caused by a stale cache.

See also