Fody / Costura

Embed references as resources
MIT License
2.37k stars 273 forks source link

Fody: An unhandled exception occurred. The specified path, file name, or both are too long #216

Closed quantasm closed 6 years ago

quantasm commented 7 years ago

Hello,

This is just some feedback on a bug if the filepath is too long. Exception details are below.

3>MSBUILD : error : Fody: An unhandled exception occurred: 3>MSBUILD : error : Exception: 3>MSBUILD : error : 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. 3>MSBUILD : error : StackTrace: 3>MSBUILD : error : at System.IO.PathHelper.GetFullPathName() 3>MSBUILD : error : at System.IO.Path.LegacyNormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths) 3>MSBUILD : error : at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths) 3>MSBUILD : error : at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength) 3>MSBUILD : error : 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, Boolean checkHost) 3>MSBUILD : error : at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) 3>MSBUILD : error : at ModuleWeaver.Embed(String prefix, String fullPath, Boolean compress) in C:\projects\costura\src\Costura\ResourceEmbedder.cs:line 204 3>MSBUILD : error : at ModuleWeaver.EmbedResources(Configuration config) in C:\projects\costura\src\Costura\ResourceEmbedder.cs:line 39 3>MSBUILD : error : at ModuleWeaver.Execute() in C:\projects\costura\src\Costura\ModuleWeaver.cs:line 33 3>MSBUILD : error : at lambda_method(Closure , Object ) 3>MSBUILD : error : at InnerWeaver.ExecuteWeavers() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 182 3>MSBUILD : error : at InnerWeaver.Execute() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 83 3>MSBUILD : error : Source: 3>MSBUILD : error : mscorlib 3>MSBUILD : error : TargetSite: 3>MSBUILD : error : Int32 GetFullPathName() 3>MSBUILD : error : 3> Fody: Finished Fody 1411ms.

punker76 commented 7 years ago

I got this error too after updating from v1.3.3 to latest v1.6.2. I tested a little bit and the v1.4.1 is the last which works. My project is under c:\Users\<USER>\Documents\Git\ and yes it has some sub folders.

Error       Fody: An unhandled exception occurred:
Exception:
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.
StackTrace:
   at System.IO.PathHelper.GetFullPathName()
   at System.IO.Path.LegacyNormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
   at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
   at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength)
   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, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at ModuleWeaver.Embed(String prefix, String fullPath, Boolean compress) in C:\projects\costura\src\Costura\ResourceEmbedder.cs:line 204
   at ModuleWeaver.EmbedResources(Configuration config) in C:\projects\costura\src\Costura\ResourceEmbedder.cs:line 39
   at ModuleWeaver.Execute() in C:\projects\costura\src\Costura\ModuleWeaver.cs:line 33
   at lambda_method(Closure , Object )
   at InnerWeaver.ExecuteWeavers() in C:\Code\Fody\Fody\FodyIsolated\InnerWeaver.cs:line 181
   at InnerWeaver.Execute() in C:\Code\Fody\Fody\FodyIsolated\InnerWeaver.cs:line 86
Source:
mscorlib
TargetSite:
Int32 GetFullPathName() MahApps.Metro.Caliburn.Demo.NET40           

Solution is MahApps.Metro and the error occures with MahApps.Metro.Caliburn.Demo.NET40.

gavinschultz commented 6 years ago

After debugging both 1.4.1 and 1.6.2 it looks like the difference is in the cache file used during resource embedding:

This difference of just a few characters was enough to push one of the cache file paths over the 260-character limit. As a workaround I renamed my project directory to be slightly shorter.

Although there is no output logging of the cache file, the principle seems to be that if you have a project at, say, c:\dev\Project1\Project1.csproj which is embedding the assembly c:\lib\Assembly1.dll, then the cache file at build time will resolve to something like:

c:\dev\Project1\obj\Release\Costura\C3848473E42E2F9B4D0A00180EA9ADE654432587.Assembly1.dll.compressed

You can see how those characters might add up, particularly on a build server where the working directory is likely to be more deeply nested.

punker76 commented 6 years ago

Still getting these Fody System.IO.PathTooLongException together with Fody.Costura

Fody 2.3.24 Costura.Fody 1.6.2

Annoying to see, that the path is limited.

I put all my sources normally under c:\Users\<USER>\Documents\Git\. So the only workaround with the current Fody is, not to work with current Fody.

Error       Fody: An unhandled exception occurred:
Exception:
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.
Type:
System.IO.PathTooLongException
StackTrace:
   at System.IO.LongPathHelper.Normalize(String path, UInt32 maxPathLength, Boolean checkInvalidCharacters, Boolean expandShortPaths)
   at System.IO.Path.NewNormalizePath(String path, Int32 maxPathLength, Boolean expandShortPaths)
   at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
   at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength)
   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, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at ModuleWeaver.Embed(String prefix, String fullPath, Boolean compress) in C:\projects\costura\src\Costura\ResourceEmbedder.cs:line 204
   at ModuleWeaver.EmbedResources(Configuration config) in C:\projects\costura\src\Costura\ResourceEmbedder.cs:line 39
   at ModuleWeaver.Execute() in C:\projects\costura\src\Costura\ModuleWeaver.cs:line 33
   at lambda_method(Closure , Object )
   at InnerWeaver.ExecuteWeavers() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 200
   at InnerWeaver.Execute() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 102
Source:
mscorlib
TargetSite:
System.String Normalize(System.String, UInt32, Boolean, Boolean)    MahApps.Metro.Caliburn.Demo.NET40           
SimonCropp commented 6 years ago

can someone upload a small repro?

SimonCropp commented 6 years ago

closing this as stale. if it is still an problem please raise a new issue

lumogox commented 5 years ago

I still get the same issue with version 3.1.6

mikeprag commented 5 years ago

Still getting this with 3.3.2 - Is there any fix or workaround?

SimonCropp commented 5 years ago

@mikeprag https://github.com/Fody/Costura/issues/216#issuecomment-417300866

can someone upload a small repro?

punker76 commented 5 years ago

@SimonCropp @mikeprag @lumogox I don't get this error with the latest tools anymore, but I can't tell from which version on.

mikeprag commented 5 years ago

Here's the full error when I try to build the project. I am using v3.3.2 Costura.Fody and Fody v4.0.2. None of the paths seem to be over the limit in obj/Debug/Costura folder. I'll go with moving the project to a shorter path location for now.

Let me know if you need anything from me

Thanks

Mike

Error       Fody: An unhandled exception occurred:
Exception:
Failed to execute weaver C:\Development\Synthesis\Core\EOSTasks\Synthesis.Task.RunBusinessTransformerLight\packages\Costura.Fody.3.3.2\build\..\netclassicweaver\Costura.Fody.dll
Type:
System.Exception
StackTrace:
   at InnerWeaver.ExecuteWeavers()
   at InnerWeaver.Execute()
Source:
FodyIsolated
TargetSite:
Void ExecuteWeavers()
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.
Type:
System.IO.PathTooLongException
StackTrace:
   at System.IO.LongPathHelper.Normalize(String path, UInt32 maxPathLength, Boolean checkInvalidCharacters, Boolean expandShortPaths)
   at System.IO.Path.NewNormalizePath(String path, Int32 maxPathLength, Boolean expandShortPaths)
   at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
   at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength)
   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, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at ModuleWeaver.Embed(String prefix, String fullPath, Boolean compress, Boolean addChecksum, Boolean disableCleanup)
   at ModuleWeaver.EmbedResources(Configuration config)
   at ModuleWeaver.Execute()
   at InnerWeaver.ExecuteWeavers()
Source:
mscorlib
TargetSite:
System.String Normalize(System.String, UInt32, Boolean, Boolean)    Synthesis.Task.RunBusinessTransformerLight              Build   
SimonCropp commented 5 years ago

@mikeprag to be using fody you should be a patron.

SimonCropp commented 5 years ago

ok i have deployed 3.3.3 with some better logging. so if someone want to update and re-build there should be some more info in the stack trace