nhibernate / fluent-nhibernate

Fluent NHibernate!
BSD 3-Clause "New" or "Revised" License
1.66k stars 685 forks source link

Assembly FullNames can be too long for NHibernate mapping filenames #84

Closed palfrey closed 11 years ago

palfrey commented 13 years ago

When wanting a good unique filename for the .hbm.xml's, the Assembly.FullName will be unique, but it may exceed Windows 260 character path limits.

e.g. I had a class with two generic parameters that had the FullName

GapFillVerification.Models.Audits.ThingAudit`2[[GapFillVerification.Models.Record, gapfill-verification-models, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[GapFillVerification.Models.Audits.LockAction, gapfill-verification-models, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]

That's 298 characters on it's own, ignoring any path before it.

Exception trace was:

 [exec] The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
 [exec]    at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength)
 [exec]    at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
 [exec]    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
 [exec]    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
 [exec]    at System.Xml.XmlTextWriter..ctor(String filename, Encoding encoding)
 [exec]    at FluentNHibernate.PersistenceModel.<>c__DisplayClass5.<WriteMappingsTo>b__4(HibernateMapping mapping) in C:\projects\jagregory-fluent-nhibernate-c24de5a\src\FluentNHibernate\PersistenceModel.cs:line 246
 [exec]    at FluentNHibernate.PersistenceModel.WriteMappingsTo(Func`2 writerBuilder, Boolean shouldDispose) in C:\projects\jagregory-fluent-nhibernate-c24de5a\src\FluentNHibernate\PersistenceModel.cs:line 269
 [exec]    at FluentNHibernate.PersistenceModel.WriteMappingsTo(String folder) in C:\projects\jagregory-fluent-nhibernate-c24de5a\src\FluentNHibernate\PersistenceModel.cs:line 242
 [exec]    at FluentNHibernate.Cfg.FluentMappingsContainer.Apply(PersistenceModel model) in C:\projects\jagregory-fluent-nhibernate-c24de5a\src\FluentNHibernate\Cfg\FluentMappingsContainer.cs:line 131
 [exec]    at FluentNHibernate.Cfg.MappingConfiguration.Apply(Configuration cfg) in C:\projects\jagregory-fluent-nhibernate-c24de5a\src\FluentNHibernate\Cfg\MappingConfiguration.cs:line 84
 [exec]    at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration() in C:\projects\jagregory-fluent-nhibernate-c24de5a\src\FluentNHibernate\Cfg\FluentConfiguration.cs:line 252

http://msdn.microsoft.com/en-us/library/Aa365247#maxpath indicates the use of the "\?\" prefix might help, but then XmlTextWriter starts throwing exceptions about "invalid characters"...

chester89 commented 12 years ago

maybe you meant Type.FullName (cause your example is 100% not an assembly name)? also, I'm no expert at .NET file API, but I think if Windows set its limits to characters for a filepath, there's no way we can overcome it. even if that's possible - that wouldn't be portable in a sense that this project is built on machines with different configurations and OS versions. if I'm wrong, please correct me

chester89 commented 12 years ago

just looked into it - it seems that the only way to overcome this is via Win32 API. that's just not good. btw, it'll be more easy to use a guid instead of full name, and then append a class name to it.

jagregory commented 12 years ago

The main considerations are: Make sure the filename is unique, and make sure the file can easily be identified as entity it represents.

Using a GUID appended to the class name sounds like a good compromise.

On Thu, Oct 11, 2012 at 7:06 AM, Gleb Chermennov notifications@github.comwrote:

just looked into it - it seems that the only way to overcome this is via Win32 API. that's just not good. btw, it'll be more easy to use a guid instead of full name, and then append a class name to it.

— Reply to this email directly or view it on GitHubhttps://github.com/jagregory/fluent-nhibernate/issues/84#issuecomment-9317548.

James Gregory

Tel: +61 (0) 411 619 513 Website: http://jagregory.com Twitter: @jagregory http://twitter.com/jagregory

chester89 commented 11 years ago

closing this for now as it's not an issue related to Fluent NHibernate