Error SaveService on Android

When using the code for Windows the class works and my document is loaded:

public partial class SaveService
{
    //Method to save document as a file and view the saved document.
    public partial void SaveAndView(string filename, string contentType, MemoryStream stream);
    public partial void ViewFile(string filePath);
}

but when I try to use the same code with any Android Device/Emulator, I get the following errors.

Partial method 'SaveService.SaveAndView(string, string, MemoryStream)' must have an implementation part because it has accessibility modifiers.
Partial method 'SaveService.ViewFile(string)' must have an implementation part because it has accessibility modifiers.

6 Replies

DA Dharanitharan Ayyasamy Syncfusion Team November 18, 2024 12:35 PM UTC

Hi Frederick Switzer,

From the provided error details, we suspect that you may have missed to implement the required “SaveAndView()” and “ViewFile()” implementation in the corresponding platform save files. For example, as like for Windows in “SaveWindows.cs”, you need to implement the method for Android on “SaveAndroid.cs“ location and for MacCatalyst – “SaveMac.cs” location and for iOS – “SaveIOS.cs” location.

Kindly implement the required logics in the mentioned platforms and try to run the sample. Now, it will run properly without throwing any errors. If you are still facing the error, kindly share us the issue reproducible sample using our below mentioned GitHub sample.

GitHub sample: Open-and-save-Word-document

Regards,
Dharanitharan A.



FS Frederick Switzer November 21, 2024 05:54 PM UTC

DA,

I've added the SaveAndroid.cs to my Android Platform but I'm still getting errors:


Partial method 'SaveService.ViewFile(string)' must have an implementation part because it has accessibility modifiers.

Partial method 'SaveService.SaveAndView(string, string, MemoryStream)' must have an implementation part because it has accessibility modifiers.


And when running the Github sample, for the an Android emulator, I get the following error.


Failed to generate Java type for class: AndroidX.Core.View.Accessibility.AccessibilityManagerCompat/IAccessibilityStateChangeListenerImplementor due to MAX_PATH: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Temp\DocIO-Examples-main\Read-and-Save-document\Open-and-save-Word-document\.NET-MAUI\Open-and-save-Word-document\obj\Debug\net8.0-android\android\src\mono\androidx\core\view\accessibility\AccessibilityManagerCompat_AccessibilityStateChangeListenerImplementor.java'.

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)

   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, Int32 bufferSize)

   at Microsoft.Android.Build.Tasks.Files.CopyIfStreamChanged(Stream stream, String destination) in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/Files.cs:line 170

   at Xamarin.Android.Tasks.GenerateJavaStubs.CreateJavaSources(IEnumerable`1 newJavaTypes, TypeDefinitionCache cache, MarshalMethodsClassifier classifier, Boolean useMarshalMethods)




DS Dharanya Sakthivel Syncfusion Team November 25, 2024 06:38 AM UTC

Frederick, we are currently verifying the reported query on the Android emulator and will provide further details within a day.

Regards,
Dharanya.



DS Dharanya Sakthivel Syncfusion Team November 25, 2024 05:57 PM UTC

Frederick,

Upon further analysis, we found that the reported error while running the GitHub sample is due to an excessively long file path (
C:\Temp\DocIO-Examples-main\Read-and-Save-document\Open-and-save-Word-document\.NET-MAUI\Open-and-save-Word-document\obj\Debug\net8.0-android\android\src\mono\androidx\core\view...)

To resolve this issue, we suggest reducing the path length of the sample location and then try to run the GitHub sample again. It should now work correctly.

If you continue to face any issues after running the GitHub sample, please provide more details about the problem. We will check further and provide you with an appropriate solution at the earliest.

Regards,
Dharanya.



FS Frederick Switzer November 27, 2024 08:01 PM UTC

Dharanya,


Where would you make that change?

Has the Github example been updated?



DS Dharanya Sakthivel Syncfusion Team November 28, 2024 09:43 AM UTC

Frederick,

We are maintaining our GitHub folder for all kinds of use cases with a relevant folder structure. Therefore, we have not modified the location in GitHub.

The issue occurs because the file path exceeds the maximum length (due to a lengthy folder structure). To resolve this, kindly download the sample from GitHub and move it to a folder with a shorter path (e.g.,
C:\Temp\Open-and-save-Word-document) to reduce the total length. This will allow you to build the project successfully.

Regards,
Dharanya.


Loader.
Up arrow icon