title: Microsoft.JSInterop.JSException: Could not find '<method>' in 'window'
body: <p>oof what a day, trying to figure out dynamically injecting sdk.js and create button tag with src = some url.</p>
  <p>I have added all my js code into a file  scripting to inject sdk based on params and kept under wwwroot, but for somereason my function is not able detect by server.js</p>
  <p>Exception that am getting is -
  <strong>Error: Microsoft.JSInterop.JSException: Could not find 'initializeSDK' in 'window'.</strong></p>
  <p>here's the js code i have</p>
  <pre><code>    window.initializeSDK = {
  
      ejectInjectSdk: function (action, environment) {
          var script = document.createElement('script');
          if (action == &quot;inject&quot;) {
              if (self === top) {
                  var antiClickjack = document.getElementById(&quot;antiClickjack&quot;);
                  antiClickjack.parentNode.removeChild(antiClickjack);
              } else {
                  top.location = self.location;
              }
  
  
              if (environment == 'Sandbox') {
  
                  script.type = 'text/javascript';
                  script.src = &quot;https://sandbox-assets.secure.checkout.visa.com/checkout-widget/resources/js/integration/v1/sdk.js&quot;;
                  document.body.append(script);
              } else if (environment == 'live') {
                  script.type = 'text/javascript';
                  script.src = &quot;https://assets.secure.checkout.visa.com/checkout-widget/resources/js/integration/v1/sdk.js&quot;;
                  document.body.append(script);
              }
  
          } else if (action == &quot;eject&quot;) {
              if (environment == 'Sandbox') {
                  $(&quot;script[src='https://sandbox-assets.secure.checkout.visa.com/checkout-widget/resources/js/integration/v1/sdk.js']&quot;).remove();
              } else if (environment == 'live') {
                  $(&quot;script[src='https://assets.secure.checkout.visa.com/checkout-widget/resources/js/integration/v1/sdk.js']&quot;).remove();
              }
  
          }
          $(&quot;#vcoholder&quot;).hide();
      },
  
      ejectInjectBtn: function (initpayload) {
          $(&quot;#vcoholder&quot;).append(&quot;&lt;img alt='Visa Checkout' class='v-button' role='button' src='https://sandbox.secure.checkout.visa.com/wallet-services-web/xo/button.png' /&gt;&quot;);
          onVisaCheckoutReady(initpayload);
          $(&quot;#vcoholder&quot;).show();
  
      },
  
      onVisaCheckoutReady: function (initpayload) {
  
          console.log(initpayload);
          V.init(initpayload);
          V.on(&quot;payment.success&quot;, function (payment) {
              console.log(payment);
              var obj = {};
              obj.isLive = false;
              obj.apikey = $.trim($(&quot;#apikey&quot;).val());
              obj.sharedsecretkey = $.trim($(&quot;#sharedsecretkey&quot;).val());
              obj.encapikey = $.trim($(&quot;#encapikey&quot;).val());
              obj.encsharedsecretkey = $.trim($(&quot;#encsharedsecretkey&quot;).val());
              obj.encKey = payment.encKey;
              obj.encPaymentData = payment.encPaymentData;
              obj.vInitRequest = payment.vInitRequest;
              obj.callid = payment.callid;
  
              console.log(&quot;Payload sending to server &quot; + JSON.stringify(obj));
  
              $.ajax({
                  type: &quot;POST&quot;,
                  url: '../api/Restful/Getresultsv2',
                  data: JSON.stringify(obj),
                  dataType: &quot;json&quot;,
                  success: function (result) {
                      console.log(result);
                      $(&quot;#displayJson&quot;).jsonViewer(result, {
                          collapsed: false,
                          withQuotes: true
                      })
                  }
              });
  
          });
          V.on(&quot;payment.cancel&quot;, function (payment) {
              console.log(JSON.stringify(payment));
          });
          V.on(&quot;payment.error&quot;, function (payment, error) {
              console.log(JSON.stringify(error));
          });
      }
  };
  </code></pre>
  <p>And complete razor page below-</p>
  <pre><code>@page &quot;/ClicktoPay&quot;
  @using Microsoft.AspNetCore.Authorization
  @using Zapy.Server.ViewModels
  @using Zapy.Server.Servcies
  @using Zapy.Server.Models.Clicktopay;
  @using Newtonsoft.Json;
  @inject CheckoutService Checkoutservice
  @inject IJSRuntime JSRuntime
  @using Microsoft.Extensions.Configuration
  @inject IConfiguration Configuration
  
  
  &lt;h3&gt;Component1&lt;/h3&gt;
  
  &lt;div id=&quot;nonsegmentedkeys&quot; class=&quot;row&quot;&gt;
  
      &lt;div class=&quot;col&quot;&gt;
          &lt;div class=&quot;card&quot; style=&quot;height: 560px;&quot;&gt;
              &lt;div class=&quot;card-body&quot;&gt;
                  &lt;EditForm Model=&quot;@clicktoPayViewModel&quot;&gt;
                      &lt;div id=&quot;segmentedkeys&quot;&gt;
                          &lt;div class=&quot;form-group&quot;&gt;
                              &lt;label for=&quot;encryptionapikey&quot;&gt;Encryption's Apikey&lt;/label&gt;
                              &lt;InputText class=&quot;form-control form-control-sm&quot; id=&quot;encryptionapikey&quot; @bind-Value=&quot;clicktoPayViewModel.EncryptionKey&quot; /&gt;
                          &lt;/div&gt;
                          &lt;div class=&quot;form-group&quot;&gt;
                              &lt;label for=&quot;encryptionsharedsecretkey&quot;&gt;Encryptions's Sharedsecret&lt;/label&gt;
                              &lt;InputText class=&quot;form-control form-control-sm&quot; id=&quot;encryptionsharedsecretkey&quot; @bind-Value=&quot;clicktoPayViewModel.EncryptionSharedsecret&quot; /&gt;
                          &lt;/div&gt;
                          &lt;div class=&quot;form-group &quot;&gt;
                              &lt;label for=&quot;inboundapikey&quot;&gt;Inbound Apikey&lt;/label&gt;
                              &lt;InputText class=&quot;form-control form-control-sm&quot; id=&quot;inboundapikey&quot; @bind-Value=&quot;clicktoPayViewModel.InboundApikey&quot; /&gt;
                          &lt;/div&gt;
                          &lt;div class=&quot;form-group&quot;&gt;
                              &lt;label for=&quot;inboundsharedsecret&quot;&gt;Inbound Sharedsecret&lt;/label&gt;
                              &lt;InputText class=&quot;form-control form-control-sm&quot; id=&quot;inboundsharedsecret&quot; @bind-Value=&quot;clicktoPayViewModel.InboundSharedsecret&quot; /&gt;
                          &lt;/div&gt;
  
                      &lt;/div&gt;
                  &lt;/EditForm&gt;
                  &lt;div id=&quot;vcoholder&quot;&gt;
                  &lt;/div&gt;
  
              &lt;/div&gt;
              &lt;div class=&quot;card-footer&quot;&gt;
                  &lt;button class=&quot;btn btn-primary&quot; @onclick=&quot;CreateClicktopay&quot;&gt;Initialize ClicktoPay&lt;/button&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class=&quot;col&quot;&gt;
          &lt;div class=&quot;card&quot;&gt;
              &lt;div class=&quot;card-body&quot;&gt;
                  &lt;h5 class=&quot;card-title&quot;&gt;Initialize parameters here&lt;/h5&gt;
                  &lt;textarea id=&quot;displayJson&quot; value=&quot;@clicktoPayViewModel.InitParameters&quot; style=&quot;width: 550px; height: 480px;&quot; rows=&quot;10&quot;&gt;&lt;/textarea&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
  &lt;/div&gt;
  
  
  @code {
      private ClicktoPayViewModel clicktoPayViewModel = new ClicktoPayViewModel();
  
      protected override async Task OnInitializedAsync()
      {
  
          clicktoPayViewModel = await Checkoutservice.GetClicktoPayDefaultAsync();
  
      }
  
      public async Task CreateClicktopay()
      {
  
          await JSRuntime.InvokeVoidAsync(&quot;initializeSDK.ejectInjectSdk&quot;, &quot;inject&quot;, &quot;Sandbox&quot;);
          await JSRuntime.InvokeVoidAsync(&quot;initializeSDK.ejectInjectBtn&quot;, clicktoPayViewModel.InitParameters);
  
      }
  }
  </code></pre>