Попытка внедрить отчет PowerBI в приложение WebSharper Client Server F#

Я начал с загруженной демонстрации бритвы PowerBIEmbedded_AppOwnsData C#, которая работает, как и ожидалось. Затем я попытался сделать то же самое, начиная с проекта WebSharper, но пока безуспешно. Проблема возникает, когда я пытаюсь создать объект PowerBIClient.

Сначала рабочий C#

...
// Create a user password cradentials.
var credential = new UserPasswordCredential(Username, Password);
// Authenticate using created credentials
var authenticationContext = new AuthenticationContext(AuthorityUrl);
var authenticationResult = await authenticationContext.AcquireTokenAsync(ResourceUrl, ClientId, credential);
var tokenCredentials = new TokenCredentials(authenticationResult.AccessToken, "Bearer");
// Create a Power BI Client object. It will be used to call Power BI APIs.
using (var client = new PowerBIClient(new Uri(ApiUrl), tokenCredentials))
{
...   

А теперь код F#, который не работает:

...
let credential = new UserPasswordCredential(Username, Password)
let authenticationContext = new AuthenticationContext(AuthorityUrl)
let authenticationResult = 
    authenticationContext.AcquireTokenAsync(ResourceUrl, ClientId, credential)
    |> Async.AwaitTask |> Async.RunSynchronously
let tokenCredentials = new TokenCredentials(authenticationResult.AccessToken, "Bearer")
let client = new PowerBIClient(new Uri(ApiUrl), tokenCredentials)
...

Проект компилируется без ошибок, но во время выполнения генерирует исключение; Когда let client = ... выполняется, я получаю:

Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, 
Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. 
The located assembly's manifest definition does not match the assembly 
reference. (Exception from HRESULT: 0x80131040) 

=== Pre-bind state information ===
LOG: DisplayName = Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, 
PublicKeyToken=30ad4fe6b2a6aeed
 (Fully-specified)
LOG: Appbase = file:///C:/Root/Project/NCF/NCF.BPP1/
LOG: Initial PrivatePath = C:\Root\Project\NCF\NCF.BPP1\bin
Calling assembly : Microsoft.Rest.ClientRuntime, Version=2.0.0.0, 
Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: 
C:\Root\Project\NCF\NCF.BPP1\web.config
LOG: Using host configuration file: 
\\aunpmfps1\mydocs$\Franco.Tiveron\IISExpress\config\aspnet.config
LOG: Using machine configuration file from 
C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Newtonsoft.Json, Version=6.0.0.0, 
Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
LOG: Attempting download of new URL 
file:///C:/Users/franco.tiveron/AppData/Local/Temp/Temporary ASP.NET 
Files/vs/6323d2e3/834678d6/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL 
file:///C:/Users/franco.tiveron/AppData/Local/Temp/Temporary ASP.NET 
Files/vs/6323d2e3/834678d6/Newtonsoft.Json/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL 
file:///C:/Root/Project/NCF/NCF.BPP1/bin/Newtonsoft.Json.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing 
terminated.

Пожалуйста помоги. Заранее спасибо.


person Franco Tiveron    schedule 07.09.2017    source источник
comment
Я считаю, что вам нужно настроить перенаправление сборки в файле app.config, но я точно не знаю, как это сделать. Если вы используете пакет для получения зависимостей пакета NuGet, я знаю, что в пакете есть функция, позволяющая сделать это за вас. Как вы получаете зависимости в своем проекте?   -  person rmunn    schedule 07.09.2017
comment
Я использую Visual Studio 2017   -  person Franco Tiveron    schedule 07.09.2017


Ответы (1)


Наконец я обнаружил, что добавление перенаправления в web.config устраняет проблему:

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.4.1.0" newVersion="4.4.1.0" />
      </dependentAssembly>

      <!-- Manual add BEGIN -->
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
          <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
      </dependentAssembly>
      <!-- Manual add END -->

    </assemblyBinding>
  </runtime>
  <system.web>
  <!-- NOTE: remove debug="true" to serve compressed JavaScript -->
    <compilation debug="true" targetFramework="4.0" />
    <httpRuntime targetFramework="4.0" />
  </system.web>
  <system.webServer>
    <modules>
      <add name="WebSharper.RemotingModule" type="WebSharper.Web.RpcModule, WebSharper.Web" />
      <add name="WebSharper.Sitelets" type="WebSharper.Sitelets.HttpModule, WebSharper.Sitelets" />
    </modules>
 </system.webServer>
</configuration>

Большое спасибо @rmunn за подсказку.

person Franco Tiveron    schedule 07.09.2017