WPF MVVM works with Add-In Manager but not otherwise

WPF MVVM works with Add-In Manager but not otherwise

Rab_i
Advocate Advocate
1,239 Views
4 Replies
Message 1 of 5

WPF MVVM works with Add-In Manager but not otherwise

Rab_i
Advocate
Advocate

I have come across this strange issue where my Revit add-in works exactly like I would expect when I load it using Add-In Manager. But if I load it using Add-Ins > External Tools, it fails to work as expected.  Here are some of the things I have used.

 

1) I use System.Windows.Interactivity.dll for XAML reference. 

2) I use Revit API in the View Model that is used as a Data Context for the View.

3) My XAML is a Window type and not User Control.

 

I would like to know how Add-In Manager is loading my add-in differently than using the Add-Ins > External Tools? 

 

I will try to load it using a Ribbon menu item and see if that makes the difference. Any help or thoughts in this issue would be so helpful.

 

Thank you! 

0 Likes
1,240 Views
4 Replies
Replies (4)
Message 2 of 5

jeremytammik
Autodesk
Autodesk

Dear Rabi,

 

Thank you for your query.

 

I have occasionally heard of problems using WPF with the Revit API, and also of problems using certain aspects of the .NET functionality.

 

You seem to be running into a combination of both.

 

Where are you placing your add-in DLL assembly?

 

Some .NET security regulations seem to be much happier if all the DLLs that you are working with live in the same folder or subfolders of the main EXE location, i.e., somewhere under the root installation location of Revit.exe.

 

Have you tried that?

 

Otherwise, I would suggest that you trim down your add-in to the absolute minimum required to reproduce the problem and submit that as a reproducible case that I can ask the development team to analyse in more depth:

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#1b

 

I hope this helps.

 

By the way, please refrain from manually escalating your thread to the ADN developer support if it has already been automatically escalated.

 

That creates a duplicate case and causes more overhead for all of us.

 

In this case, I see the following notes under your query:

 

  • This topic was escalated to Salesforce Case 12605340 on 01/26/2017 by Rabi.Adhikari.
  • This topic was escalated to Salesforce Case 12605274 on 01/26/2017 by an automatic escalation.

 

Do you see those as well?

 

I now closed the case 12605340 [WPF MVVM works with Add-In Manager but not otherwise] as a duplicate of 12605274 [WPF MVVM works with Add-In Manager but not otherwise].

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 5

Moustafa_K
Collaborator
Collaborator

I came across such a scenario before and realized it was a problem with my resource library was not correctly implemented. But Like Jeremy said a snippet of your code will help to learn and resolve your issue.

 

 

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
Message 4 of 5

Rab_i
Advocate
Advocate

So the mystery has been resolved. Thank you, Jeremy, for making me consider isolating the problem to its minimal. Michale Tumminello helped me confirm and solve some of these issues.

 

Here I will try to explain what happened. I used a Singleton Pattern to point to a single object reference as my view model. The methods to process information were called in the default implementation. Thus it would work the first time every time but not when we repeat the command.  The "Instance" wouldn't know how to update.  We moved the codes out of the view model class to make it a part of the Instance and voila, it's running as expected.

 

It is still a mystery to me why it worked using AddIn Manager. Perhaps, I am guessing, AddIn Manager was disposing of the objects every time I would reload thus I could never catch the problem. Certainly, it was not the case when I tested it as a command in the Revit directly.

 

This is how I created the WPF add-in. 

 

http://spiderinnet.typepad.com/blog/2011/11/wpf-and-revit-addinapi-convert-wpf-application-to-revit-...

 

I am going to test more and will update if I run into other issues. Thank you for your help.

 

 

 

0 Likes
Message 5 of 5

jeremytammik
Autodesk
Autodesk

Dear Rabi,

 

Thank you for very much your update, confirmation and appreciation.

 

I am glad that the issue is resolved and the simplification helped uncover the mystery.

 

The Add-In Manager does indeed do things differently.

 

Maybe, when the it loads an add-in, it does not actually load the assembly DLL itself, which would lock it and prevent any further unlocking or reloading of it.

 

Instead, it may read the IL code from the DLL and load that as a byte stream, or something.

 

This enables easier debugging and modification of the add-in code, as described in Using AddInManager and Attach to Process to Edit and Continue:

 

http://thebuildingcoder.typepad.com/blog/2016/10/ai-edit-and-continue.html#2

 

I really need to write a post on the importance of simplification to understand the root cause of an issue. It has cropped up in a couple of other cases recently as well, and I already had it on my list of things to do.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes