Kis*_*Oli 27 c# visual-studio win-universal-app windows-10 windows-10-universal
我有一个以前在Windows 8.1上使用VS 2013构建的WinJS项目.
最近我通过创建一个空白的Javascript Universal windows 10项目将该项目升级到Universal Windows 10,然后从旧项目添加了我的所有文件.
我有Windows运行时组件以及SQLite的类库.
我添加了通用Windows运行时组件和通用类库,并将我的所有文件从旧项目复制到各自的位置.
不知何故,我设法删除所有构建错误.
我安装了所有必需的SQLite-net,SQLite for Universal Windows Platform,Newtonsoft等.
但是当我运行应用程序并在Windows运行时组件中调用Native方法时,它会产生一些奇怪的错误:
An exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.ni.dll but was not handled in user code.
Additional information: Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
Newtonsoft版本是:9.0.1
我的Windows运行时组件的project.json文件如下:
{
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0",
"Newtonsoft.Json": "9.0.1"
},
"frameworks": {
"uap10.0": {}
},
"runtimes": {
"win10-arm": {},
"win10-arm-aot": {},
"win10-x86": {},
"win10-x86-aot": {},
"win10-x64": {},
"win10-x64-aot": {}
}
}
Run Code Online (Sandbox Code Playgroud)
我的Visual Studio版本是:
我尝试删除所有的Newtonsoft json并重新安装它,但没有运气.
Elv*_*SFT 28
我做了一个基本的演示并重现了这个问题.似乎WinRT组件未能找到正确的程序集Newton.Json.暂时解决方法是手动添加Newtonsoft.json.dll文件.您可以通过以下步骤实现此目的:
右键单击引用 - >添加引用 - >浏览...->查找C:\ Users\.nuget\packages\Newtonsoft.Json\9.0.1\lib\portable-net45 + wp80 + win8 + wpa81\Newtonsoft.json. dll->单击"添加"按钮.
重建Runtime Component项目并运行.这个错误应该消失了.
Jfl*_*fly 21
我通过将Newtonsoft.Json添加到启动项目的NuGet来解决了这个问题.
Ric*_*Lee 15
我有同样的问题也一样,要解决这个问题,您在引用您的项目,如果版本Newtonsoft.Json被更新(probablly鸵鸟政策),然后将其删除,并在您检查任何Web.config文件或App.config中 wheter的element dependentAssembly更新如下:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
Run Code Online (Sandbox Code Playgroud)
之后,再次重建项目(dll将替换为正确的版本)
我正在使用Visual Studio 2013 Update 2.就我而言,我在一个解决方案中有一个Web项目和一个Web Api项目和单元测试项目以及其他类库.
我花了几天时间来解决这个问题.以下是我找到的逐步解决方案.
Newtonsoft.Json从Package Manager控制台使用以下查询从解决方案中删除所有包(以获取它查看>其他窗口>包管理器控制台).uninstall-package newtonsoft.json -force
Newtonsoft.Json从Package Manager控制台重新安装install-package newtonsoft.json
Newtonsoft.Json,我遇到了以下错误.'Newtonsoft.Json 10.0.3'软件包需要NuGet客户端版本'2.12'或更高版本,但当前的NuGet版本是'2.8.50313.46'
工具>扩展和更新...>在左窗格中..选择更新> Visual Studio库.
更新的NuGet包管理器扩展.按照之后的步骤进行操作.
Visual Studio将在此之后重新启动.
再次执行步骤6.
安装完成后,将在下面的行中添加packages.config
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net451" />
Run Code Online (Sandbox Code Playgroud)
安装完成后,web.config将添加以下行
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
Run Code Online (Sandbox Code Playgroud)
如果没有其他错误,它将成功执行.
前一段时间我在使用新的ASP.NET Core应用程序时遇到了类似的问题.事实证明,其中一个引用的库使用的Newtonsoft.Json版本低于9.0.0.0.所以我升级了该库的版本,问题解决了.不确定你是否能够在这里做同样的事情
在配置文件 (web.config) 中添加 Newtonsoft.Json 的绑定重定向配置将解决该问题。
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Run Code Online (Sandbox Code Playgroud)
由于您的案例中的 Newtonsoft.Json 版本是 9,请在配置中适当更新版本。
如果此配置不起作用,请确保配置标记中的命名空间 (xmlns) 正确或完全删除命名空间。
我认为 AutoCAD 劫持了我的。对我有用的解决方案是将其劫持回来。我从https://forums.autodesk.com/t5/navisworks-api/could-not-load-file-or- assembly-newtonsoft-json/td-p/7028055?profile.language=en 得到这个- 是的,互联网以神秘的方式运作。
// in your initilizer ...
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler);
.....
private Assembly MyResolveEventHandler(object sender, ResolveEventArgs args)
{
if (args.Name.Contains("Newtonsoft.Json"))
{
string assemblyFileName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\Newtonsoft.Json.dll";
return Assembly.LoadFrom(assemblyFileName);
}
else
return null;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
101907 次 |
| 最近记录: |