chuongmep / RevitAddInManager

Revit AddinManager update .NET assemblies without restart Revit for developer.
MIT License
275 stars 50 forks source link

Newly compiled code cannot be loaded into revit #47

Open hbbliyong opened 1 year ago

hbbliyong commented 1 year ago

I used the latest version 1.44, the first load ran without problems, modified the code and re-run, the newly compiled code did not load into revit. Asked other colleagues, colleagues second run will prompt whether to copy the dll, mine did not. I need to close revit and re-open it to get the new code to load into revit. My environment is Windows 10, Revit 2021. Origin : 我使用了最新1.44版本,第一次加载运行没有问题,修改代码后重新运行,新编译的代码并没有加载到revit。询问别的同事,同事二次运行会提示是否拷贝dll,我的没有。 这时候,我需要将revit关闭后重新打开,新的代码才会加载到revit。我用的环境是win10+revit2021

chuongmep commented 1 year ago

Hi @hbbliyong, many thanks for your reported, can give me provide some example to can create problem ?

hbbliyong commented 1 year ago

thank you for your reply.I don't know how to provide the example.i clone the code and debugged it. the code copy my dlls to the temp directory. image but,my dll's new code not work. I suspect that the old code is not being replaced in revit, it is possible that static data is used in my dll. they only work in the revit2018, the other revit version not work at all . i'm sorry my english not very well。 i hope your can understand my mean.

hbbliyong commented 1 year ago

I decompiled the dll from the temp directory, it's new, but it didn't work. when i close the revit2021,rerun the command ,it work well.

My solution contains two projects, command and business logic code.

i alse test the test project ,i modified the test code and complied it, it can work well.

hbbliyong commented 1 year ago

i found the reason. I have three dlls, the Command.dll,A.dll,B.dll. Commond.dll refere to A.dll. A.dll refer to B.dll. I modified the B.dll. I analyzed the dll referenced by revit and found that B.dll was not updated. Maybe we should unload the B.dll. What should we do. IIf I modify directly the command code ,it ok. @chuongmep

hbbliyong commented 1 year ago

image `
AppDomain currentDomain = AppDomain.CurrentDomain; //Provide the current application domain evidence for the assembly. Evidence asEvidence = currentDomain.Evidence; //Make an array for the list of assemblies. Assembly[] assems = currentDomain.GetAssemblies();

            //List the assemblies in the current application domain.
            Console.WriteLine("List of assemblies loaded in current appdomain:");
            foreach (Assembly assem in assems)
            {
                if(assem.GetName().Name.Contains("MCREV_Features1"))
                System.IO.File.AppendAllLines(@"D:\\ddd.txt", new string[] { assem.Location });
            }

` I log all reference dll's.but only the "MCREV_Features1_Commands.dll" was update,the other dlls still old. when you finished the command ,the first temp directory "MCREV_Features1_Commands-Executing-20230411_154218_6128" still have many dlls not be delete.

chuongmep commented 1 year ago

Thank for provide more information and explaination , I know that problem, Revit Addin Manager at the moment just apply for command change with one assembly, all library dependent change can't update, this also is limit of addinmanager at this time, maybe I will consider find another way to allow dependent assembly work with like same namespace so far :

hbbliyong commented 1 year ago

@chuongmep thank you for replying.

Is there any possibility for us to solve this problem by AppDomain? I don't know if this will give you some ideas. PluginAppDemo

chuongmep commented 1 year ago

@hbbliyong at the moment, addin manager also working by resolve with App Domain because .Net Framework still is 4.8, I will think find another way when I have time, thanks for your ideas.

hbbliyong commented 1 year ago

@chuongmep Do you mean that it cannot be solved under .Net Framework4.8? Do you have any idea for me ,I try to solve it.

chuongmep commented 1 year ago

@hbbliyong I recommend you try to look this project https://github.com/dotnetcore/Natasha, if I have time, I also try to hack something

hbbliyong commented 1 year ago

@chuongmep i have another question,why it works well in reivt2018?

chuongmep commented 1 year ago

@hbbliyong , I'm not sure about that, just look about 24 and fix for that .

chuongmep commented 10 months ago

Thank you @kelilife , I will take a look to that when I have time. I'm happy if any people have some pull request to clearly for it.

chuongmep commented 10 months ago

@kelilife thank you for good catch. It is useful with any develop are looking to this project and continue to explore all detail of that. Appreciated !