I am using Visual Studio 2017. I have a solution and in that solution I have 2 projects. One project is a library I made. This library is using Target Framework .Net Standard 1.6 and Output type: Class Library. The other project is a Windows Application using Target Framework: .Net Framework 4.6.1 and output type: Windows Application.
I added my class library to my windows application and the reference is in the Reference section, but when I try to use a class from the library, it cannot find it. Also I tried adding the "Using MyLibrary" and it still cannot find the reference. What else can I do?
I'm not sure why but the whole solution must had been corrupted or something. So I remade a whole new solution and created the projects again and copied all my files over and it worked. Not sure what the whole problem was but it is now working.
Related
I have a .NET framework WPF project that references a .net standard library that I wrote. This library references io.ports.dll
I found that there is a problem with .net framework referencing .net standard projects and that it would not copy the io.ports.dll to the output folder. The solution here was to add the dependency to my WPF project also which solved the problem.
However I noticed that the two projects reference the io.ports.dll from different locations.
The WPF project references from
project location\packages\System.IO.Ports.4.5.0\lib\net461\System.IO.Ports.dll
The .net standard library io.ports.dll location is
C:\users\.nuget\packages\system.io.ports\4.5.0
The DLLs have different sizes, although they are the same version.
The problem appears when I use advanced installer to create a .msi.
It gets very confused and tries to copy both DLLs and in the end my .net standard library tries to read the wrong DLL.
Anyone have any idea how to solve this?
Pavel answered (now deleted) that it was due to my GUI project using the old packages.json. This solved the original problem. Another problem was that the io.ports dll has a dependency on Microsoft.Win32.Registry.dll which I also had to add to the GUI project.
I've added a new Class Library (Package) project to my solution. It's my first experience with a .NET Core (or whatever I'm using, still confused)
My class library contains two references: .NET Framework 4.5.1 and .NET Platform 5.4
I'm trying to import some code from a sample project that uses IPrincipal. For some reason it's saying that it doesn't exist on namespace "System.Security" altohugh I can get it trough intellisense.
What's wrong with my project settings?
The new feature of .NET Core and Class Library (Package) is that it targets multiple platform and will compile into multiple assemblies which get automatically packaged into a nuget package.
When your class library targets multiple targets, it will compile to all of them. So if a certain library is only available on full .NET framework but not on .NET Core or other target framework, then you may receive intellisense if your editor is set to .NET 4.5. More information can be found in my other recent answer.
You can switch back and forth with the pull down menu on top left of the coding window, show in the screenshot below.
If you do not want to target a certain framework, you have to remove it's moniker from the project.json file or use preprocessor directives to write platform specific code or libraries/replacements.
.NET Core is heavily modularized and most of only the core modules are referenced in the default project and if you need additional one you need to reference them within the dotnet5.x section.
Basically you have multiple places with "dependencies" in your project.json, a global one where you can add dependencies which are available on all targeted frameworks and one within each "frameworks" section for each of the targets only.
Though the other answer covers some basic concepts, it would require some attention on which classes are available and which are not.
Microsoft temporarily host a web site at http://packagesearch.azurewebsites.net to assist.
If you can find a suitable package for RC1 from there, then you can add it to your project.json file. If not, you will have to conditional compile it to a desktop profile or use other alternatives.
So i try to develop little andriod application by Xamarin Studio 5.4. I have three projects in my solution - project of android application (ClientProject), some class library that used by first one (MyLib) and some console application (ConsoleApp).
But when i try to add reference to MyLib into ClientProject i fail. Xamarin Studio tells me that "Incompatible target framework .NET Framework Version 4.0".
That looks this
I changed MyLib's framework version to 3.5, to 4.5 but it takes no effect.
But when i try to add this reference into ConsoleApp there is no problem:
So i have to add to ClientProject a reference to MyLib.dll so I can not debug its code.
What should i do to solve this problem?
The Android project will have a framework of MonoAndroid. This framework is incompatible with the full .NET Framework. Your options are to do one of the following:
Create an Android Library Project.
Create a Portable Class Library Project.
Create a Shared Project.
If you are only interested in creating an Android application, and not interested in using the library for other mobile platforms, then the first option will be the simplest.
I have a asp.net MVC 4 Application I'm working using visual Studio 2010.
I have added 3 Class libraries to the solution and for some reason only one of them is being picked up by visual studio.
So in any class where I reference the other in Using statement. I get the following error "The type or namespace name "*" does not exist in the namespace "MyProject"(are you missing an assembly reference?)"
I have right clicked on the main project, selected properties and checked that all the class libraries are listed under projects, which they are.
I have right clicked on the solution, selected properties and ProjectDependcies, and this is also set up correctly.
The class libraries are all listed in the References folder for the main Project.
I've tried cleaning and rebuilding , no joy any suggestions ??? Thanks
The DLLs are likely built using an later version of the framework than your project is targeting.
The version of .NET that your class libraries are targetting is greater than the version your application is targeting.
Either demote your libraries to use the version of .net targeted by your application, or promote your application to the version used by your libraries.
In Visual Studio 2012 in a blank new Class Library I am trying to add reference to an existing project in the solution, also a Class Library, MonoGame.Framework.Windows8 (https://github.com/mono/MonoGame), but get the error:
Unable to add reference to Project MonoGame.Framework.Windows8
I have built the existing library, MonoGame, successfully and made it a dependency of the new one. What could be the problem?
(It's extremely annoying the error message does not give a reason!)
Trying to add the built dll has a reference gave a more explicit error message which has solved the problem for me, it said:
“A reference to ‘x’ could not be added. The project targets ‘.NetFramework’ while the file reference targets ‘.NetCore’. This is not a supported scenario”
The MonoGame Class Library is a Class Library (Windows Store apps) type! (The bit in parenthesis is important! Presumably the difference is the Windows Store apps type use .Net Core which is not the same as .Net Framework).
So to get it working your project must be a Class Library (Windows Store apps) which is available under the Windows Store option in Add New Project.
I suspect the problem is to do with the 'Target Framework' in project options.
I don't know how MonoGame works for Windows 8 but when you're developing for Android the target framework options are the different versions of Android [e.g. Android 2.2 (Froyo)]. When you create a regular class library you have choices between the different versions of the .NET framework or Mono [e.g. Mono / .NET 4.0].
Unfortunately, these frameworks are not compatible with each other. You can't add a project reference for Android to a .NET framework class library and visa-versa.
The solution is to use a Portable Class Library. They are specifically designed to deal with this issue. The downside is that you will only have access to the subset of assemblies provided in the lowest denominator you choose to target.
You might also want to consider code sharing between projects using linked files. It can make maintenance a little trickier but gives you a little more control over code that should compile in both target frameworks but doesn't fit into the portable class library. Here's a related question:
Project reference vs. file links in Mono multi-target projects
The key to all of this once you understand what's going on here is how you structure your solution. With a little care you can have nearly all your code shared across different platforms.
I might be because of both projects are using different Framework versions and change the Framework versions in both Projects of properties section then your problem might solve.
Same question I guess here:
Visual Studio 11 metro apps unable to add reference?
The answer was:
What are you adding a reference to? Metro style apps can only add references to other Metro style class libraries or portable class libraries