Revit 2015 log4net compatibility issue

Revit 2015 log4net compatibility issue

btmsoftware
Advocate Advocate
1,424 Views
10 Replies
Message 1 of 11

Revit 2015 log4net compatibility issue

btmsoftware
Advocate
Advocate

Hi All,

 

I'm creating a plugin for Revit 2015 to connect to some other software which provides a .NET API whihc I can use.

 

The problem is that Revit uses log4net version 1.2.10 and the other piece uses log4net 1.2.12.

 

the problem is that obviouly, Revit runs before my addin loads and then my adding will crash because the underlying stuff, which I don't control, tries to load log4net 1.2.12 and crashes.

 

I try removing log4net.sll from the Revit install path, my addin loads fibne, however Revit dies on me as sooin as I open a file

I tried replacing the Revit log4net dll with the one from thr underlying layer, same my adding loads but revit dies when I open a file

 

I tried replacing the underlying stuff's dll with the Revit dll but then it won;t load anymore

 

Any other ideas ?

0 Likes
1,425 Views
10 Replies
Replies (10)
Message 2 of 11

augusto.goncalves
Alumni
Alumni

Hi,

 

I believe you can handle this by setting the log4net reference to "Specific Version" equal TRUE. This should force you addin to load only that specific version of the DLL. Can you try it?

 

Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
0 Likes
Message 3 of 11

btmsoftware
Advocate
Advocate

Well, I'm afraid I can't.

 

Basically, my add-in is just a wrapper for an underlyoing DLL that comes with log4net.dll too, version 1.212 and I don;t have the code for those DLLs

 

These DLL's are in a separate directory and I don;t control which log4net they try to use but it seems to me like since revit already loads log4net, they try ot reuse the same but they can't because they actually look to use 1.2.12 but revit load 1.2.10

 

Which, by the way, make me think that these DLLs already have the Specific Version set to True.

 

I'm also talking to the vendor of those DLLs so they use Specifi Version to False instead but it's like asking Microsoft to change windows just for me, I don't have much hope....

0 Likes
Message 4 of 11

augusto.goncalves
Alumni
Alumni

Hi,

 

Indeed this is tricky... I'm not an expert on .NET loading engine, but if the 3rd party is already crashing, then it should be looking for a specific version.

 

What about make sure both versions are loaded? Call Assembly.Load with all the required versions and, as .NET can control it, it should track them. 

 

Hope this can help

Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
0 Likes
Message 5 of 11

btmsoftware
Advocate
Advocate

Well, I wish I could but as I said, I don't control the way they load the different assemblies they use.

 

Believe me, if I did, I'd have resolved this quickly 🙂

0 Likes
Message 6 of 11

augusto.goncalves
Alumni
Alumni

Sorry if I'm missing anything.

 

What I mean is: inside your app (that shares memory with Revit and the 3rd pary app), explicitly call Assembly.Load on the versions you believe are required.

 

You may also track the Assembly Resolve and, whenever a module is not found (like this log4net), your code load it correctly.

 

If still not the case, can you clarify the error message that you're receiving?

Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
0 Likes
Message 7 of 11

btmsoftware
Advocate
Advocate
I'll give it a shot and will let you know
0 Likes
Message 8 of 11

btmsoftware
Advocate
Advocate

Still no luck.

 

BTE, I get the following error:

 

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileLoadException: Could not load file or assembly 'log4net, Version=1.2.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
   at BTMSoftware.DRAWbridge.Documentum.Connect.splash()
   at BTMSoftware.DRAWbridge.Documentum.Connect..ctor() in C:\BTM\Documentum\BTMsoftware.DRAWbridge.Documentum\Connector\Connect.cs:line 151
   --- End of inner exception stack trace ---
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Activator.CreateInstance(Type type)
   at BTMSoftware.DRAWbridge.Webtop.Revit._2015.RevitEventsHandler.onStartupIdle(Object sender, IdlingEventArgs e) in C:\BTM\Documentum\Revit\src\Revit\RevitEventsHandler.vb:line 47

 

As far as I can see, Revit loads its own log4net (1.2.10) before loading my DLL (which is in its own sub dir from Revit as well as the log4net used 1.2.12)

This sub dir is in the probing -> privatePath definition of the revit.exe.config file, it is the 1st entry but it seems like it's ignored as it A log4net.dll is found in the revit directory itself

 

0 Likes
Message 9 of 11

augusto.goncalves
Alumni
Alumni

Hi,

 

I believe this is where the Assembly Resolve (https://msdn.microsoft.com/en-us/library/system.reflection.assembly.moduleresolve(v=vs.110).aspx) can help. When a assembly is not found, the main execution (Revit.exe) will trigger this, which can be captured by your application. Then, inside the event, call Assembly.Load passing the correct DLL (where the version you need is).

 

Sorry I don't have the same scenario here to try it, but I have done for other reference problems in the past. Usually I place the DLLs on a "strange" folder and wait for the Assembly Resolve event, then according to my logic, load the correct one (instead waiting the system to choose).

Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
0 Likes
Message 10 of 11

btmsoftware
Advocate
Advocate

Well, I don;t think it will help because

1. the assembly is acually found, only it's not the version expected which is found

2. I don't call log4net myself in my addin, it's the vendor DLL that calls it and I can't control how it does it as I don;t have the source

 

I guess I'm going to have to kick the vendor's butt so they specify the version when using log4net....

 

I'll keep you posted when/if I get something new from the vendor.

 

Thanx for trying to help anyways

0 Likes
Message 11 of 11

augusto.goncalves
Alumni
Alumni

Ok, keep me updated if the 3rd pary replies or if you decide to try the event.

Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
0 Likes