Skip to content

[BUG]: EntraMockResponsePlugin crashes on startup: Unable to resolve service for type X509Certificate2 #1610

@hkachouti

Description

@hkachouti

Description

Starting Dev Proxy with EntraMockResponsePlugin enabled fails immediately with a DI resolution error on all versions from v2.0.0 onwards (tested v2.0.0, v2.2.0, v2.3.0). The same configuration works correctly on v1.3.0.

Expected behaviour

Dev Proxy starts and intercepts requests to login.microsoftonline.com, returning mock token responses.

Actual behaviour

Immediate crash:

fail    An error occurred while running Dev Proxy
Exception Details: System.InvalidOperationException: Unable to resolve service for type
'System.Security.Cryptography.X509Certificates.X509Certificate2'
while attempting to activate 'DevProxy.Plugins.Mocking.EntraMockResponsePlugin'.
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(...)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(...)
   ...

Steps to reproduce

  1. Install Dev Proxy v2.3.0 (or any v2.x):

    winget install DevProxy.DevProxy --version 2.3.0 --force
    
  2. Create devproxyrc.json:

    {
      "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v2.3.0/rc.schema.json",
      "plugins": [
        {
          "name": "EntraMockResponsePlugin",
          "enabled": true,
          "pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll",
          "configSection": "entraMocks"
        }
      ],
      "urlsToWatch": [
        "https://login.microsoftonline.com/*"
      ],
      "entraMocks": {
        "mocksFile": "entra-mocks.json"
      }
    }
  3. Create entra-mocks.json:

    {
      "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v2.3.0/mockresponseplugin.mocksfile.schema.json",
      "mocks": [
        {
          "request": {
            "url": "https://login.microsoftonline.com/*/oauth2/v2.0/token",
            "method": "POST"
          },
          "response": {
            "statusCode": 200,
            "body": {
              "token_type": "Bearer",
              "expires_in": 3600,
              "access_token": "mock-access-token"
            },
            "headers": [
              { "name": "Content-Type", "value": "application/json" }
            ]
          }
        }
      ]
    }
  4. Run:

    devproxy --config-file devproxyrc.json
    

Dev Proxy Version

2.3.0

Operating system (environment)

Windows

Shell

PowerShell

Configuration file

{
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v1.3.0/rc.schema.json",
"asSystemProxy": false,
"validateSchemas": false,
"port": 8001,
"apiPort": 9500,
"plugins": [
{
"name": "EntraMockResponsePlugin",
"enabled": true,
"pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll",
"configSection": "entraMocksPlugin"
}
],
"urlsToWatch": [
"https://login.microsoftonline.com/*"
],
"entraMocksPlugin": {
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v1.3.0/mockresponseplugin.schema.json",
"mocksFile": "entra-mocks.json"
},
"logLevel": "information",
"showSkipMessages": true,
"showTimestamps": true
}

Additional Info

No response

Metadata

Metadata

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions