Home > database >  WCF customUserNamePasswordValidatorType error - Could not load file or assembly 'CustomUserName
WCF customUserNamePasswordValidatorType error - Could not load file or assembly 'CustomUserName

Time:10-25

I have created a simply WCF web service and require WCF Security with username/password added to the service and have read through the following MS documentation enter image description here

If you want to see this class, here is the code for it:

Imports System.IdentityModel.Selectors

Public Class CustomUserNameValidator
    Inherits UserNamePasswordValidator

    Public Overrides Sub Validate(ByVal userName As String, ByVal password As String)
        If userName Is Nothing OrElse password Is Nothing Then
            Throw New ArgumentNullException()
        End If

        If Not (userName = "user" AndAlso password = "pass123") Then
            Throw New FaultException("Unknown Username or Incorrect Password")
        End If
    End Sub
End Class

Also, this is all that shows in Properties for the file.

enter image description here

If you can please help with the error, that would be very much appreciated.

CodePudding user response:

You must to be sure that the “Build Action” on the “CustomUserNameValidator.vb” Properties is set to “Compile”. It seems to be set on “Content” based on what you are describing.

The image shows how you can do that or take a look here: enter image description here

CodePudding user response:

The reason I was getting the problem above was because I needed to set this in the web.config

    <serviceCredentials>
        <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="CustomUserNameValidator, App_Code" />
    </serviceCredentials>

When I went to the following path on my machine, the only dll was App_Code.tjgywzog.dll so figured the assembly is just App_Code and then it just has to use the class name CustomUserNameValidator since my code is not using namespaces.

  • Related