I am trying to use OnInstanceUpdated but it doesn't even hit my breakpoint? (It does update the Schema, and returns Success, but it just seems to remove the element instances.)

private DGN.SchemaUpdateStatus UpdateSchema()
FindInstancesScope scope = FindInstancesScope.CreateScope(ActiveDgnFile, new FindInstancesScopeOption(DgnECHostType.File, false));
IECSchema dgnSchema = DgnECManager.Manager.LocateSchemaInScope(scope, SchemaName, VersionMajor, VersionMinor, SchemaMatchType.Latest);
if (null != dgnSchema)
DGN.SchemaUpdateStatus updStatus = DGN.SchemaUpdateStatus.Success;
if (dgnSchema.VersionMajor < VersionMajor || dgnSchema.VersionMinor < VersionMinor)
UpdateSchemaOptions opts = new UpdateSchemaOptions((ushort)ECProviderId, false, true);
DgnECManager.Manager.OnInstanceUpdated += UpdateInstanceHandler;
updStatus = DgnECManager.Manager.UpdateSchema(MySchema, ActiveDgnFile, opts);
DgnECManager.Manager.OnInstanceUpdated -= UpdateInstanceHandler;
return updStatus;
catch { }
return DGN.SchemaUpdateStatus.SchemaNotFound;

public override void UpdateInstanceHandler(IDgnECInstance ecInstance)
string msg = "WTF Tom?";   // <- Breakpoint
//SetPropertyStringValue(ecInstance, VersionName, Version()); <- I want to do more than this, just trying to test right now...

Parents Reply
  • the last parameter of new UpdateSchemaOptions(...., true) is supposed to be telling UpdateSchema() to also updateInstances?

    Did you read API documentation? In this case (as in many other situations), I mean C++ documentation for native equivalent of the managed one:

    There is no transformation of data already stored in the file.
    The caller is at their own risk to ensure that the new ECSchema is compatible
    with existing data 

    so I wasn't attempting to use the OnInstanceUpdated event.

    I did not implement such code in the past, so I am not sure I am right, but it sounds to me like a missunderstanding how EC ecosystem works: Schema and EC data are stored separately (both as XAttributes). In fact, they are plain (probably compressed) XML data.

    EC schema is updated without any relation to existing EC data. And OnInstanceUpdate event is not involved in this process in any way (because EC schema, not EC instance data is changed).

    With regards,