function [interfaceList, default] = getNetInterfaces(assemblyPath)
% GETNETINTERFACES Return the .NET interfaces in a given assembly.
    % If the input path is empty, return an empty interface list
    interfaceList = {};
    if ~isempty(assemblyPath) &&  ~exist(assemblyPath, 'dir') 
        fid = fopen(assemblyPath);
        if( fid > 0 )
            fclose(fid);
            % Reflect on the assembly and populate interfaceList with the pure
            % interfaces the assembly contains. Uses dtsutils.dll, which may 
            % fail to load if it is installed remotely and the user's MATLAB
            % configuration file (MATLAB.exe.config) does not have
            % loadFromRemoteSources set to true.
            try
                NET.addAssembly([matlabroot '\toolbox\dotnetbuilder\bin\' computer('arch') '\dtsutils.dll']);
            catch ex
                netVer = char(System.Environment.Version.ToString());
                if strcmp(ex.identifier, 'MATLAB:NET:CLRException:AddAssembly')
                    msg = getString(message('BuilderNE:typesafe:ErrMsg'));
                    if ~isempty(regexp(netVer, '^4[.0-9]+', 'once'))
                        error(message('BuilderNE:typesafe:RemoteSourceException',msg));
                    else
                        error(message('BuilderNE:typesafe:CASException',msg));
                    end
                else
                    rethrow(ex)
                end
            end
            try
                netInterfaces = dtsutils.TypeSafeUtils.GetInterfaceList(assemblyPath);
                interfaceList = {netInterfaces.Length};
                for k = 1:netInterfaces.Length
                    interfaceList{k} = char(netInterfaces(k));
                end
                %A nested interface has a '+' in the name returned through
                %reflection. For example foo.bar+SomeInterface. Sanitize it so it's
                %valid C# code.
                interfaceList = strrep(interfaceList,'+','.');
            catch dtex
                if(strcmp(class(dtex.ExceptionObject),'System.IO.FileLoadException' ))
                    error(message('BuilderNE:typesafe:FileLoadException', strrep(char(dtex.ExceptionObject.InnerException.Message.ToString()), '\', '\\')));
                else
                    error(message('BuilderNE:typesafe:Error', strrep(char(dtex.ExceptionObject.Message.ToString()), '\', '\\')));
                end


            end
        end
    end
    default = '';
    if ~isempty(interfaceList)
        default = interfaceList{1};
    end
end
