Have written all the code in a silverlight class library (dll) and linked this same library to my web app and silverlight app, is there a way to avoid the "Compiler Error Message: CS0433" or do I have to create a separate dll for the web app?
Error mostly occurs when XElement is called...
You need to create two projects, but can add the same CS file using Add Existing Item as a Link. http://msdn.microsoft.com/en-us/library/9f4t9t92.aspx explains it.
http://www.scip.be/index.php?Page=ArticlesNET28 is a nice read with related info.
Do you mean you are referencing a single dll from both the web app and the Silverlight app? I would have two versions of the dll (and two project files); one built for regular .NET (for use in the web app), and one for Silverlight; the main difference being the target framework and the references.
If you don't want to deal with having to maintain two project files (when you add classes etc), then you can use this trick to reduce this overhead.
Related
As the title says, I have a WPF form that I want to build in 3 separate projects:
A Windows application, used standalone by clicking the .exe file
A GUI control that can be imported and used in some other projects (dll)
A Custom Visualizer, that can also be used to view a collection of some specific types (dll)
The interface and all the functionality will be the same(identical) between the 3 projects
My questions are the following:
Can this be achieved by making only one project? Or do I have to make 3 separate projects?
If there is not other way but to make 3 separate projects, how can I have the logic for the controls in a separate project common for all of them?
All the logic is now in the controls events (MouseWheel, button click etc)
I need to use net framework 4.7.2 (or 4.8). Can I make all the projects with this? Or can I also use .net 6.0 on some of them?
Thank you
In such case, you can use a Shared Project. Add a Shared Project (case-sensitive) to your solution and reference that project from other pojects. Then you can access the code inside the Shared Project from other projects as if the code belongs to each of other projects.
Shared Project is often explained in the context of sharing the codes among different platforms but it could be useful for other purpose as well.
I'm new to programming so I might not be using some of the correct terminology. I'm running into an issue with InteliSense when calling a C# class from another project within the same solution. It's not suggesting a using statement and is instead trying to get me to create a new class inside of the current project which is not what I want. I am having to go in and add a refernce to the project and then add the using statement in order to get access to the class.
I looked at some of the documentation online and nothing has helped so far. InteliSense appears to configured correctly to suggest using statements. It provide suggestions just fine. I've been able to create lists and then use it to add the proper using statement along with some other things. Just doesn't want to work with anything inside the solution. I've been following a couple of different tutorials including, .net core 2.1 and 3.1, inside MVC and Razor page projects along with a couple just straight C# console apps. It doesn't work in any of them when I start adding multiple projects to the solution and try using classes from outside the current project.
I am having to go in and add a refernce to the project and then add the using statement in order to get access to the class.
That is the correct behavior. In order for ProjectB to use classes defined in ProjectA, you must first add a reference to ProjectA. Just having the projects in the same solution is not sufficient.
The purpose of having multiple projects in the same solution is simply for grouping related code. The projects may or may not actually depend on each other. For example, a web application may have a separate projects for the actual web UI (the pages themselves), a data access layer, unit tests, maybe some class libraries for shared code used by multiple projects, and maybe even console applications (or some other project type) for performing backend administrative tasks. In this scenario, the web UI and console applications may have references to the data access layer project and/or the class libraries. The unit test project will have a reference to the web UI project, and so on. The dependencies are one-way - you may not have circular references (the unit test project has the web UI project as a dependency, but not the other way).
I currently have a library which was created in a silverlight application for its use. But Now we are switching over to WPF. So i don't know how would i convert the library to a wpf library. Would i just have to copy all the file in a new project(wpf class library)
As you can see when i reference this silver light library in my wpf project. It gives me a warning.
As the message says, you can't use a project compiled to target Silverlight as a reference for a project targeting some other .NET framework family. You will need to compile a separate assembly compatible with the .NET framework family you're using (i.e. a desktop version). This will require the creation of a whole new project (I'm not aware of a practical way to have a single project target both Silverlight and desktop .NET).
Note that the new project can use the same source files as the original Silverlight one. After creating the project (which you should create as an "Empty Project"), you can add the source files from the Silverlight project, by using the "Add Existing..."/"As Link" option for adding items to the project. Adding the source code as links will cause the new project to reference the original .cs files in their current location rather than creating a new copy of them for the new project.
Note also that your Silverlight code may or may not be 100% compatible with the WPF API. You may have to introduce conditional compilation (i.e. use #if, and declare appropriate conditional compilation symbols, in the projects' settings "Build" tab) so that you can provide correct code for each platform in each .cs file.
Related topics (there a lot of duplicate questions involving adding existing items as links…though many of these involve multiple solutions, not just adding items to a new project):
Share c# class source code between several projects
How do I keep common code shared between projects in c#?
Adding Existing Files To Different Visual Studio 2010 Project
Is it possible to statically share code between projects in C#?
Updating classes used in multiple projects?
Make reference to C# code from multiple projects
Share .cs file among VS 2010 C# projects
How to include source files of one project in another project?
I've a C# solution that consists of an MVC project and a Windows Application project. Is there any way for MVC to call a Windows Application method and pass values to it?
I added Windows Application to References in the MVC project. But when adding the namespace reference using Windows Application name in the MVC class, it can't be found.
I appreciate any pointers.
Check that classes are public (else you can't call methods from the class) and that you have added reference to the project in your solution.
Take the code that's shared between the two, add a class library, and place it in there. That's what they are for. Past this, referencing a Windows application (.exe) is sure to be an issue even further down the road.
Hi I would like to use the same class library from my Silverlight application and WCF based service. I created a Silverlight C# class library and found the WCF service does not allow adding reference to Silverlight Project types. So
What should i do to make this work?
Can Silverlight invoke methods on Silverlight Class library if it communicates with WCF service?
Is silverlight always this hard?
Portable Class Library
http://msdn.microsoft.com/en-us/library/gg597391.aspx
Try making 2 class libraries, one for Silverlight and one for WCF. Both use the same C# source code files. In the second project, you can add the files as link (In Visual Studio in solution explorer: add existing item, and then in the drop-down Add button, choose "Add as link".
That's how we solved it for shared code. You have to limit yourself to library calls that exist in both worlds though.
Now it is easy :D - just use the .shared trick. It allows you to share the same code between server and client. Look here: http://msdn.microsoft.com/en-us/library/ee707371(v=vs.91).aspx
PS.: You can even add conditional directives on your .shared classes, like this:
#if SILVERLIGHT
MessageBox.Show("yay, I will run only on silverlight");
#endif