Public Folder Creation

we are creating public folder by this code

NetworkCredential credentials = (NetworkCredential)client.getCredentials();
String SMTPaddress = credentials.getUserName();
ExchangeFolderPermissionCollection pc = new ExchangeFolderPermissionCollection();

	//ExchangeFolderUserType userType = ExchangeFolderUserType.Anonymous
	
              //	int userType=client.getExchangeType();
	
	ExchangeFolderUserInfo userInfo = ExchangeFolderUserInfo.getAnonymousUser();
	userInfo.setUserAccountType(ExchangeFolderUserType.Anonymous);
	userInfo.setPrimarySmtpAddress(SMTPaddress);
	ExchangeFolderPermission folderPermission = new ExchangeFolderPermission(userInfo);
	folderPermission.canCreateItems(true);
	folderPermission.canCreateSubFolders(true);
	folderPermission.setDeleteItems(ExchangeFolderPermissionAction.Owned);	
	folderPermission.setEditItems(ExchangeFolderPermissionAction.Owned);		
	folderPermission.setFolderOwner(true);
	folderPermission.setFolderVisible(true);
	folderPermission.setReadItems(ExchangeFolderPermissionReadAccess.FullDetails);	
	folderPermission.setUserInfo(userInfo);
	folderPermission.setFolderContact(true);
	folderPermission.setPermissionLevel( ExchangeFolderPermissionLevel.Owner);	
	pc.addItem(folderPermission);
	
	client.createPublicFolder("ABC", pc);
	System.out.println("Folder ABC Created @ "+"xxx@xxxxx.onmicrosoft.com");

but getting this exception

Exception in thread “main” java.lang.ClassCastException: com.aspose.email.microsoft.schemas.exchange.services._2006.types.DistinguishedFolderIdType cannot be cast to com.aspose.email.microsoft.schemas.exchange.services._2006.types.FolderIdType
at com.aspose.email.zpv.a(SourceFile:377)
at com.aspose.email.zpm.createPublicFolder(SourceFile:6057)
at email.code.Check.main(Check.java:99)

@Harish2020

Can you please ensure which API version you are using on your end and also share the test account credentials with us for further investigation with us. We have fixed this issue since Aspose.Email for Java 20.7 on our end.