Wednesday, April 20, 2011

[Revit API]– Running your add-ins from a network drive in Revit 2012

In previous years our office has run our add-ins directly off a network drive. I’ve placed the DLL files in a network directory, and then installed the .addin manifest file on each users computer that points to these DLL’s. This way when I update the add-ins I only need to update one location and the users simply need to reboot Revit.

To get this to work, I just had to run caspol.exe on each machine to make their machines trust that certain location, for example:
echo y|C:\WINDOWS\Microsoft.NET\Framework\v3.5\caspol.exe -cg LocalIntranet_Zone FullTrust 
echo y|C:\WINDOWS\Microsoft.NET\Framework\v3.5\caspol.exe -m -ag 1.2 -url file://L:\* FullTrust

However in upgrading the add-ins to Revit 2012, this method did not work. The add-ins simply would not load, and in the journal file I was seeing this error:
Jrn.RibbonEvent "Execute external command:35015:Plotting.PLT"
' 0:< DBG_WARN: Could not load file or assembly 'file:///L:\Plotting.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515): line 171 of AddIn\AddInItem.cpp. 

This was when my assemblies were compiled in .NET 4 and the same error occurred after I recompiled them in .NET 3.5. I had a feeling that it might have something to do with the changes in security that were introduced with .NET 4, but the fact that it happened to .NET 3.5 dll’s as well was odd.
Turns out there’s a fix for it, which is a little bit of a pain, your user needs to update their revit.exe.config file in the Revit program directory (C:\Program Files\Autodesk\Revit Structure 2012\Program) and make the following change:

look for the <runtime> tag, and just after it’s opening, put:
<loadFromRemoteSources enabled="true" />
making it:
<runtime>
  <loadFromRemoteSources enabled="true" />
  <generatePublisherEvidence enabled="false"/>
</runtime>

The add-ins should then run correctly. This is however a bit of a pain, I’ll have to incorporate this into an installation tool. I’d love to hear of a better solution to this problem if anyone knows of one, however for now, this will work around it.

Thanks to this post for helping to point me in the right direction.

6 comments:

gregory said...

Rod,

Thanks for the info. This appears to have fixed my build problem...well at least part of my problems.

fyi. relative to your problem of keeping everyone up to date. At the office of one of my clients I have developed a small program that simply pushes the new/modified dlls/ addin manifests out to each computer.

Each time a user starts revit it compares a version in a simple text file on their computer with a similar file on the server. If they don't match, then I pop up a window and generate an email with computer name and info already written(but don't autosend) saying that their revit is out of date.

When i update or add a dll, i run the routine with all computer names (from a text file list) as a target.

When i receive the email, i simply run the routine with their computer as a target.

The only downside (and I suppose you have this with your method too) is that the user has to be out of revit for me to be able to up date (since it locks the dlls...or was that just the revit.ini...i'm not sure anymore)

anyway...info.

thanks again.

Rod Howarth said...

Glad to hear it helped you Gregory. Thanks for the tip about the update, I'd considered making something like that if I couldn't get this working!

I've been talking to ADN about this problem, and if there's a business case for getting this problem fixed they might be able to fix it sooner and enable that option by default, so if anyone wants this fixed be sure to contact them (or post here and I'll pass it on) with some good reasons why it should be changed!

Dima Chiriacov said...

Thanks a lot for the tip! I had exactly the same problem migrating to 2012 and my dlls that were sitting on the network drive for the whole office wouldn't run. That solved the problem!

Dima Chiriacov said...

Thanks a lot for the tip! I had exactly the same problem migrating to 2012 and my dlls that were sitting on the network drive for the whole office wouldn't run. That solved the problem!

Erik said...

AS far as ADN making that the default condition. Add my vote.

Anonymous said...

Hi Rod,

I have a requirement,on starting a revit, i need to run an addin automatically that would fetch details of the.rvt file store it in the database.

Can u help me plz?