Visual Studio - C# - multiple assemblies with same namespace conflict - alias get ignored

Viewed 99

I'm working on a Plugin for a software (Revit) using its API (RevitAPI.dll).

Some functions in the API have been changed in the latest version 2022 so I'm trying to implement these differences in my code.

I'm loading the 2020 API with the alias rvt20api and the 2022 as rvt22api - they have the same namespaces inside.

My problem is that in the 2022 there should be a class called ForgeTypeId but its giving me the CS0234 error (not found) when calling it.

I've opened the RevitAPI.dll (2022) and confirmed that the Class is indeed inside there and if i load just the 2022 API assembly then Visual Studio sees that and is happy but when I load both assemblies then the error. Seems it's almost reading the rvt20api namespace even tho I'm calling the rvt22api one.

enter image description here

enter image description here

Short-term question : how do I fix this ? Am i missing something (not an expert) ?

Long-term question : what is the most appropriate method to go with when working with multiple external api versions? Would it be using the Shared Project approach ?

Thanks in advance

1 Answers

I would suggest creating aliases for each, like so:

extern alias rvt20api;
extern alias rvt22api;
using rvt20apidb = rvt20api::Autodesk.Revit.DB;
using rvt22apidb = rvt22api::Autodesk.Revit.DB;

// then within the code
var foo = rvt22apidb.forgeTypeId;

Docs on this here.

Related