question

Ryan-3643 avatar image
0 Votes"
Ryan-3643 asked MarileeTurscak-MSFT answered

Why does custom Azure B2C policy, SignUpInvitation.xml, throw `Object reference not set to an instance of an object` error?

Greetings,

I'm trying to get the sample project, from this repo at the following URL, to work ...

https://github.com/azure-ad-b2c/samples/tree/master/policies/invite

The sample project includes a custom B2C policy, SignUpInvitation.xml, and a web project. It's my basic understanding that the included custom policy essentially requires a signed token in order to access the policy. The sample basically uses this as an "invitation" step to restrict access to the sign up policy. This is what I am after and so I do believe this sample is pointing me in the right direction. I'm just trying to get it to work, now.

My issue is that, after configuring what I believe to be all the required settings, I am getting an error from within the B2C policy - I think. So, I'll first walk through the steps of how I produce the error ...

producing the error


I run the provided web project and put in my email and then click invite. I receive the invitation email, which contains the link to the custom B2C policy - SignUpInvitation.xml. I click the link and am taken to the policy, but am given a page that says that an exception has occurred - "AADB2C: An exception has occurred."

Unable to find any additional debug info, we added our Application Insights configuration to the custom policy so that it logs output to App Insights. Now, within AI, I can see that the policy is producing the following error ...

       {
         ""Kind"": ""Action"",
         ""Content"": ""Web.TPEngine.StateMachineHandlers.GetRelyingPartyInputClaimsHandler""
       },
       {
         ""Kind"": ""FatalException"",
         ""Content"": {
           ""Time"": ""7:05 PM"",
           ""Exception"": {
             ""Kind"": ""Handled"",
             ""HResult"": ""80004003"",
             ""Message"": ""Object reference not set to an instance of an object."",
             ""Data"": {}
           }
         }
       }

So, there is a clear error, but still the message is a bit vague. And this is where I'm stuck. I'm unsure how to further debug this and pinpoint what is causing the reference error.

things I looked into


I have spent several days debugging this, and so through that course of debugging I've looked at basically every little bit of info that I could find regarding this. I'm just not well versed in the B2C policy XML scripts, and that seems to be a very deep and technical topic. It's a topic I am interested in learning, but just need some help on how to debug the scripts, etc.

One thing I did notice is that the Action in the above error mentions that it's getting the input claims. So, it looks to me like perhaps there is an issue in the policy, or my configuration, in getting the claims. So, I went up the "stack trace", in App Insights, for the above message and found the following action and result ...

   {
     ""Kind"": ""Predicate"",
     ""Content"": ""Web.TPEngine.StateMachineHandlers.InitiatingMessageValidationHandler""
   },
   {
     ""Kind"": ""HandlerResult"",
     ""Content"": {
       ""Result"": false,
       ""RecorderRecord"": {
         ""Values"": [
           {
             ""Key"": ""Validation"",
             ""Value"": {
               ""Values"": [
                 {
                   ""Key"": ""SubmittedBy"",
                   ""Value"": ""Application""
                 },
                 {
                   ""Key"": ""ProtocolProviderType"",
                   ""Value"": ""OpenIdConnectProtocolProvider""
                 }
               ]
             }
           }
         ]
       },
       ""Statebag"": {
         ""MSG(e4c7c6a9-8023-4cf7-9a34-c920e8325284)"": {
           ""c"": ""2020-03-20T19:05:48.1325292Z"",
           ""k"": ""MSG(e4c7c6a9-8023-4cf7-9a34-c920e8325284)"",
           ""v"": ""{\""TenantId\"":\""wibradixdev.onmicrosoft.com\"",\""PolicyId\"":\""B2C_1A_signup_invitation\"",\""RedirectUri\"":\""https://jwt.ms/\"",\""AdditionalParameters\"":{\""TEST\"":\""TEST\"",\""p\"":\""B2C_1A_signup_invitation\""},\""Nonce\"":\""0eefd73e94224dc69d8766dd219180e6\"",\""ClientId\"":\""30639331-3c2c-4ade-8c36-814dfe007170\"",\""ResponseType\"":\""id_token\"",\""ResponseRedirector\"":{\""URI\"":\""https://jwt.ms\"",\""D\"":false,\""WF\"":true},\""Scope\"":\""openid\"",\""AppModelVersion\"":1,\""ScopedProviders\"":[]}"",
           ""p"": true,
           ""t"": ""OAuth2""
         },
         ""CMESSAGE"": {
           ""c"": ""2020-03-20T19:05:48.1325292Z"",
           ""k"": ""CMESSAGE"",
           ""v"": ""e4c7c6a9-8023-4cf7-9a34-c920e8325284"",
           ""p"": true
         },
         ""IMESSAGE"": {
           ""c"": ""2020-03-20T19:05:48.1325292Z"",
           ""k"": ""IMESSAGE"",
           ""v"": ""e4c7c6a9-8023-4cf7-9a34-c920e8325284"",
           ""p"": true
         },
         ""ComplexItems"": ""_MachineEventQ, TCTX, ORCH_IDX, REPRM, IC""
       },
       ""PredicateResult"": ""True""
     }
   }

This action seems to be doing some type of validation, but I noticed that the result returns false, which usually means some sort of failure? I'm unsure in this case.

how do I proceed ?


Can you please help me out or point me in the right direction on how to figure this out? I deployed the sample web project to Azure, and you can access that here if you'd like to see what I'm seeing. If you have access to App Insights, you might be able to access my logs using the below information. The error in question occurred on 3/24/2020, 3:45:28.039 PM, with ikey and itemid 5d95a95b-6887-4798-a984-98a0a9d32d53 and 8a3a3e80-6de6-11ea-a0a3-ab73ec95556d.

App Insights Subscription Id: 265b7109-497d-42bc-8a20-fa6399a96a9c
App Insights Instrumentation Key: 5d95a95b-6887-4798-a984-98a0a9d32d53

Also, I attached the error message output here just in case you cannot see them in App Insights.

Also, here is a link to the full error text, from App Insights. This is linked to from my Github issue for the same related question.

Thank you!


azure-ad-b2c
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MarileeTurscak-MSFT avatar image
0 Votes"
MarileeTurscak-MSFT answered

Hi Ryan,

I apologize for the late reply and wanted to check if you were able to get this resolved. Are you still facing this issue?

"Object reference not set to an instance of an object" - indicates that you are trying to access member fields, or function types, on an object reference that points to null. That means the reference to an Object which is not initialized.

It looks like you also posted this on Stackoverflow and the issue was related to an incorrectly set metadata field in the technical profile. Can you confirm if this was the same case? https://stackoverflow.com/questions/60835115/why-does-custom-azure-b2c-policy-signupinvitation-xml-throw-object-reference

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.