M-Files VAF 仅需要 json.net 版本 =10.0.3,而不是 >=10.0.3。这与 Microsoft.PowerBI.API 崩溃了,因为它在任何版本中都不支持这种确切的依赖关系。它从 7.0 -> 11.xx
我已经为此苦苦挣扎了一天。我一直在遵循本指南:
How to use two versions of the same DLL in the same project
我什至无法从 VS 添加第二个版本的 json.net。
然后我在 *.proj 文件和 app.config 中手动尝试,如下所示:
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Aliases>NewJson</Aliases>
</Reference>
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Aliases>OldJson</Aliases>
</Reference>
应用配置<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<codeBase version="7.0.0.0" href="FILE:///../packages/Newtonsoft.Json.7.0.1/lib/net45/Newtonsoft.Json.dll" />
<codeBase version="10.0.0.0" href="FILE:///../packages/Newtonsoft.Json.10.0.3/lib/net45/Newtonsoft.Json.dll" />
</dependentAssembly>
这甚至有效吗?还是首先在 GAC 中查找?我可以在 gac 中安装版本 7 和 10 吗? 无论哪种方式,通过 ../packages 或通过本地文件夹引用旧的,都会在 VS 中给我黄色感叹号。 VS 说只要我点击运行:
System.IO.FileNotFoundException:无法加载文件或程序集“Newtonsoft.Json,版本=7.0.0.0,Culture=neutral,PublicKeyToken=30ad4fe6b2a6aeed”或其依赖项之一。该系统找不到指定的文件。
我确实添加了:
外部别名 OldJson;
并使用 OldJson::Newtonsoft.Json;
这适用于 NewJson 别名。
我看过这个:.NET: Load two version of the same DLL .我不想在运行时这样做,还是最好的方法?如果我稍后将其推送到 azure 服务,最好的方法是什么?
有人愿意分享有关这种困境的一些看法吗? 😊
更新 :我现在实际上在使用这个版本的 powerbi:Version 2.0.12 .不需要任何 json.net。但在加载 json.net 时仍然出错。这是 fuslog 的截图。
=== Pre-bind state information ===
LOG: DisplayName = Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
(Fully-specified)
LOG: Appbase = file:///C:/Program Files/M-Files/20.8.9339.3/Bin/x64/
LOG: Initial PrivatePath = NULL
Calling assembly : Microsoft.PowerBI.Api, Version=2.0.12.18114, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: C:\Program Files\M-Files\20.8.9339.3\Bin\x64\mfappplatform.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
LOG: Attempting download of new URL file:///C:/Program Files/M-Files/20.8.9339.3/Bin/x64/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/M-Files/20.8.9339.3/Bin/x64/Newtonsoft.Json/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/M-Files/20.8.9339.3/Bin/x64/Newtonsoft.Json.EXE.
LOG: Attempting download of new URL file:///C:/Program Files/M-Files/20.8.9339.3/Bin/x64/Newtonsoft.Json/Newtonsoft.Json.EXE.
LOG: Attempting download of new URL file:///C:/Program Files/M-Files/20.8.9339.3/Server/Data/Apps/{508AA001-0DF6-4396-A440-6985D9C46A7E}/{9DC357E6-D62A-4A53-A8D4-747B23826B2E}-hVIg9CF9YxhkXsvwapj2HCgrFD1Yi6XZhBsR7WU0Be0=/Newtonsoft.Json.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
LOG: Attempting download of new URL file:///C:/Program Files/M-Files/20.8.9339.3/Server/Data/Apps/{508AA001-0DF6-4396-A440-6985D9C46A7E}/{9DC357E6-D62A-4A53-A8D4-747B23826B2E}-hVIg9CF9YxhkXsvwapj2HCgrFD1Yi6XZhBsR7WU0Be0=/Newtonsoft.Json/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/M-Files/20.8.9339.3/Server/Data/Apps/{508AA001-0DF6-4396-A440-6985D9C46A7E}/{9DC357E6-D62A-4A53-A8D4-747B23826B2E}-hVIg9CF9YxhkXsvwapj2HCgrFD1Yi6XZhBsR7WU0Be0=/Newtonsoft.Json.EXE.
LOG: Attempting download of new URL file:///C:/Program Files/M-Files/20.8.9339.3/Server/Data/Apps/{508AA001-0DF6-4396-A440-6985D9C46A7E}/{9DC357E6-D62A-4A53-A8D4-747B23826B2E}-hVIg9CF9YxhkXsvwapj2HCgrFD1Yi6XZhBsR7WU0Be0=/Newtonsoft.Json/Newtonsoft.Json.EXE.
如果我使用 M-Files VAF 10.0.3 以外的任何其他版本,它甚至无法编译。VS警告:
缺少 JSON.NET 7.0 依赖项的 Nuget 信息
CodeReflect Microsoft.PowerBI.Api.2.0.14 引用。
最佳答案
There are more ways of loading multiple versions of the same assembly into a single application domain. All of them require the assemblies to be strong-named to avoid identity conflicts.
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Some.API" publicKeyToken="12ab3cd4e5f6abcd"
culture="neutral" />
<codeBase version="1.0.0.0" href="v1\Some.API.dll" />
<codeBase version="2.0.0.0" href="v2\Some.API.dll" />
<!-- INFO: The version attribute represents an assembly
version which doesn't always have to match the
NuGet package version.
The codebase attribute can be anywhere on
the local intranet or the Internet. -->
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
注:您不应更改 CMSDependencies 文件夹的内容。这样做可能会破坏您的升级路径,因为该文件夹旨在专门包含 Kentico 的依赖项。
有用的网址:
关于c# - Visual Studio : Can't load 2 versions of Json. NET 和使用别名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63596664/