Got a "System.AppDomainUnloadedException: The application domain in which the thread was running has been unloaded" error

Rod At Work 866 Reputation points
2020-11-20T18:32:58.677+00:00

We're working with EF 6 (I think it's EF 6.1.3, but not sure), in a WPF app using .NET Framework 4.5.2. We use .EDMX files for specifying our EF models.

Yesterday we added three new tables to the database, so I got into the EDMX file designer, to try to add those new tables. That failed, miserably. For whatever reason EF was removing other tables to put those new tables into the EDMX.

After trying for several hours to add those three tables I decided to just rebuild the .EDMX file from scratch, so I emptied everything out of it, then put them all back in again. That has helped. Instead of getting almost 200 EF related error messages, I'm now down to just one EF related error message. But it's one I've never seen before. Since I'm using the EF EDMX designer, I've not written any code to cause this error. And I've no idea how to resolve it. Here's the complete text of the error:

Error An Exception was thrown while processing the template. The following Exception was thrown:
System.AppDomainUnloadedException: The application domain in which the thread was running has been unloaded.

Server stack trace:
at System.Threading.Thread.InternalCrossContextCallback(Context ctx, IntPtr ctxID, Int32 appDomainID, InternalCrossContextDelegate ftnToCall, Object[] args)
at System.Runtime.Remoting.Channels.CrossAppDomainSink.DoTransitionDispatch(Byte[] reqStmBuff, SmuggledMethodCallMessage smuggledMcm, SmuggledMethodReturnMessage& smuggledMrm)
at System.Runtime.Remoting.Channels.CrossAppDomainSink.SyncProcessMessage(IMessage reqMsg)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Microsoft.VisualStudio.TextTemplating.IDebugTransformationRun.PerformTransformation()
at Microsoft.VisualStudio.TextTemplating.Engine.ProcessTemplateImplementation(TemplateProcessingSession session, String content, ITextTemplatingEngineHost host, String className, String classNamespace, ITelemetryScope scope)
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject) CoreFramework C:\Src\NMBAD\NMBAD\CoreFramework\Model\AppModel.tt 0

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,417 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,621 Reputation points
    2020-11-23T06:21:28.413+00:00

    Hi Rod At Work,
    >>I decided to just rebuild the .EDMX file from scratch, so I emptied everything out of it, then put them all back in again.
    Can you describe in detail the steps you did which caused the error?
    >> I've not written any code to cause this error.
    I guess that the problem was being caused by my Entity Framework installation.
    So you can try to open up the NuGet Package Manager console and run the command:

    Update-Package –reinstall EntityFramework.  
    

    After waiting for EF to reinstall, you need to restart Visual Studio.
    Best Regards,
    Daniel Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments