Ganesh
Ganesh

Reputation: 934

How to fix the "ConvertResourcesCases" in Xamarin Forms Android build?

I am facing an issue while building Xamarin Forms Android module application. The below error I am facing frequently.

Severity Code Description Project File Line Suppression State
Error The "ConvertResourcesCases" task failed unexpectedly.
System.IO.PathTooLongException: 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.
  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.InternalGetDirectoryName(String path)
  at System.IO.Path.GetDirectoryName(String path)
  at Xamarin.Android.Tools.Files.CopyIfChanged(String source, String destination)
  at Xamarin.Android.Tasks.MonoAndroidHelper.CopyIfChanged(String source, String destination)
  at Xamarin.Android.Tasks.ConvertResourcesCases.FixupResources(ITaskItem item, Dictionary 2 acwMap)
  at Xamarin.Android.Tasks.ConvertResourcesCases.FixupResources(Dictionary 2 acwMap)
  at Xamarin.Android.Tasks.ConvertResourcesCases.Execute()
  at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
  at Microsoft.Build.BackEnd.TaskBuilder<ExecuteInstantiatedTask>d__26.MoveNext() EHG.EmployeeApp.Mobile.Android

Please suggest and help me out, Thanks in advance.

Upvotes: 1

Views: 711

Answers (1)

York Shen
York Shen

Reputation: 9084

The "ConvertResourcesCases" task failed unexpectedly. System.IO.PathTooLongException: The specified path, file name, or both n are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

This means that the path is beyond the max that Windows allows. Try moving your solution to the root of your disk so that the path is smaller. For example, move it to :

D:\YourProject

EDIT :

I am facing this Issue in Release mode only, If I switch to Debug mode working fine.

I think in release mode, Windows has a more strict inspection mechanism. To verify this, I create a demo, here is the project path :

C:\Users\username\Downloads\CollapsingToolbarLayout\CollapsingToolbarLayout123\CollapsingToolbarLayout1234\CollapsingToolbarLayoutasd\CollapsingToolbarLayoutaasda\App1

It works fine in debug model, but facing the exact same Issue in Release mode.

But when I move this project to :

C:\Users\username\Downloads\CollapsingToolbarLayout\CollapsingToolbarLayout123\App1

It works fine in both debug model and Release mode. So you could move your project to a more short path, and I think this is a permanently solution.

Windows has a Maximum Path Length Limitation. You could see it in Windows Naming Files, Paths, and Namespaces :

Maximum Path Length Limitation In the Windows API (with some exceptions discussed in the following paragraphs), the maximum length for a path is MAX_PATH, which is defined as 260 characters. A local path is structured in the following order: drive letter, colon, backslash, name components separated by backslashes, and a terminating null character. For example, the maximum path on drive D is "D:\some 256-character path string" where "" represents the invisible terminating null character for the current system codepage. (The characters < > are used here for visual clarity and cannot be part of a valid path string.) This is the reason why you have the issue.

Another solution is use the long path tool. As PierceBoggan said :

the easiest way to avoid this issue is to move your source to the C:/ drive (or another location with fewer characters in the path) or install the long path tool.

Upvotes: 1

Related Questions