Handling multiple versions of library containing WPF/XAML

Handling multiple versions of library containing WPF/XAML

Anonymous
Not applicable
1,082 Views
2 Replies
Message 1 of 3

Handling multiple versions of library containing WPF/XAML

Anonymous
Not applicable

Hello

 

I have a problem with loading multiple versions of DLLs containing WPF code, specifically .xaml files.

 

My setup is as follows:
I have to applications, "AppA" and "AppB", which both uses a library, "Lib". Since the two applications can be compiled/installed at different times they must be able to use different versions of my library. This in itself is no issue since I create the library I have solved it using strong name signing of the library.

 

The problem occurs as soon as there are .xaml files in the library. Then it fails to load the .xaml from the correct library version, it seems it always tries to load it from the oldest version. Then I get the attached exception.

 

I have read the blog post (linked below) by Jeremy Tammik, but I can't get it to work. I have tested the AssemblyResolve, but it tries to resolve the Lib.resources and not the Lib.dll.

 

http://thebuildingcoder.typepad.com/blog/2017/06/handling-third-party-library-dll-conflicts.html

 

Is there a fix for this?

 

Regards
Fredrik

0 Likes
1,083 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

Hi again

I seem to have found a workaround, but I don't think it is a very good one as it requires manually updating version number a few diffferent places before each build. I would very much appreciate getting a better solution, but this is what I have found so far.

 

1.
Regarding that the thread seemed to look for xaml files in the wrong version of my library was solved by unloading the .csproj file in visual studio and adding the <AssemblyVersion> property as shown in the attached image. I found two posts about this problem:

https://alexfeinberg.wordpress.com/2014/11/08/microsoft-mechanism-to-load-wpf-resources-is-broken-lo...

https://stackoverflow.com/questions/35035556/loading-same-assembly-with-different-versions-and-instn...

 

2.
There was another issue with loading resources such as images. These resources also needed clarification of version. This means that I have to specify in the uri which version of my library to use. See the attached image and the below post.

https://docs.microsoft.com/en-us/dotnet/framework/wpf/app-development/pack-uris-in-wpf

 

-Fredrik

0 Likes
Message 3 of 3

jeremytammik
Autodesk
Autodesk

Dear Fredrik,

 

Thank you very much for sharing this approach.

 

If you can fix the problem by manually editing some version numbers, and these version numbers are stored in text files, then you can easily automate the process by using the Unix stream editor `sed`:

 

https://en.wikipedia.org/wiki/Sed

 

You can also easily automate the modification of the text file contents using any number of scripting languages, like `perl` or `Python`.

 

I hope this helps.

 

Cheers,

 

Jeremy



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

0 Likes