Cannot access DLL inside Shared Project - xamarin

I have a Xamarin.Forms Shared project.
I need to add a reference to System.Net.Http and after some research I found out it should be done via the regular right click -> select assembly (at every regular project), done that.
But now, if I go to any class on my shared project and try to use that DLL I can't (see image)
What am I doing wrong?
I've added the reference to every other project (iOS, Android and WinPhone) but can't access it on my Shared Project classes.
EDIT
After much try-and-error I figured it out...
I have 3 projects (iOS, Android AND WP8.1).
I was able to add System.Net.Http to iOS and Android projects but when I tried to do that at the WP project I got a message saying all needed DLLs were already in the SDK (how presumptuous!).
Anyway, I decided to unload WP project and it worked =/
So the problem now is: How can I add that DLL to the WP project, since I want to support it, but I NEED System.Net.Http?
Thanks.

You can not add a reference to a project type of SharedProject. Instead you have to add this reference to the project you referenced the SharedProject to.
Consider the following:
You have a solution with a console project and a - lets call it core project - as a SharedProject.
Your console project references core. If you now want to use System.Net.WebClient you have to add the reference to System.Net to the console project.

Well, I figured it out.
The way I solved it was by unloading the WP project and reloading it. Perfect, it worked =)
After reloading the project I checked the .NET for Windows Phone reference and System.Net.Http is indeed there. Maybe this was just a cache thing, I don't know.
All I know is unloading the project and reloading it did the trick.

Related

Xamarin Shared Library namespace cannot be found

My shared library cannot resolve using RestSharp; among other related namespaces. RestSharp is an installed package and is resolvable in the Droid/iOS projects but cannot be found in the Shared Library. I know this works because I'm using RestSharp in a MonoGame project in the same way. The shared library is referenced in the Droid/iOS projects but still fails during compilation.
Any advice? I tried clean all.
Update I created a new Cross Platform Native app solution and I was able to reference in my shared library without issue. That original project is a bit older and was created with PCL originally. I still want to know why it's not working in my original solution.
I continued to have lots of namespace and type not found issues. Once I showed warnings instead of just errors I found that the csproj was missing. After removing the reference in the native apps and re-adding the issue was resolved. Quite frusterating.

Mono.Android reference in PCL project in VS 2017 Mac

I have created a project in Visual Studio 2017 Windows. Now I am trying to work on it from Mac. While tried to build the project I can see reference to Mono.Android is not available. Also System.ComponentModel is unavailable. How I can add the reference for both of it?
I also facing the same issue mono.android is missing, finally it work by adding mono.android.dll. I did something like this in my project, in Deploy.cs file add this line
class Deploy
{
[Android.Runtime.Register("getExternalStoragePublicDirectory", "(Ljava/lang/String;)Ljava/io/File;", "")]
it show missing mono.android.dll library is missing need to add into the project. Problem solved later I comment this line.
From the picture above you can see that the reference is made to a particular file on your Windows computer which on the Mac is obviously not on that path. If you want to make the project work you should find those files on the Mac and reference them. Copying them from Windows somewhere and referencing them should work too.
But as people noted, the point of PCL project is not to contain references like this so whole the architecture of your app is wrong and that's why you see the problems. So you may want to resolve the root of the problem as this probably won't be the last thing that you encounter by doing the things in the wrong way.

Xamarin's shared project issue

I want to add a shared project to my ios/android solution. The problem is that after adding a reference to it and using a class from it, I get CS0234 error (The type or namespace name "myname space" does not exist in the namespace...). I use Xamarin studio 5.0.1 for Mac. Any suggestions?
Note: I'm using Starter Edition
I've noticed erratic/buggy behaviour of Xamarin Studio(XS) while while refactoring Shared projects.
for example, when a working(*) Type/class inside an Android project is moved to the Shared Project.
XS refuse to build(*1) the Android project with "Type not found".
Solution Attempts:
- Clean/Rebuild does not help.
- right-click reference and click Refresh,it does Not help.
- Unload-Reload Shared Project (sometimes helps) (*2) .
- Close Solution/Open Solution (sometimes Helps *2b). (more often)
- Close XS Open XS (99% of the time helps)
- Rename (*3) NameSpace in Shared Project Type/class helps 99% of the time (*4) (*5)
*: It builds
*1: Build failed
*2: Sometimes makes more damage than Help,
3: Not Refactoring
4: difficult to know if you didn't break it your self with the renaming when it didn't help , :)
5*: you need to go back to calling/referencing code and fiddle around a bit , intellisense will help you to find the right reference again (6)
6: Highly recommended to enable source analysis of open files (Resharper Mode :)
The Shared project feature is quite new so I'll expect it to get more 'stable' very soon.
To be fair and almost out of context, I also notice glitches in Visual Studio with Shared projects
When working Microsoft projects like in Win8.1/Phone scenario.

Could not load file or assembly Microsoft.Expression.Interactions and GalaSoft.MvvmLight.Extras.WPF4

I am facing unknown problem while using Prism 4. We implement business solution in MVVM pattern. For that I have used
1. Microsoft.Expression.Interactions
2. System.Windows.Interactivity
3. GalaSoft.MvvmLight.Extras.WPF4
for Interaction.Triggers, CallMethodAction and EventToCommand.
<SWI:Interaction.Triggers>
<SWI:EventTrigger SourceObject="{Binding ElementName=txtName}" EventName="GotFocus">
<MEI:CallMethodAction TargetObject="{Binding Path=DataContext,ElementName=txtName}" MethodName="txtName_GotFocus"></MEI:CallMethodAction>
</SWI:EventTrigger>
<SWI:EventTrigger SourceObject="{Binding ElementName=txtName}" EventName="KeyUp">
<GMEWCMD:EventToCommand Command="{Binding Path=DataContext.cmdtxtNameKeyUpEvent,ElementName=txtName}" PassEventArgsToCommand="True">
</GMEWCMD:EventToCommand>
</SWI:EventTrigger>
</SWI:Interaction.Triggers>
Everything is working fine but now we required to make whole system loosely couple we choose prism 4. We already achieved this but above code create following problem as below.
Could not load file or assembly 'Microsoft.Expression.Interactions, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
If I comment above code everything is working fine. I don't know what an issue. Does PRISM 4 not support above assemblies?
Please help us to get rid from this problem.
Thank you
This commonly happens to me when I reference both Microsoft.Expression.Interactions and System.Windows.Interactivity in a view that belongs to a module, but I fail to also add those references to the project that acts as the shell.
I had a similar problem with Prism in Visual Studio 2012. The XAML editor would fail with the same exception.
The solution was to install Microsoft Expression Blend SDK. The assembly should be part of SDK. Allegedly, it is necessary for binding between control events and commands in XAML and some code may require it.
I had the same problem during a Prism 6.1 composite app using .NET 4.5.2, where i was referencing in one of the modules (class library) the Microsoft.Expression.Interactions & System.Windows.Interactivity.
Eventually i had to reference the same dlls in the Desktop project (where bootstrapper and Shell belong)

How to change VS2010 Add Reference box filter?

I'm getting used to the new IDE (it's vc# express), but the first contact is somewhat confusing. When I open the Add Reference dialog and switch to the .NET tab, a label above the assembly list states: "Filtered to:.NET Framework 4". And it's true - I can reference .NET 4.0 assemblies only plus things like XNA 3.1. However I can't see older assemblies i.e. Managed DirectX libs, which are obviously installed on my computer as there was no trouble with adding a ref to them in vc#08.
What is this? How to change the filter? The label is read-only. These sound like dull guy's questions, but I'm out of luck in finding an answer and there is no intuitive solution.
Thanks in advance.
Change your new application to target the .NET Framework 4 and not .NET Framework 4 Client
"When you create a new application, some projects target the .NET Framework 4 Client Profile by default."
http://msdn.microsoft.com/en-us/library/cc656912.aspx
"If you are targeting the .NET Framework 4 Client Profile, you cannot reference an assembly that is not in the .NET Framework 4 Client Profile. Instead you must target the .NET Framework 4. "
We've created a tool that will help you to achieve your goal. Muse VSReferences will allow you to add a Global Assembly Cache reference to the project from Add GAC Reference menu item.
Regards
s
How to change the filter?
Very simple - you must change the Target .NET Framework for your project, as whole. It's not pain :) just RMB on project name in Solution Explorer->Properties->Application tab->Target Framework(combobox). Select what you want. Change combobox == change filter in Add Reference dialog. ;)
I was having a similar problem until I noticed that the older .NET assemblies were actually in the list, there's just some really strange sorting going on. If you sort by assembly name, you should see them in the proper order.
Another possibility is to go into your project’s Properties page and change the Target Framework from 4.0 to your desired Framework. You will then need to reload you application. Now your Reference should be there. Once you have added the Reference you want, change back to 4.0 and again reload.
Hope this helps.
If, for instance, your project is Framework 4 and you want to reference say Microsoft.Deployment.WindowsInstaller (which is not in the filtered list of the .NET tab), then go to the Browse tab and enter the path to the reference item e.g. C:\Program Files\Windows Installer XML v3.5\SDK\Microsoft.Deployment.WindowsInstaller.dll

Resources