Search code examples
c#dsl-tools

Microsoft.VisualStudio.Modeling.DomainDataNotFoundException : Domain object with identity was not found in directory


I am working on a DSL using the DSL Tools in the Modeling SDK for Visual Studio 2015.

The DSL is working fine. The problem is occurring where I'm trying to write some unit tests to work with some of the classes generated by the DSL.

I want to create instances of some of the elements contained within the DSL, and then test running some code on them.

I have a Feature class which is part of the DSL. It is auto-generated and inherits from ModelElement (from the Modeling SDK). I want to create an instance of it and run some tests on it. Its constructor requires a Store object (again from the Modeling SDK).

I have the following:

using (var store = new Store())
using (var transaction = store.TransactionManager.BeginTransaction("create model"))
{
    var rootFeature = new Feature(store);
    // Do something with rootFeature...
}

However this is throwing:

Microsoft.VisualStudio.Modeling.DomainDataNotFoundException : Domain object with identity DSL.Feature was not found in directory.

How come?


Solution

  • You have a problem with the way you are creating the Store. You need to pass in your domain model class as in the following example:

        [TestMethod]
        public void TestMethod1()
        {
            using (Store store = new Store(typeof(EntitiesModel3DomainModel)))
            {
                using (Transaction trans = store.TransactionManager.BeginTransaction())
                {
                    Entity entity = new Entity(store);
                    Assert.IsNotNull(entity);
                }
            }
        }
    

    The EntitiesModel3DomainModel here is the domain model for a DSL I own. You need to replace it with your own class, generated by DomainModel.tt.