Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FileLoadException At InitializeComponent or x:Class=

I get a file loader exception (first chance) at the InitializeComponent-method or the debugger breaks at the x:Class attribute of the xaml-root of multiple WPF user controls. Everything works fine despite the fact that the exceptions slow down navigation by a lot.

This is the exception message:

Could not load file or assembly 'Company.Solution.UserInterface, Version=0.1.5568.25577, Culture=neutral, PublicKeyToken=45069ab0c15881ce' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

This is the Fusion log:

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  D:\Development\Product\Main\src\Company.Product \bin\Debug\Product.vshost.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = Company.Product .UserInterface, Version=0.1.5568.25577, Culture=neutral, PublicKeyToken=45069ab0c15881ce
(Fully-specified)
LOG: Appbase = file:///D:/Development/Product/Main/src/Company.Product/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.     
LOG: This bind starts in default load context.
LOG: Using application configuration file: D:\Development\Product \Main\src\Company.Product \bin\Debug\Product .vshost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Company.Product .UserInterface, Version=0.1.5568.25577, Culture=neutral, PublicKeyToken=45069ab0c15881ce
LOG: Attempting download of new URL file:///D:/Development/Product/Main/src/Company.Product/bin/Debug/Company.Product.UserInterface.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Revision Number
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

My project structure has a root project that references a module project (in which the exception occurs). The module project itself references the project that is the target of the above mentioned probing "Company.Product.UserInterface.dll" which contains some resources / controls / styles / primitives / converters and so on.

How can I get rid of the FileLoadExceptions?

Another more complete Fusion-log:

=== Pre-bind state information ===
LOG: DisplayName = Company.Product.UserInterface, Version=0.1.5577.18122,      Culture=neutral, PublicKeyToken=45069ab0c15881ce
(Fully-specified)
LOG: Appbase = file:///D:/Development/Product/Main/src/Company.Product/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = Product.vshost.exe
Calling assembly : PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
LOG: This bind starts in default load context.
LOG: Using application configuration file: D:\Development\Product\Main\src\Company.Product\bin\Debug\Product.vshost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Company.Product.UserInterface, Version=0.1.5577.18122, Culture=neutral, PublicKeyToken=45069ab0c15881ce
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///D:/Development/Product/Main/src/Company.Product/bin/Debug/Company.Product.UserInterface.DLL.
LOG: Assembly download was successful. Attempting setup of file: D:\Development\Product\Main\src\Company.Product\bin\Debug\Company.Product.UserInterface.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: Company.Product.UserInterface, Version=0.1.5577.18123, Culture=neutral, PublicKeyToken=45069ab0c15881ce
WRN: Comparing the assembly name resulted in the mismatch: Revision Number
ERR: The assembly reference did not match the assembly definition found.
ERR: Run-from-source setup phase failed with hr = 0x80131040.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

At the moment the exception occurs the version of the assembly in the SolutionExplorer referenced is 0.1.5577.18123 (in all solutions that reference the ..UserInterface.dll. I have no idea who looks up 0.1.5577.18122, this version did never exist)

If I run a new rebuild all I get the same error, Fusion looks for (I never had this version number):

LOG: Post-policy reference: Company.Product.UserInterface, Version=0.1.5577.18465, Culture=neutral, PublicKeyToken=45069ab0c15881ce

the version found is:

LOG: Assembly Name is: Company.Product.UserInterface, Version=0.1.5577.18466, Culture=neutral, PublicKeyToken=45069ab0c15881ce

Visual Studio Version is 2013 Ultimate, and the project is build on .net4.5 and the assembly versions are auto generated in the build process. I uploaded the build log to tinyupload as it was too big. The full Fusion-log can be found here at pastebin.

like image 866
quadroid Avatar asked Mar 31 '15 13:03

quadroid


2 Answers

   Version=0.1.5577.18122

This auto-generated version number tells a tale, the last two parts of the version number are not arbitrary. They are based on the date and time the assembly was built. The build number is generated from the number of days since Jan 1st, 2000. The revision number is the number of seconds*2 since midnight without daylight savings correction.

So facts we know is that the 18122 assembly was built on March 30th at 2:12:34 in the afternoon. And then it got built again, 2 seconds later at 2:12:36 in the afternoon. After it was used as a reference assembly to build another project, that made the CLR spit bullets.

This should not happen, a project must be built only once in a single build session. Finding out why this happened requires digging through the MSBuild trace. You generate the one you need with Tools + Options, Projects and Solutions, Build and Run. Change the "MSBuild project build output verbosity" setting to Detailed. MSBuild now gets very chatty and tells you why it decided to build a project. If you get lost in the woods trying to decode its output (there's a lot of it) then copy/paste it in a paste-bin and link to it in your question.

There are otherwise not that many great explanations for a mishap like this. Older VS versions made it too easy to accidentally create a circular dependency between projects. You flush that out by using Build + Clean. Rebuilding the solution now fails and tells you which reference assembly is the troublemaker. You are using .NET 4 however, so at least VS2010. So not a fantastic lead, Microsoft added more checks to prevent this from happening without a warning. Not sure if it is reliable in all cases, it could be fooled if you don't depend on MSBuild alone for example. Not uncommon on build servers with "continuous integration" features.

We need the build trace to give you a reliable diagnostic.

like image 86
2 revs Avatar answered Oct 07 '22 20:10

2 revs


Suggestion 1

Is there a cyclic reference causing an old version of the dll to be loaded? (this was proven not to be the point but I have left in for historical reasons). Relating to this answer

Suggestion 2

Can you try creating a Publisher Policy? Here is an example that needs to be added to your app.config file.

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="Company.Solution.UserInterface"
                        publicKeyToken="45069ab0c15881ce"
                        culture="en-us" />
      <!-- Redirecting to version 0.1.5568.25577 of the assembly. -->
      <bindingRedirect oldVersion="0.0.0.0-0.1.5568.25577"
                      newVersion="0.1.5568.25577"/>
    </dependentAssembly>
  </assemblyBinding>
</runtime>

Explained in further detail here

Suggestion 3

Has anything changed with regards to the key that is being used to sign your assemblies?

Suggestion 4

As a slight adaption of my initial suggestion. You have stated that there are 3 projects that reference Company.Solution.UserInterface. Can you confirm that all 3 projects are referencing the same version of that assembly?

like image 36
Bijington Avatar answered Oct 07 '22 20:10

Bijington