0

I have an Azure Mobile Service project which has a dependency to another (persistence) project which is referencing FluentNHibernate. Locally everything is running correctly in Release and Debug mode. Publishing the project seems to be successful (blue smiley). The problems starts when I make a request, where FluentNHibernate is used. I get the following error message:

Unable to find assembly 'FluentNHibernate, Version=2.0.3.0, Culture=neutral, PublicKeyToken=null'.

I already tried a lot of things:

  • Reinstalling packages
  • A new plain vanilla Mobile Service
  • Adding dependentAssembly in Web.config in the main project and App.config in the persistence project.

A little confusing for me is following fact: When I change the version of the FluentNHibernate package, I can see in the publish preview window that this dll will not be updated.

I am really not sure if this problem is depended to this specific package (FluentNHibernate). For example, what means: PublicKeyToken=null? What else can I try to make the service running in the cloud?

core
  • 851
  • 1
  • 8
  • 28
  • 1
    You should not need any entries in the `dependentAssembly` section of `Web.config`, so I'd remove those. `PublicKeyToken=null` means that the assembly is not signed, which is fine. I was able to do a very simple repro and have the assemblies load correctly so there may be something more complicated happening. When you go to {yoursite}.scm.azure-mobile.net, click `Debug Console` -> `CMD` and go to `site\wwwroot\bin`, do you see FluentNHibernate.dll there? If so and you download it locally, what version is it? – brettsam Oct 26 '15 at 18:48
  • I didn't know the SCM dashboard yet. Thank you very very much for this advice! But the dll is there and has the right version. – core Oct 26 '15 at 19:28
  • I just tried moving all my NHibernate interaction into a separate referenced assembly to see if I could repro it but could not. Where are you seeing the error message -- is it in the portal logs? If so, can you (a) share the full error message if you haven't already (b) try creating a new temporary mobile service and publishing your project there to see if it happens there as well (c) try explicitly deleting FluentNHibernate.dll via the SCM dashboard and checking the Publish preview window again – brettsam Oct 28 '15 at 15:59
  • Sorry for the late response but I wasn't able to answer the last 3 days. After many many trials I could find the bits which causes the exception: It is the using of `SubclassMap` This is used for mapping base classes to a kind of base tables: http://stackoverflow.com/questions/655494/inheritance-mapping-with-fluent-nhibernate. Before I need to find a different solution could you check if you can reproduce this error? By the way: thank you for your time so far! – core Oct 31 '15 at 20:34
  • Okay I'm seeing that exception now. I'll have to dig in and see why -- I'll report back when I find anything. Thanks for the specific repro. – brettsam Nov 02 '15 at 22:52
  • I think I may know why this is happening. That code bath in FluentNHibernate calls a DeepClone helper method which uses the BinaryFormatter to serialize and deserialize an object. My guess is that deserialization is happening in the context of the hosting environment and it cannot find the assembly for some reason. I'm going to try to find a fix for this. See their code here: https://github.com/jagregory/fluent-nhibernate/blob/6302b200c349ca5c5c61ad5f829fbf14b9ba123b/src/FluentNHibernate/Utils/Extensions.cs#L67 – brettsam Nov 02 '15 at 23:11

1 Answers1

3

The code below worked for my solution. It wires up a handler to the AppDomain's AssemblyResolve event, which is raised if an assembly cannot be found. In this case, I tell it to check the currently loaded assemblies and return one if there is a match, which there should be for FluentNHibernate. Try sticking this as the first line in WebApiConfig.Register

public static void Register()
{
    AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
        {
            return AppDomain.CurrentDomain.GetAssemblies()
                .Where(a => a.FullName == args.Name).FirstOrDefault();
        };

    // the rest of WebApiConfig.Register...
}
brettsam
  • 2,702
  • 1
  • 15
  • 24