System.TypeLoadException with Revit Add-in

By Saikat Bhattacharya

I have had couple of emails in recent past with different third party developers providing me with their Revit add-in samples, where they are stuck because of the following System.TypeLoadException.

image

As mentioned here, the reason for this exception typically is that CLR did not find the assembly, or the type within the assembly or could not load the type. This in most cases that I have seen with Revit add-ins seems to commonly due to a mismatch between the .NET framework and the Revit version being used to develop the add-in. There are also couple of discussions on this topic in the Revit API discussion forum.  

In the recent case, I had spent quite sometime confirming that the correct for the .NET framework was being targeted for in the VS project, the version of the Revit API references, and other settings and even double checked that entries in the .addin manifest file – all of which seemed perfect. Next, I started reading through the VB.NET code and immediately saw Namespace was provided in the code as well as in the Root Namespace field in the VB.NET project settings. Once I removed the Namespace entry from the code, the Add-in loaded up just fine in Revit. This would be a typical case whenever we end up converting C# code to VB.NET. Something to watch out for!


Comments

3 responses to “System.TypeLoadException with Revit Add-in”

  1. I’ve got the same exception, but on a C# project. I don’t think it is related to the namespace, because the same .dll work on a computer, but not on another one…

  2. Hi Maxence:
    Reading through your inputs, I am hoping that the following might help resolve the error?
    http://through-the-interface.typepad.com/through_the_interface/2011/07/loading-blocked-and-network-hosted-assemblies-with-net-4.html
    cheers
    Saikat

  3. No, I’ve found that it is a problem with ILMerge and .NET 4.5. If you use ILMerge and you are targeting .NET 4.0, you have to use the path C:\Program Files\Reference
    Assemblies\Microsoft\Framework.NETFramework\v4.0 instead of c:\windows\Microsoft.NET\Framework\v4.0.30319 in the /targetplatform switch. In .NET 4.5, the type ExtensionAttribute has been moved from System.Core to mscorlib. More details here:http://www.mattwrock.com/post/2012/02/29/What-you-should-know-about-running-ILMerge-on-Net-45-Beta-assemblies-targeting-Net-40.aspx

Leave a Reply