How to Solve Partial method must have an implementation part because it has accessibility modifiers

Jassim Al Rahma 1,501 Reputation points


How can I solve this error:

Partial method must have an implementation part because it has accessibility modifiers.

in the below code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

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



An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
9,935 questions
{count} vote

2 answers

Sort by: Most helpful
  1. Reza Aghaei 4,931 Reputation points MVP

    You can remove the private access modifier.

    According to the documentations:

    A partial method isn't required to have an implementation in the following cases:

    • It doesn't have any accessibility modifiers (including the default private).
    • It returns void.
    • It doesn't have any out parameters.
    • It doesn't have any of the following modifiers virtual, override, sealed, new, or extern.

    Any method that doesn't conform to all those restrictions (for example, public virtual partial void method), must provide an implementation.

    To learn more, take a look at:

  2. DP Technology LLC 1 Reputation point

    The way we have this working involves what @Reza Aghaei said plus a little more.

    Set up your partial methods in your cross-platform class as @Reza Aghaei said but then also create public methods to access the private partial methods.

    Yes, the documentation is wrong and within that documentation if you click on the Sample you will see it doesn't exist anymore.

    This is what we have:

    public partial class WakeLock 
    	partial void PlatformAcquire();     
    	partial void PlatformRelease();       
    	public void Acquire() { this.PlatformAcquire(); }     
    	public void Release() { this.PlatformRelease(); } 
    0 comments No comments