Is it possible to reference the System.Data.Linq in a Portable Class Library project?
Note:
I am just trying to share code between a WP8 and WinStore8 app [DataContext]
No it is not. The Data namespace is unavailable in PCLs.
You can tell because http://msdn.microsoft.com/en-us/library/system.data.aspx none of its members have the PCL icon, and it is not listed on http://msdn.microsoft.com/en-us/library/vstudio/gg597391%28v=vs.100%29.aspx
Related
I'm not new to C# programming, but I suppose I'm new to programing "the right way" in C#. I've worked in C on embedded devices for years and have written desktop apps to support them. First in VB6, then in C#.
I recently started making better use of classes for reusing code (and for instantiating more than one instance of the class in a program). For example, I "wrapped" a UART interface with some additional functionality so I can use the same code for multiple ports by creating an instance of the class for each one.
It is in a separate file, but still in the same program namespace, so when I want to reuse it, I have to copy the file and change the namespace to the new project.
I'm sure there's a way to create it such that I can just reference it like everything else with either a "using..." reference at the top of the program or with a "Project | References..." checkbox. But for the life of me I can't find a good learning journey for this.
Any direction would help.
You want to create your reuseable class in an assembly - this is the equivalent of a dll from your C experience.
To create an assembly, have a separate project of type assembly (instead of exe) . You can reference the assembly from other projects. If your project is in the same solution you can reference the project, otherwise you can reference the compiled assembly.
C# uses a packaging system called Nuget, so you can package your assemblies into "Nugets" which you host in a Nuget Server. You can then use tooling to discover and import these.
Please create a Class Library project and include your class into that project. Make sure your class is public. Once you build this project you'll get an assembly which can be referenced from other projects. See Tutorial: Create a .NET class library using Visual Studio
There are different ways of referencing it.
You can have the class library project in the same solution as the main project. In this case you should add a project reference.
You can copy the compiled *.dll file to some folder in your solution (e.g. Lib) and add an assembly reference.
If this assembly is to be used in multiple projects please consider creating a NuGet package with this library and pushing it to some repository. Then other projects can add a package reference to this package.
Details:
How to: Add or remove references by using the Reference Manager
Install and manage packages in Visual Studio using the NuGet Package Manager
It is in a separate file, but still in the same program namespace, so when I want to reuse it, I have to copy the file and change the namespace to the new project.
Well, it isn't the best practice but (unfortunatly) still a common behavior. So don't worry to much about it.
What you could do to improve it place the file (and other reusable parts) in a seperated csproj.
For example name the project of the type class library and name it VinDag.Tools. Within the project create a folder UART and place the wrapper there. The namespace of the wrapper would then be VinDag.Tools.UART.
From know on you can just reference the class library instead of renaming the file. It's not necessarily required to be the same namespace as the project.
From there you can start considering (private) nugets. This would prevent you from copying files/csproj around.
I am attempting to use the System.Numerics.BigInteger struct from within a Xamarin.Android project, but the System.Numerics namespace is not accessible, despite having installed the latest version of the Nuget package that claims to contain BigInteger:
Update: If I create a .NET Standard 1.6 class library, I can reference BigInteger from within it. I find it hard to understand why BigInteger is not accessible from with the Android project, which also references .NET Standard 1.6. I can also reference the class library from the Xamarin.Android project and build the solution, but if the Android project tries to access any method in the class library that returns a BigInteger, the compile complains:
The type 'BigInteger' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Numerics, Version=2.0.5.0 ... '.
Any suggestions please?
Why I do not have access to Attribute.IsDefined() in a portable class library? How could I use this method in PCL? In a class library the following code works perfect but in a pcl it says there is no method there.
if (Attribute.IsDefined(item, typeof(Title))) ...
Title is an attribute. Is it possible to solve this problem by adding a reference or something to the project?
I am new on C# and I have a solution which consists of two projects: a class library project and a REST service project (asp-net web-api). Though both of them work when run independently (in the case of the Class Library by using an entry-point), when I add the class library project to the REST project as a reference and run it, it throws an exception. The exception states that it cannot find/load a library (SQLite.Interop.dll) which is actually referenced by my class library. Any ideas or hints is welcome !
SQLite.Interop.dll is referred in Class lib project not in REST project.
Mark this SQLite.Interop.dll as copy local true in property.
I have a class library project which uses a namespace (e.g., "Cosmos.Creator.Util"). I then create a solution and windows forms application to test the library. From the windows form application, I add a reference to the library. So now I have two projects open in visual studio, a class library and a windows forms project. The forms project references the library.
When I edit my form's code, code autocompletion works correctly for the namespace that I use in the library. E.g., if I type "using Cosmos." I get autocomplete options like "Creator". But now if I build my solution, all of the "Cosmos" are red-underlined with the compile error: "The type or namespace name "Cosmos" could not be found (are you missing a using directive or an assembly reference?)".
For the purposes of the form application test, I placed my library code into a folder CosmosFormExample\Cosmos. When I check the reference from the form application, the reference is to CosmosFormExample\Cosmos\bin\Debug\Cosmos.dll, so that looks okay. I looked at the GUID referenced in the solution file and it matches the GUID of the project file Cosmos.csproj.
What has happened? How has the build caused my forms application to forget about the Cosmos namespace, despite the fact that it is still referencing the library project? Thanks much in advance.
Are you using VS2010 & .NET 4? If so you're probably using .NET 4 Client Profile instead of full fledged .NET 4. Go to project properties and check your Target Framework.
for more info: http://msdn.microsoft.com/en-us/library/cc656912.aspx
you need to check the framework you are using and the framework yout library was compiled for...