Search code examples
.net.net-assemblyfilenotfoundexceptionfusion

Fusion attempting to load assembly that's not referenced anywhere


When I tried to sign my project I discovered that Fusion attempts to load certain dlls that do not exist. This will obviously fail, but I don't understand why it tries to load these dlls. I cannot find references to these dlls anywhere in the different projects I use.

fuslogvw gave the following output for one of those dlls:

*** Assembly Binder Log Entry  (28-9-2015 @ 16:29:53) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  D:\Projects\<snip>.vshost.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = RecentItemsManager.XmlSerializers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b9588042c0f5ae4b, processorArchitecture=MSIL
 (Fully-specified)
LOG: Appbase = file:///D:/Projects/<snip>/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = <snip>.vshost.exe
Calling assembly : System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: D:\Projects\<snip>\bin\Debug\<snip>.vshost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: RecentItemsManager.XmlSerializers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b9588042c0f5ae4b, processorArchitecture=MSIL
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///D:/Projects/<snip>/bin/Debug/RecentItemsManager.XmlSerializers.DLL.
LOG: Attempting download of new URL file:///D:/Projects/<snip>/bin/Debug/RecentItemsManager.XmlSerializers/RecentItemsManager.XmlSerializers.DLL.
LOG: Attempting download of new URL file:///D:/Projects/<snip>/bin/Debug/RecentItemsManager.XmlSerializers.EXE.
LOG: Attempting download of new URL file:///D:/Projects/<snip>/bin/Debug/RecentItemsManager.XmlSerializers/RecentItemsManager.XmlSerializers.EXE.
LOG: All probing URLs attempted and failed.

In this case it tries to load RecentItemsManager.XmlSerializers, which might at one point have existed within one of the projects but has been deleted quite a few months ago. I tried using Windows Grep to look for any instances of these strings on most of my disk, but it can't find anything either. Does anyone have any ideas on how I can fix this?


Solution

  • Following @ama1111's link I did some research and discovered that the .NET XmlSerializers are generated during the runtime. I managed to build the missing dlls using sgen and now it no longer complains about the missing dlls since those are built during compilation.

    You can automatically build those dlls in Visual Studio in the project properties under the Build tab. If you turn Generate serialization assembly to On it should always build them. However, it only does this for webservice serialization. When you use your own XmlSerialization classes it will not generate the dll unless you make sure sgen doesn't run with the /p(roxytypes) parameter. You cannot specify this in the Visual Studio build tab, but you can edit the csproj file to do this:

    <GenerateSerializationAssemblies>On</GenerateSerializationAssemblies>
    <SGenUseProxyTypes>false</SGenUseProxyTypes>
    

    The one thing that still confuses me is that I can't be the first person ever that wants to add a Strong Name to a project that contains an XmlSerializer. If the default behaviour is to generate those dlls during runtime I can't see how this would work out of the box for anyone.