Exception occurred in ConfigAddCameras when using full-width characters

Hello.

I found a bug in the ConfigAddCameras of the MIP SDK sample that causes an exception, and solution for this exception.

I’d like to share it.

This bug may occur in regions that use full-width characters (East Asia).

Please note that it is unlikely to occur in Europe or America.

Prerequisites:

A camera group with full-width characters, “TestGroup123” (full-width characters), already exists in XProtect 2024 R2 server.

Reproduction steps:

In the ConfigAddCameras of the MIP SDK sample, specify the camera group “TestGroup123” (half-width characters) and add a camera to the group.

Result:

An exception occurs in [ServerTask task = folder.AddDeviceGroup(groupName, “group added by tool”);] and the exception message “name” is displayed.

Reason:

The following is my speculation.

1. [CameraGroup groupExist = ms.CameraGroupFolder.CameraGroups.Where(x => x.Name == groupName).FirstOrDefault();] distinguishes between full-width and half-width characters, so “TestGroup123” (full-width characters) and “TestGroup123” (half-width characters) will be determined to be different groups.

2. [ServerTask task = folder.AddDeviceGroup(groupName, “group added by tool”);] does not distinguish between full-width and half-width characters, so an exception occurs when attempting to register a “group name that is already registered” even though it should be rejected.

Solution for this exception:

It needs to replace [CameraGroup groupExist = ms.CameraGroupFolder.CameraGroups.Where(x => x.Name == groupName).FirstOrDefault();] with the following method.

private CameraGroup CheckGroupExist(CameraGroupFolder alreadyRegFolder, string groupName)
        {
            const string FULLWIDTH = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!\"#$%&’()*+,-./:;<=>?@[\]^_`{|}~";
            const string HALFWIDTH = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
 
            // Group name to be registered
            string halfwidthGroupName = groupName;
            for (int i = 0; i < FULLWIDTH.Length; i++)
            {
                // Change to half-width characters
                halfwidthGroupName = halfwidthGroupName.Replace(FULLWIDTH[i], HALFWIDTH[i]);
            }
 
            // Check if it's already registered
            foreach (CameraGroup alreadyRegGroup in alreadyRegFolder.CameraGroups)
            {
                // Group name already registered in XProtect 2024R2
                string halfwidthAlreadyRegGroupName = alreadyRegGroup.Name;
                for (int i = 0; i < FULLWIDTH.Length; i++)
                {
                    // Change to half-width characters
                    halfwidthAlreadyRegGroupName = halfwidthAlreadyRegGroupName.Replace(FULLWIDTH[i], HALFWIDTH[i]);
                }
                if (halfwidthGroupName == halfwidthAlreadyRegGroupName)
                {
                    // The group name entered by the user matches the name of a group already registered.
                    return alreadyRegGroup;
                }
            }
            return null;
        }

Thank you for reporting this and suggesting an improvement to the sample.

I was able to observe that in Management Client (MC) you can create two groups that are named the same but with full-width and half-width characters. This means that the APIs and the MC does not implement the same behavior, which is a cause for starting an investigation.

I will give you feedback from this investigation, and let you know how Milestone will handle the issue.

Dear Bo,

Thank you for your reply.

Certainly, I confirmed that it can be create two groups that are named the same but with full-width and half-width characters in Management Client.

I’m look forward your investigation.

Hello,

Milestone Development has fixed this issue, and the fix will be included in the next release (2025 R2).

Hello Kiuchi-san,

Thank you for information for fixing.