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

Jassim Al Rahma 1,501 Reputation points
2023-02-05T18:56:56.52+00:00

Hi,

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);
    }
}

Thanks,

Jassim

C#
C#
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
    2023-02-05T19:56:32.54+00:00

    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
    2023-11-18T19:26:13.9833333+00:00

    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