Upgrading extensible storage schema containing elementID AND a GUID fails in 2024

Upgrading extensible storage schema containing elementID AND a GUID fails in 2024

ken_marsh_pelogic
Contributor Contributor
251 Views
1 Reply
Message 1 of 2

Upgrading extensible storage schema containing elementID AND a GUID fails in 2024

ken_marsh_pelogic
Contributor
Contributor

We were excited to see that 2024.1 fixed an issue with upgrading schemas containing ElementID fields!  

 

However, we also have a reproducible case where a Schema which contains two simple fields: ElementID and GUID will still fail on upgrade to 2024.

 

Steps to reproduce with the attached code:

1. start debugging in 2023

2. create new document (addin automatically adds an entity to ProjectInformation)

3. save 2023 document

4. start debugging in 2024

5. create a new document (addin automatically adds an entity to ProjectInformation)

6. close this new 2024 document (Schema built in 2024 is now in Revit Session memory)

7. open the 2023 saved document -> Schema error

 

Observations:

1. Guid alone will not cause the problem

2. ElementID alone will not cause the problem (with 2024.1 update installed)

3. other data types (e.g., string) in combo with ElementID do not seem to cause the problem

 

Code below (in case something obvious is messed up in our code)

 

using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Events;
using Autodesk.Revit.DB.ExtensibleStorage;
using Autodesk.Revit.UI;
using System;

namespace Pelogic.EntityStorageTest {
	public class Main : IExternalApplication
	{
		private static readonly Guid guid = new Guid("5f21990e-1765-4624-bb52-fd49685da022");
		private static readonly string name = "id";
		private static readonly string guidId = "Guid";

		private AddExtensibleStorage addExtensibleStorage;

		public Result OnStartup(UIControlledApplication application)
		{
			application.ControlledApplication.DocumentCreated += OnDocumentCreated;
			application.ControlledApplication.DocumentOpened += OnDocumentOpened;
			addExtensibleStorage = new AddExtensibleStorage();
			return Result.Succeeded;
		}

		public Result OnShutdown(UIControlledApplication application)
		{
			return Result.Succeeded;
		}

		private void OnDocumentCreated(object sender, DocumentCreatedEventArgs e)
		{
			addExtensibleStorage.Raise();
		}

		private void OnDocumentOpened(object sender, DocumentOpenedEventArgs e)
		{
			addExtensibleStorage.Raise();
		}

		private static Schema CreateSchema()
		{
			SchemaBuilder builder = new SchemaBuilder(guid);
			builder.SetSchemaName("PelogicEntityStorageTest");
			builder.AddSimpleField(name, typeof(ElementId));
			builder.AddSimpleField(guidId, typeof(Guid));
			return builder.Finish();
		}

		private class AddExtensibleStorage : IExternalEventHandler
		{
			private readonly ExternalEvent _revitEvent;

			public AddExtensibleStorage() {
				_revitEvent = ExternalEvent.Create(this);
			}

			public void Raise() => _revitEvent.Raise();

			public void Execute(UIApplication app)
			{
				Element elem = app.ActiveUIDocument.Document.ProjectInformation;
				using (Transaction tr = new Transaction(elem.Document, "Create Test Schema"))
				{
					tr.Start();
					try
					{
						Schema schema = CreateSchema();
						Entity entity = new Entity(schema);
						elem.SetEntity(entity);
						tr.Commit();
						new TaskDialog("Schema successfully added!").Show();
					}
					catch (Exception ex)
					{
						tr.RollBack();
						new TaskDialog("Error")
						{
							MainContent = ex.ToString()
						}.Show();
					}
				}
			}

			public string GetName()
			{
				return "AddExtensibleStorage";
			}
		}
	}
}

 

0 Likes
252 Views
1 Reply
Reply (1)
Message 2 of 2

jeremy_tammik
Alumni
Alumni

That sounds like a clever (nasty) thing to do. Thank you very much for narrowing it down so effectively! That should give them something new to ponder... Oh dear. Sorry that these problems are so persistent! I'll pass it on asap... don't have the required access right now...

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes