Skip to content

Commit

Permalink
resolve assembly conflic pdb autocad vs civil3d
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed May 20, 2022
1 parent 15b2b34 commit c08b9b2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
44 changes: 34 additions & 10 deletions CadAddinManager/Model/AssemLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Windows;
using CadAddinManager.View;
using Mono.Cecil;
using Mono.Cecil.Pdb;

namespace CadAddinManager.Model;

Expand Down Expand Up @@ -84,16 +85,18 @@ public Assembly LoadAddinsToTempFolder(string originalFilePath, bool parsingOnly
{
stringBuilder.Append("-Executing-");
}

tempFolder = FileUtils.CreateTempFolder(stringBuilder.ToString());
string fileAssemblyTemp = String.Empty;
try
{
fileAssemblyTemp = ResolveDuplicateMethod(originalFilePath);
}
catch (Exception)
{
fileAssemblyTemp = originalFilePath;
}
string fileAssemblyTemp = ResolveDuplicateMethod(originalFilePath);
// string fileAssemblyTemp = String.Empty;
// try
// {
// fileAssemblyTemp = ResolveDuplicateMethod(originalFilePath);
// }
// catch (Exception)
// {
// fileAssemblyTemp = originalFilePath;
// }
var assembly = CopyAndLoadAddin(fileAssemblyTemp, parsingOnly);
if (assembly == null || !IsAPIReferenced(assembly))
{
Expand All @@ -104,7 +107,9 @@ public Assembly LoadAddinsToTempFolder(string originalFilePath, bool parsingOnly

private string ResolveDuplicateMethod(string originalFilePath)
{
AssemblyDefinition ass = AssemblyDefinition.ReadAssembly(originalFilePath);

// AssemblyDefinition ass = AssemblyDefinition.ReadAssembly(originalFilePath);
AssemblyDefinition ass = GetAssemblyDef(originalFilePath);
foreach (ModuleDefinition def in ass.Modules)
{
foreach (TypeDefinition d in def.Types)
Expand Down Expand Up @@ -144,7 +149,26 @@ private string ResolveDuplicateMethod(string originalFilePath)
ass.Write(fileAssemblyTemp);
return fileAssemblyTemp;
}
public static AssemblyDefinition GetAssemblyDef(string assemblyPath)
{

var assemblyResolver = new DefaultAssemblyResolver();
var assemblyLocation = Path.GetDirectoryName(assemblyPath);
assemblyResolver.AddSearchDirectory(assemblyLocation);

var readerParameters = new ReaderParameters { AssemblyResolver = assemblyResolver };

var pdbName = Path.ChangeExtension(assemblyPath, "pdb");
if (File.Exists(pdbName))
{
var symbolReaderProvider = new PdbReaderProvider();
readerParameters.SymbolReaderProvider = symbolReaderProvider;
readerParameters.ReadSymbols = true;
}

var assemblyDef = AssemblyDefinition.ReadAssembly(assemblyPath, readerParameters);
return assemblyDef;
}
private string SaveAssemblyModifyToTemp(string originalFilePath)
{
string prefix = "RenameCommand-";
Expand Down
3 changes: 2 additions & 1 deletion CadAddinManager/ViewModel/AddinManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Windows;
using CadAddinManager.Model;
using Application = Autodesk.AutoCAD.ApplicationServices.Core.Application;
Expand Down Expand Up @@ -66,7 +67,7 @@ public AddinType LoadAddin(string filePath, AssemLoader assemLoader)
{
assemLoader.HookAssemblyResolve();

var assembly = assemLoader.LoadAddinsToTempFolder(filePath, true);
Assembly assembly = assemLoader.LoadAddinsToTempFolder(filePath, true);
list = commands.LoadItems(assembly, filePath, AddinType.Command);
}
catch (Exception e)
Expand Down

0 comments on commit c08b9b2

Please sign in to comment.