public static int?ValidateAsPositiveInteger(string value, string propertyName, IDictionary <string, string> parameters, string fileName)
        {
            int convertedValue;

            if (!IsValidParameter(value, propertyName, parameters, fileName))
            {
                convertedValue = ConvertProperty <int>(value, propertyName, fileName);
                if (convertedValue < 1)
                {
                    ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                        TraceType,
                        fileName,
                        StringResources.ImageBuilderError_ValueMustBePositiveInt,
                        convertedValue,
                        propertyName);
                }
            }
            else
            {
                // Resource is specified as a parameter
                // Parse it from parameter list and get the value for the specified key
                string parameterName = value.Substring(1, value.Length - 2);
                convertedValue = ConvertProperty <int>(parameters[parameterName], propertyName, fileName);
                // Do not check and throw if convertedValue is less than 1 as application should be provisioned with default params
                // We shouldn't allow creation with incorect params
            }
            return(convertedValue);
        }
        private void ValidateManageAssembly(string serviceManifestFileName, FileLocator fileLocator, string entryPointValue)
        {
            AssemblyName assemblyName = null;

            try
            {
                assemblyName = new AssemblyName(entryPointValue);
            }
            catch (Exception exception)
            {
                ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                    exception,
                    TraceType,
                    serviceManifestFileName,
                    StringResources.ImageBuilderError_InvalidValue,
                    "EntryPoint",
                    entryPointValue);
            }

            if (!fileLocator.AssemblyExists(assemblyName))
            {
                ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                    TraceType,
                    serviceManifestFileName,
                    StringResources.ImageBuilderError_EntryPointInvalidOrNotFound,
                    entryPointValue,
                    fileLocator.DirectoryOrArchivePath);
            }
        }
Ejemplo n.º 3
0
        public void Add(string name)
        {
            if (this.hashSet.Contains(name))
            {
                if (string.IsNullOrEmpty(this.fileName))
                {
                    ImageBuilderUtility.TraceAndThrowValidationError(
                        TraceType,
                        StringResources.ImageBuilderError_DuplicateElementFound,
                        this.elementName,
                        this.propertyName,
                        name);
                }
                else
                {
                    ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                        TraceType,
                        this.fileName,
                        StringResources.ImageBuilderError_DuplicateElementFound,
                        this.elementName,
                        this.propertyName,
                        name);
                }
            }

            this.hashSet.Add(name);
        }
        private void ValidateEntryPoint(string serviceManifestFileName, FileLocator fileLocator, DllHostEntryPointType entryPoint)
        {
            bool hasNative = false;

            foreach (var item in entryPoint.Items)
            {
                ManagedAssemblyType managedAssembly = item as ManagedAssemblyType;
                UnmanagedDllType    unmanagedDll    = item as UnmanagedDllType;

                hasNative = hasNative || unmanagedDll != null;

                if (unmanagedDll != null)
                {
                    this.ValidateEntryPointPath(serviceManifestFileName, fileLocator, unmanagedDll.Value.Trim());
                }
                else
                {
                    this.ValidateManageAssembly(serviceManifestFileName, fileLocator, managedAssembly.Value.Trim());
                }
            }

            if (hasNative && entryPoint.IsolationPolicy != DllHostEntryPointTypeIsolationPolicy.DedicatedProcess)
            {
                ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                    TraceType,
                    serviceManifestFileName,
                    StringResources.ImageBuilderError_InvalidIsolationPolicyForNativeDll);
            }
        }
        private void ValidateEntryPointPath(string serviceManifestFileName, FileLocator fileLocator, string program, bool isExternalExecutable = false)
        {
            string entryPointPath = this.GetEntryPointPath(program, serviceManifestFileName);

            if (string.IsNullOrEmpty(entryPointPath))
            {
                ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                    TraceType,
                    serviceManifestFileName,
                    StringResources.ImageBuilderError_NullOrEmptyError,
                    "EntryPoint");
            }
            else if (entryPointPath.IndexOfAny(System.IO.Path.GetInvalidPathChars()) != -1)
            {
                ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                    TraceType,
                    serviceManifestFileName,
                    StringResources.ImageBuilderError_InvalidValue,
                    "EntryPoint",
                    entryPointPath);
            }
            else if (System.IO.Path.IsPathRooted(entryPointPath))
            {
                ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                    TraceType,
                    serviceManifestFileName,
                    StringResources.ImageBuilderError_RootedEntryPointNotSupported,
                    entryPointPath);
            }

            if (isExternalExecutable)
            {
                ImageBuilder.TraceSource.WriteInfo(
                    TraceType,
                    "EntryPointPath {0} is external executable",
                    entryPointPath);
            }
            else if (!fileLocator.FileExists(entryPointPath))
            {
#if !DotNetCoreClrLinux
                if (string.IsNullOrEmpty(Path.GetExtension(entryPointPath)) && fileLocator.FileExists(entryPointPath + ".exe"))
                {
                    return;
                }
#endif
                ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                    TraceType,
                    serviceManifestFileName,
                    StringResources.ImageBuilderError_EntryPointNotFound,
                    entryPointPath);
            }
        }
 void ValidateServiceTypeCombination(
     string serviceManifestFileName,
     int implicitServiceTypeCount,
     int normalServiceTypeCount,
     bool hasServiceGroupTypes)
 {
     if (implicitServiceTypeCount > 0 && (normalServiceTypeCount > 0 || hasServiceGroupTypes))
     {
         ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
             TraceType,
             serviceManifestFileName,
             StringResources.ImageBuilderError_InvalidServiceTypeCombination);
     }
 }
 private void ValidatePlacementConstraints(string fileName, string placementConstraints)
 {
     if (!string.IsNullOrEmpty(placementConstraints))
     {
         if (!InteropHelpers.ExpressionValidatorHelper.IsValidExpression(placementConstraints))
         {
             ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                 TraceType,
                 fileName,
                 StringResources.ImageBuilderError_InvalidValue,
                 "PlacementConstraint",
                 placementConstraints);
         }
     }
 }
        public static double?ValidateAsPositiveZeroIncluded(decimal value, string propertyName, string fileName)
        {
            double convertedValue = (double)value;

            if (convertedValue < 0)
            {
                ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                    TraceType,
                    fileName,
                    StringResources.ImageBuilderError_ValueMustNotBeNegative,
                    convertedValue,
                    propertyName);
            }

            return(convertedValue);
        }
        public static bool IsValidParameter(string value, string propertyName, IDictionary <string, string> parameters, string fileName)
        {
            if (ImageBuilderUtility.IsParameter(value))
            {
                string parameterName = value.Substring(1, value.Length - 2);
                if (!parameters.ContainsKey(parameterName))
                {
                    ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                        TraceType,
                        fileName,
                        StringResources.ImageBuilderError_UndefinedParameter,
                        propertyName,
                        parameterName);
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 10
0
        public static int?ValidateAsPositiveInteger(string value, string propertyName, IDictionary <string, string> parameters, string fileName)
        {
            int convertedValue;

            if (!IsValidParameter(value, propertyName, parameters, fileName))
            {
                convertedValue = ConvertProperty <int>(value, propertyName, fileName);
                if (convertedValue < 1)
                {
                    ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                        TraceType,
                        fileName,
                        StringResources.ImageBuilderError_ValueMustBePositiveInt,
                        convertedValue,
                        propertyName);
                }
            }
            else
            {
                return(null);
            }
            return(convertedValue);
        }
Ejemplo n.º 11
0
        private void InitializeAndValidateApplicationParameters(ApplicationManifestTypeParameter[] parameters)
        {
            Dictionary <string, string> validatedParameters = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            if (parameters != null)
            {
                foreach (ApplicationManifestTypeParameter parameter in parameters)
                {
                    if (validatedParameters.ContainsKey(parameter.Name))
                    {
                        ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                            TraceType,
                            this.GetApplicationManifestFileName(),
                            StringResources.ImageBuilderError_DuplicateParametersFound,
                            parameter.Name);
                    }

                    validatedParameters.Add(parameter.Name, parameter.DefaultValue);
                }
            }

            this.ApplicationParameters = validatedParameters;
        }
        private void ValidateConfiguration(ApplicationTypeContext context)
        {
            Dictionary <string, IEnumerable <ConfigPackage> > configurationPackageDictionary = new Dictionary <string, IEnumerable <ConfigPackage> >();

            foreach (var serviceManifest in context.ServiceManifests)
            {
                configurationPackageDictionary.Add(serviceManifest.ServiceManifestType.Name, serviceManifest.ConfigPackages);
            }

            ApplicationManifestTypeServiceManifestImport[] serviceManifestImports = context.ApplicationManifest.ServiceManifestImport;
            bool hasEncryptedParameter = false;

            foreach (KeyValuePair <string, IEnumerable <ConfigPackage> > configKeyValuePair in configurationPackageDictionary)
            {
                if (configKeyValuePair.Value != null)
                {
                    ApplicationManifestTypeServiceManifestImport matchingServiceManifestImport = serviceManifestImports.FirstOrDefault <ApplicationManifestTypeServiceManifestImport>(
                        serviceManifestImport => ImageBuilderUtility.Equals(serviceManifestImport.ServiceManifestRef.ServiceManifestName, configKeyValuePair.Key));

                    ReleaseAssert.AssertIf(
                        matchingServiceManifestImport == null,
                        "Could not find matching ServiceManifest with Name {0}",
                        configKeyValuePair.Key);

                    foreach (ConfigPackage configurationPackage in configKeyValuePair.Value)
                    {
                        ImageBuilder.TraceSource.WriteInfo(
                            TraceType,
                            "Validating the configuration. ApplicationTypeName:{0}, ServiceManifestName:{1}, ConfigPackageName:{2}",
                            context.ApplicationManifest.ApplicationTypeName,
                            matchingServiceManifestImport.ServiceManifestRef.ServiceManifestName,
                            configurationPackage.ConfigPackageType.Name);

                        if (configurationPackage.SettingsType != null && configurationPackage.SettingsType.Section != null)
                        {
                            string configPackageDirectory = context.BuildLayoutSpecification.GetConfigPackageFolder(configKeyValuePair.Key, configurationPackage.ConfigPackageType.Name);
                            string configPackageArchive   = context.BuildLayoutSpecification.GetSubPackageArchiveFile(configPackageDirectory);

                            if (!FabricDirectory.Exists(configPackageDirectory) && !FabricFile.Exists(configPackageArchive))
                            {
                                continue;
                            }

                            ConfigOverrideType matchingConfigOverride = null;
                            if (matchingServiceManifestImport.ConfigOverrides != null)
                            {
                                matchingConfigOverride = matchingServiceManifestImport.ConfigOverrides.FirstOrDefault <ConfigOverrideType>(
                                    configOverride => ImageBuilderUtility.Equals(configOverride.Name, configurationPackage.ConfigPackageType.Name));
                            }

                            string settingsFileName = context.BuildLayoutSpecification.GetSettingsFile(configPackageDirectory);

                            DuplicateDetector sectionDuplicateDetector = new DuplicateDetector("Section", "Name", settingsFileName);
                            foreach (SettingsTypeSection section in configurationPackage.SettingsType.Section)
                            {
                                sectionDuplicateDetector.Add(section.Name);

                                SettingsOverridesTypeSection matchingConfigOverrideSection = null;
                                if (matchingConfigOverride != null && matchingConfigOverride.Settings != null)
                                {
                                    matchingConfigOverrideSection = matchingConfigOverride.Settings.FirstOrDefault <SettingsOverridesTypeSection>(
                                        configOverrideSection => ImageBuilderUtility.Equals(configOverrideSection.Name, section.Name));
                                }

                                if (section.Parameter != null)
                                {
                                    DuplicateDetector settingDuplicateDetector = new DuplicateDetector("Parameter", "Name", settingsFileName);
                                    foreach (SettingsTypeSectionParameter parameter in section.Parameter)
                                    {
                                        settingDuplicateDetector.Add(parameter.Name);

                                        if (!hasEncryptedParameter)
                                        {
                                            hasEncryptedParameter = parameter.IsEncrypted;
                                        }

                                        if (parameter.MustOverride)
                                        {
                                            SettingsOverridesTypeSectionParameter matchingOverrideParameter = null;
                                            if (matchingConfigOverrideSection != null && matchingConfigOverrideSection.Parameter != null)
                                            {
                                                matchingOverrideParameter = matchingConfigOverrideSection.Parameter.FirstOrDefault <SettingsOverridesTypeSectionParameter>(
                                                    configOverrideSetting => ImageBuilderUtility.Equals(configOverrideSetting.Name, parameter.Name));
                                            }

                                            if (matchingOverrideParameter == null)
                                            {
                                                ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                                                    TraceType,
                                                    settingsFileName,
                                                    StringResources.ImageBuilderError_ParameterNotOverriden,
                                                    parameter.Name);
                                            }
                                        }

                                        if (!String.IsNullOrEmpty(parameter.Type))
                                        {
                                            this.VerifySourceLocation(parameter.Name, "Settings.xml", parameter.Type);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (hasEncryptedParameter &&
                RequireCertACLingForUsers(context.ApplicationManifest.Principals) &&
                (context.ApplicationManifest.Certificates == null || context.ApplicationManifest.Certificates.SecretsCertificate == null))
            {
                ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                    TraceType,
                    context.GetApplicationManifestFileName(),
                    StringResources.ImageBuilderError_EncryptedSettingsNoCertInAppManifest);
            }
        }
        private void ValidateServiceManifests(ApplicationTypeContext context)
        {
            IEnumerable <ServiceManifestType> serviceManifestTypes = context.GetServiceManifestTypes();

            // Validates the ServiceManifest
            var duplicateServiceTypeDetector = new DuplicateDetector("ServiceType", "ServiceTypeName");

            foreach (ServiceManifestType serviceManifestType in serviceManifestTypes)
            {
                ImageBuilder.TraceSource.WriteInfo(
                    TraceType,
                    "Validating ServiceManifest. ApplicationTypeName:{0}, ServiceManifestName:{1}, ServiceManifestVersion:{2}",
                    context.ApplicationManifest.ApplicationTypeName,
                    serviceManifestType.Name,
                    serviceManifestType.Version);

                string serviceManifestFileName = context.GetServiceManifestFileName(serviceManifestType.Name);

                if (!ManifestValidatorUtility.IsValidName(serviceManifestType.Name))
                {
                    ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                        TraceType,
                        serviceManifestFileName,
                        StringResources.ImageBuilderError_InvalidName_arg2,
                        "ServiceManifest",
                        serviceManifestType.Name,
                        Path.DirectorySeparatorChar,
                        StringConstants.DoubleDot);
                }

                if (!ManifestValidatorUtility.IsValidVersion(serviceManifestType.Version))
                {
                    ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                        TraceType,
                        serviceManifestFileName,
                        StringResources.ImageBuilderError_InvalidVersion_arg2,
                        "ServiceManifestVersion",
                        serviceManifestType.Version,
                        Path.DirectorySeparatorChar,
                        StringConstants.DoubleDot);
                }

                var implicitServiceTypeCount = 0;
                var normalServiceTypeCount   = 0;
                var hasServiceGroupTypes     = false;

                foreach (object manifestServiceTypeType in serviceManifestType.ServiceTypes)
                {
                    string serviceTypeName      = null;
                    string placementConstraints = null;
                    if (manifestServiceTypeType is ServiceTypeType serviceTypeType)
                    {
                        serviceTypeName      = serviceTypeType.ServiceTypeName;
                        placementConstraints = serviceTypeType.PlacementConstraints;

                        if (IsImplicitServiceType(serviceTypeType))
                        {
                            ++implicitServiceTypeCount;
                        }
                        else
                        {
                            ++normalServiceTypeCount;
                        }
                    }
                    else
                    {
                        hasServiceGroupTypes = true;

                        ServiceGroupTypeType serviceGroupTypeType = (ServiceGroupTypeType)manifestServiceTypeType;
                        serviceTypeName      = serviceGroupTypeType.ServiceGroupTypeName;
                        placementConstraints = serviceGroupTypeType.PlacementConstraints;
                    }

                    this.ValidatePlacementConstraints(serviceManifestFileName, placementConstraints);

                    duplicateServiceTypeDetector.Add(serviceTypeName);
                }

                this.ValidateServiceTypeCombination(
                    serviceManifestFileName,
                    implicitServiceTypeCount,
                    normalServiceTypeCount,
                    hasServiceGroupTypes);

                var activatorCodePackageCount = 0;

                // Validates the CodePackage in the ServiceManifest
                var codePackageDuplicateDetector = new DuplicateDetector("CodePackage", "Name", serviceManifestFileName);
                foreach (CodePackageType codePackageType in serviceManifestType.CodePackage)
                {
                    if (!ManifestValidatorUtility.IsValidName(codePackageType.Name))
                    {
                        ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                            TraceType,
                            serviceManifestFileName,
                            StringResources.ImageBuilderError_InvalidName_arg2,
                            "CodePackage",
                            codePackageType.Name,
                            Path.DirectorySeparatorChar,
                            StringConstants.DoubleDot);
                    }

                    if (!ManifestValidatorUtility.IsValidVersion(codePackageType.Version))
                    {
                        ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                            TraceType,
                            serviceManifestFileName,
                            StringResources.ImageBuilderError_InvalidVersion_arg2,
                            "CodePackageVersion",
                            codePackageType.Version,
                            Path.DirectorySeparatorChar,
                            StringConstants.DoubleDot);
                    }

                    codePackageDuplicateDetector.Add(codePackageType.Name);

                    if (codePackageType.IsActivator)
                    {
                        if (implicitServiceTypeCount > 0)
                        {
                            ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                                TraceType,
                                serviceManifestFileName,
                                StringResources.ImageBuilderError_GuestAppWithActivatorCodePackage);
                        }

                        activatorCodePackageCount++;
                        if (activatorCodePackageCount > 1)
                        {
                            ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                                TraceType,
                                serviceManifestFileName,
                                StringResources.ImageBuilderError_MultipleActivatorCodePackage);
                        }
                    }

                    var codePackageFolderName  = context.BuildLayoutSpecification.GetCodePackageFolder(serviceManifestType.Name, codePackageType.Name);
                    var codePackageArchiveName = context.BuildLayoutSpecification.GetSubPackageArchiveFile(codePackageFolderName);

                    FileLocator fileLocator = null;
                    if (FabricFile.Exists(codePackageArchiveName))
                    {
                        fileLocator = new FileLocator(codePackageArchiveName, true);
                    }
                    else if (FabricDirectory.Exists(codePackageFolderName))
                    {
                        fileLocator = new FileLocator(codePackageFolderName, false);
                    }
                    else
                    {
                        // If the code package doesn't exist, it means it was already provisioned;
                        // validation must have passed at the time of first provisioning
                        continue;
                    }

                    if (codePackageType.SetupEntryPoint != null)
                    {
                        this.ValidateEntryPointPath(serviceManifestFileName, fileLocator, codePackageType.SetupEntryPoint.ExeHost.Program);
                    }

                    if (codePackageType.EntryPoint != null && codePackageType.EntryPoint.Item != null)
                    {
                        if (codePackageType.EntryPoint.Item is DllHostEntryPointType)
                        {
                            this.ValidateEntryPoint(serviceManifestFileName, fileLocator, (DllHostEntryPointType)codePackageType.EntryPoint.Item);
                        }
                        else if (codePackageType.EntryPoint.Item is ExeHostEntryPointType)
                        {
                            this.ValidateEntryPoint(serviceManifestFileName, fileLocator, (ExeHostEntryPointType)codePackageType.EntryPoint.Item);
                        }
                    }
                }

                // Validates the ConfigPackage in the ServiceManifest
                if (serviceManifestType.ConfigPackage != null)
                {
                    DuplicateDetector configPackageDuplicateDetector = new DuplicateDetector("ConfigPackage", "Name", serviceManifestFileName);
                    foreach (ConfigPackageType configPackageType in serviceManifestType.ConfigPackage)
                    {
                        if (!ManifestValidatorUtility.IsValidName(configPackageType.Name))
                        {
                            ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                                TraceType,
                                serviceManifestFileName,
                                StringResources.ImageBuilderError_InvalidName_arg2,
                                "ConfigPackage",
                                configPackageType.Name,
                                Path.DirectorySeparatorChar,
                                StringConstants.DoubleDot);
                        }

                        if (!ManifestValidatorUtility.IsValidVersion(configPackageType.Version))
                        {
                            ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                                TraceType,
                                serviceManifestFileName,
                                StringResources.ImageBuilderError_InvalidVersion_arg2,
                                "ConfigPackageVersion",
                                configPackageType.Version,
                                Path.DirectorySeparatorChar,
                                StringConstants.DoubleDot);
                        }

                        configPackageDuplicateDetector.Add(configPackageType.Name);
                    }
                }

                // Validates the DataPackage in the ServiceManifest
                if (serviceManifestType.DataPackage != null)
                {
                    DuplicateDetector dataPackageDuplicateDetector = new DuplicateDetector("DataPackage", "Name", serviceManifestFileName);
                    foreach (DataPackageType dataPackageType in serviceManifestType.DataPackage)
                    {
                        if (!ManifestValidatorUtility.IsValidName(dataPackageType.Name))
                        {
                            ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                                TraceType,
                                serviceManifestFileName,
                                StringResources.ImageBuilderError_InvalidName_arg2,
                                "DataPackage",
                                dataPackageType.Name,
                                Path.DirectorySeparatorChar,
                                StringConstants.DoubleDot);
                        }

                        if (!ManifestValidatorUtility.IsValidVersion(dataPackageType.Version))
                        {
                            ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                                TraceType,
                                serviceManifestFileName,
                                StringResources.ImageBuilderError_InvalidVersion_arg2,
                                "DataPackageVersion",
                                dataPackageType.Version,
                                Path.DirectorySeparatorChar,
                                StringConstants.DoubleDot);
                        }

                        dataPackageDuplicateDetector.Add(dataPackageType.Name);
                    }
                }

                // Validates the Resources in the ServiceManifest
                if (serviceManifestType.Resources != null && serviceManifestType.Resources.Endpoints != null)
                {
                    DuplicateDetector resourceNameDuplicateDetector = new DuplicateDetector("Endpoint", "Name", serviceManifestFileName);
                    foreach (var endpoint in serviceManifestType.Resources.Endpoints)
                    {
                        if (endpoint.Name.Contains(';') || endpoint.Name.Contains(','))
                        {
                            ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                                TraceType,
                                serviceManifestFileName,
                                StringResources.ImageBuilderError_InvalidName_arg2,
                                "EndppointResource",
                                endpoint.Name,
                                ",",
                                ";");
                        }

                        if (!string.IsNullOrEmpty(endpoint.CodePackageRef))
                        {
                            var matchingCodePackage = serviceManifestType.CodePackage.FirstOrDefault(
                                codePackageType => ImageBuilderUtility.Equals(codePackageType.Name, endpoint.CodePackageRef));

                            if (matchingCodePackage == null)
                            {
                                ImageBuilderUtility.TraceAndThrowValidationErrorWithFileName(
                                    TraceType,
                                    serviceManifestFileName,
                                    StringResources.ImageBuilderError_InvalidRefSameFile,
                                    "CodePackageRef",
                                    endpoint.CodePackageRef,
                                    "EndppointResource",
                                    endpoint.Name,
                                    "CodePackage",
                                    "ServiceManifest");
                            }
                        }

                        resourceNameDuplicateDetector.Add(endpoint.Name);
                    }
                }
            }
        }