FluentNHibernate and Nhibernate.Core dependency package issue

Dec 15, 2010 at 9:35 AM

Hi,

I have added a FluentNHibernate V1.1.1.694 to my Visual Studio 2010 project via Nuget, which has installed NHibernate.Core V3.0.0.3001.  The problem is, FluentNHibernate V1.1.1.694 still relies on NHibernate.Core V3.0.0.2001, which is not included in the Nuget package and doesn't appear to be available via Nuget any more, so my solution will not build.

Can you please update the official Nuget FluentNHibernate package to reference the correct NHibernate.Core version?

Thanks

Dec 15, 2010 at 2:44 PM

It probably does reference the correct version, but because it's not in the feed, it automatically looked for the next version up.

____
Rob
"Be passionate in all you do"

http://devlicio.us/blogs/rob_reynolds
http://ferventcoder.com
http://twitter.com/ferventcoder

On Dec 15, 2010 3:36 AM, "ndonkin" <notifications@codeplex.com> wrote:
> From: ndonkin
>
> Hi,I have added a FluentNHibernate V1.1.1.694 to my Visual Studio 2010 project via Nuget, which has installed NHibernate.Core V3.0.0.3001. The problem is, FluentNHibernate V1.1.1.694 still relies on NHibernate.Core V3.0.0.2001, which is not included in the Nuget package and doesn't appear to be available via Nuget any more, so my solution will not build.Can you please update the official Nuget FluentNHibernate package to reference the correct NHibernate.Core version?Thanks
>
>
Dec 15, 2010 at 3:49 PM

Yeah, I'm sure it's something straightforward like that, rather than a bug in Nuget.

Dec 15, 2010 at 4:40 PM

I should also have mentioned that I'm using Visual Studio 2010 Code Analysis and these are the build errors I receive:

CA0001 : The following error was encountered while reading module 'FluentNHibernate': Assembly reference cannot be resolved: NHibernate, Version=3.0.0.2001, Culture=neutral, PublicKeyToken=aa95f207798dfdb4.

 CA0058 : The referenced assembly 'NHibernate, Version=3.0.0.2001, Culture=neutral, PublicKeyToken=aa95f207798dfdb4' could not be found. This assembly is required for analysis...[truncated]

 

Dec 15, 2010 at 8:37 PM

That's strange, because 2001 is still on the feed.

Can you run "$Host.Version" to get the version of your NuGet client?

Also, can you run "List-Package -Remote nhi" to list the available packages?

Dec 16, 2010 at 8:32 AM

Hi David,

Here's what I get. 

Version *.2001 is there.  Do you know why it isn't being downloaded as part of FluentNHibernate?  I would rather use V*.3001 but I guess I'll have to wait for a new version of FluentNHibernate to be released?

PM> $Host.Version

Major  Minor  Build  Revision
-----    -----    -----    --------
1          0           10128  89     


PM> List-Package -Remote nhi

Id                                             Version                         Description                                 
--                                             -------                          -----------                                 
FluentNHibernate                 1.1.0.694                       Fluent, XML-less, compile safe, automated,...
FluentNHibernate                 1.1.1.694                       Fluent, XML-less, compile safe, automated,...
NHibernate.Core                   2.1.2.4000                     NHibernate is a mature, open source object...
NHibernate.Core                 3.0.0.2001                   NHibernate 3 Beta 1 - NHibernate is a matu...
NHibernate.Core                   3.0.0.3001                     NHibernate 3 RC1 - NHibernate is a mature,...
NHibernate.Linq                    1.0                                 NHibernate Linq support is based on the ex...
NHWebConsole                     0.2                                 Embedded web NHibernate console             
SolrNet.NHibernate               0.3.0                              NHibernate integration for SolrNet          

Dec 16, 2010 at 8:42 AM

I've just checked the FluentNHibernate website and V1.2.0.694 is now available:

http://fluentnhibernate.org/downloads

Can you please add this to the feed?

Dec 16, 2010 at 8:46 AM

I'm not sure why you end up getting 3001 with that  build.  Here is what I get with the same build:

PM> $Host.Version

Major  Minor  Build  Revision
-----  -----  -----  --------
1      0      10128  89      


PM> Install-Package FluentNHibernate
'NHibernate.Core (≥ 3.0.0.2001)' not installed. Attempting to retrieve dependency from source...
Done
'Iesi.Collections (≥ 1.0.1)' not installed. Attempting to retrieve dependency from source...
Done
'Antlr (≥ 3.1.3.42154)' not installed. Attempting to retrieve dependency from source...
Done
'Castle.Core (≥ 2.5.1)' not installed. Attempting to retrieve dependency from source...
Done
Successfully installed 'Iesi.Collections 1.0.1'
Successfully installed 'Antlr 3.1.3.42154'
Successfully installed 'Castle.Core 2.5.1'
Successfully installed 'NHibernate.Core 3.0.0.2001'
Successfully installed 'FluentNHibernate 1.1.1.694'
Successfully added 'Iesi.Collections 1.0.1' to Mvc3Application
Successfully added 'Antlr 3.1.3.42154' to Mvc3Application
Successfully added 'Castle.Core 2.5.1' to Mvc3Application
Successfully added 'NHibernate.Core 3.0.0.2001' to Mvc3Application
Successfully added 'FluentNHibernate 1.1.1.694' to Mvc3Application

PM> 

Could you run this same 'Install-Package FluentNHibernate' on a clean web app to see if you get anything different?

 

But note that even with 3001, you should be able to get things running by running:

Add-BindingRedirects

This will add a binding redirect to config that should allow things to load correctly.  Please let us know how that goes as that is a new feature! :)

Dec 16, 2010 at 8:47 AM
ndonkin wrote:

I've just checked the FluentNHibernate website and V1.2.0.694 is now available:

http://fluentnhibernate.org/downloads

Can you please add this to the feed?

Yes, it would be great to have whoever owns that package get the newest version up on the feed.

Dec 16, 2010 at 1:33 PM

I ran "Install-Package FluentNHibernate" on a new project and I get the same results as you, where it installs V*.2001, so I don't know when or why it starting referencing .3001 in my solution.  I did manage to get around the problem by explicitly installing the V*.2001 NHibernate.Core using this command:

Install-Package NHibernate.Core -version 3.0.0.2001

My solution now builds and I have both the .2001 and .3001 versions in my packages folder, so I didn't need to use Add-BindingRedirects.

Thanks for your help.

Developer
Dec 16, 2010 at 5:10 PM

The only reason you would have gotten 3.0.0.3001 instead of 3.0.0.2001 is if it was already installed, was that the case?

Dec 16, 2010 at 5:17 PM

Also, if you are able, would you mind testing the binding redirect command on a copy of your project?  You can run 'Update-Package NHibernate.Core' to get back to 3001.  This would be good data for us about how the binding redirect works in real scenarios. Thanks!

Dec 17, 2010 at 8:45 AM

I tried running Add-BindingRedirects -All but nothing happened?

Dec 17, 2010 at 8:53 AM

There is no -All flag.  In fact, you should get an error if you try to use -All:

PM> Add-BindingRedirects -All
Add-BindingRedirects : A parameter cannot be found that matches parameter name 'All'.
At line:1 char:26
+ Add-BindingRedirects -All <<<< 
    + CategoryInfo          : InvalidArgument: (:) [Add-BindingRedirects], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,NuGet.VisualStudio.Cmdlets.AddBindingRedirectsCmdlet

Have you tried running it without flags?

Dec 17, 2010 at 8:58 AM

One more thing: you need to build the project before running this command.

Dec 17, 2010 at 11:00 AM

Sorry, I actually ran the "Add-BindingRedirects All" (without the -) and nothing happened.

Yesterday I explicitly downloaded NHibernate 3.0.0.2001 via Nuget so that my solution would build again.  I just ran the following to update NHibernate.Core to V3.0.0.3001:

PM> Update-Package NHibernate.Core [Project Name]
'Iesi.Collections 1.0.1' already installed
'Antlr 3.1.3.42154' already installed
'Castle.Core 2.5.2' already installed
'NHibernate.Core 3.0.0.3001' already installed
Successfully removed 'NHibernate.Core 3.0.0.2001' from [Project Name]
Uninstalling 'NHibernate.Core 3.0.0.2001' might cause 'FluentNHibernate 1.1.1.694' to be broken
The directory is not empty.

Successfully uninstalled 'NHibernate.Core 3.0.0.2001'
Successfully added 'NHibernate.Core 3.0.0.3001' to NCFE.Repositories

I then ran Add-BindingRedirects as you suggested and got the following:

PM> Add-BindingRedirects

Name                   : NHibernate
Culture               : neutral
PublicKeyToken         : aa95f207798dfdb4
ProcessorArchitecture : 
NewVersion             : 3.0.0.3001
OldVersion             : 0.0.0.0-3.0.0.3001
CodeBaseHref          
CodeBaseVersion    
PublisherPolicy      

These changes were made to my web.config:

<dependentAssembly>        
<assemblyIdentity name="NHibernate" publicKeyToken="aa95f207798dfdb4" culture="neutral" />        
<bindingRedirect oldVersion="0.0.0.0-3.0.0.3001" newVersion="3.0.0.3001" />      
</dependentAssembly>

I now get the following build errors:

MSBUILD : error : CA0001 : The following error was encountered while reading module 'FluentNHibernate': Assembly reference cannot be resolved: NHibernate, Version=3.0.0.2001, Culture=neutral, PublicKeyToken=aa95f207798dfdb4.
MSBUILD : error : CA0058 : The referenced assembly 'NHibernate, Version=3.0.0.2001, Culture=neutral, PublicKeyToken=aa95f207798dfdb4' could not be found. This assembly is required for analysis and was referenced by: [Path to DLLs].

Developer
Dec 17, 2010 at 5:02 PM

You might be hitting another issue we found in RC:
http://nuget.codeplex.com/workitem/471

Try the newest build here and see if you still get the same issue.

Dec 23, 2010 at 1:00 PM
dfowler wrote:

You might be hitting another issue we found in RC:
http://nuget.codeplex.com/workitem/471

Try the newest build here and see if you still get the same issue.

I am also having this issue.  I updated to the latest version you posted.  I try the Add-BindingRedirects, and it seems that nothing happens (at least not visible to me).  My project is a Class Library that references log4net which is strongly named.  I'm trying to add a binding redirect specifically for a proof of concept to show that NuGet will work for us.

 

Dec 23, 2010 at 1:47 PM

Grrr... ignore that last post.  It's working perfectly.  The problem is that by some amazing stroke of bad luck I was testing this concept using log4net 1.2.9 and 1.2.10.  It turns out that someone screwed up and changed the PublicKeyToken between those two versions.  See link here: http://forum.springframework.net/archive/index.php/t-470.html

Now that I use a better example, it works fine.

That said, I think the whole binding-redirect issue could possibly be handled either when one installs a package or builds a new package from a .nuspec file.  Since we are already specifying which versions of a dependency we deem acceptable when we call "nuget.exe pack", could we not at that point add the BindingRedirect automatically?

-Alan-

Dec 23, 2010 at 4:34 PM

Note that package and assembly versions don't have to match, and there could in fact be multiple unrelated assemblies in a package.  So we can't use the package version in the binding redirect generation.  That being said, there could be ways to make it more automatic in the future.

Mar 24, 2011 at 1:01 AM

Hi guys,

I am still having this issue with the latest build. We grabed the latest NuGet src code and built the extension ourselves. Then I installed FluentNHibernate. That installed NHibernate 3.0.0.4000 for me automatically.  I checked the feed and 3.0.0.2001 is still in the list.   My tests all pass but when I compile my project with Code Analysis turned on, it complained about NHibernate 3.0.0.2001 is missing...  I tried Add-BindingRedirects and nothing happened.  I fixed the issue by uninstall 3.0.0.4000 with force flag and then installed 3.0.0.2001. 

Then, here is the second issue. I ran Add-BindingRedirects again and nothing happened. Then I get File IO errors running my tests becuase the project is still referencing 3.0.0.4000... I can manually change the configuration file to fix it but was Add-BindingRedirects suppose to do it?  

Recap :)  of my questions:

  1. It looks like the lastest FluentNHibernate requires NHibernate 3.0.0.2001 but how comes NuGet installs 3.0.0.4000 for it?
  2. After I uninstall .4000 and installed 3.0.0.2001, should Add-BindingRedirects command fix my project configuration?

Thanks,

Henry

Version of my extension

PM> $Host.Version
 
Major  Minor  Build  Revision
-----  -----  -----  --------
1      3      0      0   
Mar 24, 2011 at 1:14 AM

The fact that nuget installs 4000 instead of 2001 is by design.

With the latest build that you're running, the binding redirect should have been added automatically into your web.config when you installed FluentNH. Can you check? It should look like:

      <dependentAssembly>
        <assemblyIdentity name="NHibernate" publicKeyToken="aa95f207798dfdb4" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.4000" newVersion="3.0.0.4000" />
      </dependentAssembly>

This allows 4000 to be automatically loaded at runtime even though 2001 is being referenced.

Mar 24, 2011 at 1:51 AM

Hi David,

Thanks for the prompt rely!  Yes. the binding redirect was inserted automatically in my app.config and it looks same as what you posted. However when I compile my project with code analysis turned on with all Microsoft rules, I get the following...

Error 3 CA0058 : The referenced assembly 'NHibernate, Version=3.0.0.2001, Culture=neutral, PublicKeyToken=aa95f207798dfdb4' could not be found. This assembly is required for analysis and was referenced by: C:\temp\Scratch\src\MyProject.UnitTests\bin\Debug\MyProject.UnitTests.dll.  MyProject.UnitTests

It looks like the compiler is still looking for NHibernate 3.0.0.2001 rather than 3.0.0.4000 that specified in binding redirect...

Mar 24, 2011 at 2:04 AM

I see, it's probably because the analysis tools are not smart enough to take the binding redirects into account, though I'm not sure. I wasn't quite able to repro this. Could you give me the exact steps that lead to this? What I tried:

  1. New Console app
  2. Install FluentNH using NuGet (which gets NH 4001)
  3. Run code analysis

And that succeeds. But maybe there is a bit more to it to get to that situation?

Mar 24, 2011 at 2:13 AM

Hi David,

You are right. I just realized this is not a NuGet issue anymore. :)

 For those who are interested,  You need to go to

%PROGRAMFILES%\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop

Open FxCopCmd.exe.config and change AssemblyReferenceResolveMode from StrongName to StrongNameIgnoringVersion

Mar 24, 2011 at 2:14 AM

Good to hear, I didn't know about this setting!

Coordinator
Mar 24, 2011 at 3:19 AM

Is this worth adding to our known issues, even though it’s not exactly our issue? If so, any volunteers for a write-up that I can cut and paste into our notes? J]

Mar 24, 2011 at 4:45 AM
Haacked wrote:

Is this worth adding to our known issues, even though it’s not exactly our issue? If so, any volunteers for a write-up that I can cut and paste into our notes? J]

I will give it a shot but I have to tell you my first language is not English. :)  Is there a standard template for Known Issues?  Should I just post the notes here or send to your email?

Coordinator
Mar 24, 2011 at 4:59 AM

Take a look at: http://nuget.codeplex.com/documentation?title=Known%20Issues

Use that format. Post it here. J

Mar 24, 2011 at 12:49 PM
Edited Mar 24, 2011 at 12:55 PM

You might get the following error if you install FluentNHibernate in your project with the Package Manager console and then compile your project with "Code Analysis" turned on.  

Error 3 CA0058 : The referenced assembly 'NHibernate, Version=3.0.0.2001, Culture=neutral, PublicKeyToken=aa95f207798dfdb4' could not be found. This assembly is required for analysis and was referenced by: C:\temp\Scratch\src\MyProject.UnitTests\bin\Debug\MyProject.UnitTests.dll.  MyProject.UnitTests

David Kean has an Excellent BLog post explains this issue.  By default, FluentNHibernate requires NHibernate 3.0.0.2001. However, by design NewGet will install NHibernate 3.0.0.4000 in your project. The project will compile if code analysis is not turned on.  In contract to the compiler, code analysis tool is not smart enough to use 3.0.0.4000 instead of 3.0.0.2001. We can work around the issue by either installing NHibernate 3.0.0.2001 or tell the code analysis tool to behave the same as the compiler by doing the following:

  1. go to %PROGRAMFILES%\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop.
  2. Open FxCopCmd.exe.config and change AssemblyReferenceResolveMode from StrongName to StrongNameIgnoringVersion.
  3. Save the change and rebuild your project. 
Mar 24, 2011 at 12:53 PM

David,

I just noticed you need to use FluentNHibernate in your code to trigger code analysis on related packages. That might be why the error didn't come up in your test project.

Cheers,

Henry

Mar 24, 2011 at 7:19 PM

Ah yes, you're probably right. Though strangely, when I added some trivial code that uses FLuentNH (e.g. var type = typeof(SomeRandomFNHType)), doing the analysis got me a warning and not an error.

Coordinator
Mar 24, 2011 at 10:15 PM

Thank you! I tweaked it slightly, but you can see it at the bottom here: http://nuget.codeplex.com/wikipage?title=Known%20Issues

J