Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
I started from the downloaded PowerBIEmbedded_AppOwnsData C# razor demo, which works as expected. Then I tried to do the same starting with a WebSharper project, but didn't have success so far. The problem occurs when I try to istantiate a PowerBIClient object.
First the working 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)) { ...
And now the F# code that doesn't work:
... 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) ...
The project compiles without errors, but at runtime it generates an exception; When the let client = ... is executed I get:
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.
Please help. Thank you in advance.
Solved! Go to Solution.
Finally I found that adding a redirection to web.config fixes the issue:
<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>
Finally I found that adding a redirection to web.config fixes the issue:
<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>
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
15 | |
3 | |
1 | |
1 | |
1 |
User | Count |
---|---|
26 | |
3 | |
2 | |
2 | |
2 |