C# Xamarin Java.Interop 错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37788326/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 02:48:32  来源:igfitidea点击:

C# Xamarin Java.Interop error?

javac#xamarin

提问by highwaydog

Hello since the last Xamarin updatewe get this error.

你好,自从上次Xamarin update我们得到这个error

CS0012 The type 'IJavaPeerable' is defined in an assembly that is not referenced. You must add a reference to assembly 'Java.Interop, Version=0.1.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065'. ImageLibrary C:\Users\rutge\Source\Repos\GarderobeApp\ImageSwiper\ImageSwiper.cs 33 Active

CS0012 类型“IJavaPeerable”是在未引用的程序集中定义的。您必须添加对程序集“Java.Interop, Version=0.1.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065”的引用。ImageLibrary C:\Users\rutge\Source\Repos\GarderobeApp\ImageSwiper\ImageSwiper.cs 33 活动

Does anybody have an idea what this means?

有人知道这是什么意思吗?

回答by neneo

You can found it here

你可以在这里找到

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\Java.Interop.dll

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\Java.Interop.dll

then :

然后 :

  1. Go to your Android project
  2. Right Click in reference and choose "Add Reference"
  3. Browse file location
  4. Add and done
  1. 转到您的 Android 项目
  2. 右键单击引用并选择“添加引用”
  3. 浏览文件位置
  4. 添加并完成

if you still get error, try to rebuild your project

如果您仍然遇到错误,请尝试重建您的项目

回答by OrcusZ

I go the same error after the last update. You just have to add the reference to Java.Interop to resolve the problem.

我在上次更新后出现同样的错误。您只需添加对 Java.Interop 的引用即可解决问题。

  1. Go to your Android project
  2. Right Click in reference and choose "Add Reference"
  3. On Assembly, look for Java.Interop and add it
  4. Rebuild your project
  1. 转到您的 Android 项目
  2. 右键单击引用并选择“添加引用”
  3. 在 Assembly 上,查找 Java.Interop 并添加它
  4. 重建你的项目

If you need some screenshots, I can provide them later.

如果您需要一些屏幕截图,我可以稍后提供。

回答by Rohan Sampat

In my case it was a bit different, I couldn't find monoandroid folder in

就我而言,它有点不同,我找不到 monoandroid 文件夹

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework. 

So on further I searched and found it in

因此,我进一步搜索并在

C:\Program Files (x86)\Microsoft Visual Studio17\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid

This might be the case with someone else.

这可能是其他人的情况。

回答by wonea

You can hover over the offending line and see the missing DLL.

您可以将鼠标悬停在违规行上并查看丢失的 DLL。

Line complaining about missing reference

线路抱怨缺少参考

Now add the missing reference;

现在添加缺少的参考;

  1. Open the Solution Explorer, and within References right click, and select Add ReferenceAdd Reference from Solution Explorer

  2. Within the Reference Manager click Browse, and Browse again. Add reference

  3. In the file dialog copy and paste this path:

    C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\

  1. 打开解决方案资源管理器,在引用中右键单击,然后选择添加引用从解决方案资源管理器添加引用

  2. 在参考管理器中单击浏览,然后再次浏览。 添加参考

  3. 在文件对话框中复制并粘贴此路径:

    C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\

Go to DLL path

转到DLL路径

Click Java.Interop.dll

单击 Java.Interop.dll

Add file

添加文件

  1. Okay the Reference Manager
  1. 好的,参考经理

回答by Arun Prasad

You can directly copy the assembly Java.Interop.dllfrom the C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0to the bin/Debugfolder of your project to resolve the issue.

您可以直接将程序集Java.Interop.dll从复制C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0bin/Debug项目的文件夹中以解决该问题。

This procedure perfectly worked for me.

这个程序对我来说非常有效。

Thanks,

谢谢,

回答by Dave Rincon

In my case iOS and Android use the seem Business Layer when I run my android application works ok but when I run iOS show me the error You must add a reference to assembly 'Java.Interop, Version=0.1.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065'

在我的情况下,当我运行我的 android 应用程序时,iOS 和 Android 使用似乎业务层,但是当我运行 iOS 时,向我显示错误您必须添加对程序集“Java.Interop,版本 = 0.1.0.0,文化 = 中性”的引用, PublicKeyToken=84e04ff9cfb79065'

The problem: I was using JSONObject from Org.Json

问题:我使用的是 Org.Json 的 JSONObject

https://docs.microsoft.com/en-us/dotnet/api/org.json.jsonobject?view=xamarin-android-sdk-9

https://docs.microsoft.com/en-us/dotnet/api/org.json.jsonobject?view=xamarin-android-sdk-9

this dll just work with android

这个 dll 只适用于 android

I need change for JsonObject from System.Json

我需要从 System.Json 更改 JsonObject

https://docs.microsoft.com/en-us/dotnet/api/system.json.jsonobject?view=dotnet-plat-ext-2.1

https://docs.microsoft.com/en-us/dotnet/api/system.json.jsonobject?view=dotnet-plat-ext-2.1

That was my solution, now my two applications work

那是我的解决方案,现在我的两个应用程序工作

回答by Jammer

These errors are not due to a problem with the solution or the references. They are a by-product of other changes that seem to confuse tools like ReSharper. At least this is correct in my case, my solution still compiles and functions without manually referencing any Reference Assemblies.

这些错误不是由解决方案或参考资料的问题引起的。它们是其他更改的副产品,这些更改似乎混淆了诸如ReSharper. 至少在我的情况下这是正确的,我的解决方案仍然可以编译和运行,而无需手动引用任何参考程序集。

There is a Xamarin bug report for this but they determined this to be an external issue with ReSharperas per my experience.

有一个 Xamarin 错误报告,但ReSharper根据我的经验,他们确定这是一个外部问题。

Rather than manually adding references to the project you can also tell ReSharper to simply ignore the errors by opening:

除了手动添加对项目的引用之外,您还可以通过打开告诉 ReSharper 简单地忽略错误:

ReSharper -> Windows -> Solution Errors

And then ignoring the issues here.

然后忽略这里的问题。