swex-addin icon indicating copy to clipboard operation
swex-addin copied to clipboard

ModelDocExtension conflict

Open codestackdev opened this issue 5 years ago • 0 comments

The following compile error is displayed when ModelDocExtension class is used explicitly:

error CS0433: The type 'ModelDocExtension' exists in both 'CodeStack.SwEx.AddIn, Version=0.8.1.0, Culture=neutral, PublicKeyToken=a46023996d4724e7' and 'SolidWorks.Interop.sldworks, Version=27.1.0.72, Culture=neutral, PublicKeyToken=7c4797c3e4eeac03'

ModelDocExtension modelDocExt2 = model.Extension;
var appPageSetup4 = modelDocExt2.AppPageSetup;

This only happens if variable of type ModelDocExtension is declared explicitly.

The are several workarounds available:

  1. Use IModelDocExtension instead of ModelDocExtension
IModelDocExtension modelDocExt1 = model.Extension;
var appPageSetup3 = modelDocExt1.AppPageSetup;
  1. Use var in C# to avoid explicit declaration
var modelDocExt = model.Extension;
var appPageSetup2 = modelDocExt.AppPageSetup;
  1. Do not declare the variable, but use Extension property of IModelDoc2
var appPageSetup1 = model.Extension.AppPageSetup;

codestackdev avatar Oct 21 '19 22:10 codestackdev