user1640782
user1640782

Reputation: 11

Microsoft Information Protection -> ERROR: Default format doesn't support writing properties without protection

I'm using .net core 8

package: enter image description here

azure permsssions enter image description here

MY CODE:

public class AuthDelegateImplementation(ApplicationInfo appInfo) : IAuthDelegate { readonly ApplicationInfo _appInfo = appInfo;

public string AcquireToken(Identity identity, string authority, string resource, string claims)
{
    var authorityUri = new Uri(authority);
    authority = string.Format("https://{0}/{1}", authorityUri.Host, _appInfo.ApplicationId);


    var app = ConfidentialClientApplicationBuilder.CreateWithApplicationOptions(new ConfidentialClientApplicationOptions()
    {
        ClientId = _appInfo.ApplicationId,            
        ClientSecret = ""
    }).WithAuthority(authority).Build();
  
    string[] scopes = [resource[resource.Length - 1].Equals('/') ? $"{resource}.default" : $"{resource}/.default"];
    
    var result=  app.AcquireTokenForClient(scopes).ExecuteAsync().ConfigureAwait(false).GetAwaiter().GetResult();
    
    return result.AccessToken;
}



 // Instantiate the AuthDelegateImpl object, passing in AppInfo.
 var authDelegate = new AuthDelegateImplementation(tenantId, clientId, secretKey);
// Create MipConfiguration Object
var mipConfiguration = new MipConfiguration(appInfo, "mip_data", Microsoft.InformationProtection.LogLevel.Trace, false);

// Create MipContext using Configuration
var mipContext = MIP.CreateMipContext(mipConfiguration);

// Initialize file profile settings to create/use local state.
var profileSettings = new FileProfileSettings(mipContext,
                         CacheStorageType.OnDisk,
                         new ConsentDelegateImplementation());

// Load the Profile async and wait for the result.
var fileProfile = await MIP.LoadFileProfileAsync(profileSettings);

var engineSettings = new FileEngineSettings("engine-id", authDelegate, "", "en-US")
{
    Identity = new Identity($"{appInfo.ApplicationId}@domain.com")
};
var fileEngine = await fileProfile.AddEngineAsync(engineSettings);

// Get unified labels and apply a label
var labels = fileEngine.SensitivityLabels;

var labelToApply = labels.FirstOrDefault();//(l => l.Name == "Your Label Name"); // Replace with your label name

if (labelToApply != null)
{
 
    var handler = await fileEngine.CreateFileHandlerAsync("C:\\SharedFolder\\Contract.docx", "C:\\SharedFolder\\Contract.docx", false);
    //Set Labeling Options
    LabelingOptions labelingOptions = new LabelingOptions()
    {
        AssignmentMethod = AssignmentMethod.Standard
    };
    handler.SetLabel(labelToApply, labelingOptions, new ProtectionSettings());
    await handler.CommitAsync("C:\\SharedFolder\\Contract.docx");
}

System.NotSupportedException: 'Default format doesn't support writing properties without protection, CorrelationId=4829c8fa-8589-4577-bc38-e23d6c73ad7e, CorrelationId.Description=FileHandler'

i also change the await handler.CommitAsync("C:\SharedFolder\Contract.docx"); to a different not existed file await handler.CommitAsync("C:\SharedFolder\Contract_new.docx"); with the same result...

im always getting this error no matters the file/extension use... i do not find any related error on internet, please some help!!!

THX

Upvotes: 1

Views: 507

Answers (1)

Tom Moser
Tom Moser

Reputation: 786

That error indicates that the file isn't a valid DOCX file. Generally this occurs because you've renamed another file type to DOCX or you did a right-click->New to create a zero-byte DOCX file. You need to create a valid, empty DOCX from Word by creating a blank document and saving it.

Upvotes: 0

Related Questions