Recompile Silverlight to WPF issues - c#

I have a Silverlight control i need to convert to WPF
(Yes, i know that's not wise, don't have a choice)
And i am aware that some assemblies need to be changed.
this is a follow up of this question
Now i am kinda sure that i'm missing a big thing here.
DIdn't really know how to do that so i just started copying all the cs files code to new
class project.
Now i get all kind of weirds errors.
Most for assemblies missing ( ofcourse),
Now what i fail to understand is i'm missing very basic stuff and i am calling the right ones i belive. stuff i used in other WPF applications.
for isntance i get Errors for theese classes :
Point, Size, UIElement, DependencyProperty, MouseEventHandler etc.
Now the project is just 14 classes, no main file or anything, could this be related?
Anyway, i'm using this code to call assemblies (preety much the same anywhere):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Text;
using System.Threading;
using System.ComponentModel;
using System.Globalization;
using System.Diagnostics.CodeAnalysis;
And the VS isn't givining me on help any assembly i could call, just the option to generate my own class.
I am targeting Framework 4.0 using VS 2010
Help!

Did you put this control in a new WPF project? If you didnt make sure you add these References
PresentationFramework
PresentationCore
WindowsBase
System.Xaml
Then remove all your using Statements and readd them all.
You also may need
System.Drawing depending on what Point you are using

UIElement is in System.Windows and you'll need to make sure that PresentationCore.dll is referenced by your project.
DependencyProperty is in the same namespace but required WindowsBase.dll to be referenced.
MouseEventHandler in System.Windows.Input which is also in PresentationCore.
It might be simpler to create an empty WPF project which should have the basic references set up and then adding the source to that.

Related

Why is the reference for ConfigurationErrorsException missing from my .Net 3.0 application?

I have a .NET 3.0 Winform Application with a corrupt user.config file causing system config errors.
I wanted to improve handle these errors, similar to how it's done in this example on CodeProject.
To use '
However, when I try and use the 'ConfigurationErrorsException' to get the name of corrupted file I receive the following error:
The type or namespace name 'ConfigurationErrorsException' could not be found (are you missing a using directive or an assembly reference?)
I have only seen this error previously where there were .NET framework conflicts.
The project has the target framework .NET 3.0. The ConfigurationErrorsException was added in 2.0, so I didn't think there would be a framework conflict there.
The version 3.0 documentation is lacking compared to other versions and does say:
The current value is not one of the EnableSessionState values.
Which I'm not entirely sure what that implies (the documentation for EnableSessionState lead to more confusion rather than less).
Why does the program fail to build, with a type or namespace missing error?
Is this related to targeting .NET 3.0?
If so, Is there an alternative for .NET 3.0?
EDIT:
I have made sure to include 'using System.Configuration' at the top of my page. The total list of usings is:
using System;
using System.Collections.Generic;
//using System.Linq;
//using System.Threading.Tasks;
using System.Configuration;
using System.Windows.Forms;
using System.Threading;
using ProjectName.Properties;
using System.Security.Permissions;
using Microsoft.Win32;

C# using System.Xaml missing assembly reference

I'm writing a C# Console Application that is targeted towards .Net 4.5. I want to use Xaml Services to save and read a List data structure to file. I'm using VS 2013 Pro.
The .net doc's say Xaml has been in .NET since 4.0(?) I have my projected targeted to 4.5, but even with 4.0, 4.5.1, 4.6, and 4.6.1... same missing assembly reference. I'm doing a
using System;
using System.Collections.Generic;
using System.IO;
using System.Xaml; // <-- this is getting the assembly error
using System.Xml;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
But that is where the missing reference is getting the error...
I've used it before in Win Forms. It is that maybe it's excluded for console applications? Or am I missing something that Xaml Class depends on before using that assembly?
Could it be that you did not add a project reference to the assembly "System.Xaml.dll"? The Xaml functionality is not contained in the assemblies which are included in a new VS console project by default. (Right-Click on the "References" entry of the project, then select "Add References", then browse to "Framework" and look for System.Xaml, which refers to the dll of that name).
A namespace however does not necessarily correspond uniquely to an assembly, so you might require even more assemblies. If you know which types you need, you can browse the MSDN documentation for looking which assembly might still be required.

c# GridViewColumns missing assembly reference

I am trying to use 'System.Windows.Controls.GridViewColumn' within Visual Studio 2013, .net 4.5, but I am receiving this error :
The type 'GridViewColumn' was not found. Verify that you are not
missing an assembly reference and that all referenced assemblies have
been built.
Looking within my Reference Manager, I have this message under the Assemblies tab :
All of the Framework assemblies are already referenced. Please use the
Object Browser to explore the references in the Framework.
When I browse through I cannot find 'PresentationFramework.dll'.
Here is the MSDN for the class : http://msdn.microsoft.com/en-us/library/system.windows.controls.gridviewcolumn(v=vs.110).aspx
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
I have tried to add using System.Windows.Controls.GridViewColumn but am receiving this error:
The type or namespace name Controls does not exist in the namespace
System.Windows (are you missing an assembly reference?)
EDIT:
For WhyCry, when I search as you suggested I still don't get any results.
Perhaps I need to use a different GridView? Maybe Windows.UI.Xaml.Controls?
As you're creating Windows store apps, which is based on WinRT, while this GridViewColumn control is one of the WPF controls.
WPF and WinRT are mutually exclusive, you can not use WPF control in Windows Store apps. Please read this: Windows 8 Store Applications Vs. WPF Applications
Okay. So in your Solution Explorer, Right click References, and Add Reference. Then make sure Framework is highlighted in the top left corner of the Dialog. Search for PresentationFramework in the top right search bar. Add PresentationFramework.
After this is done, do:
using System.Windows.Controls;
You can then access all of the GridViewColumn variables, objects, to your hearts desire.
System.Windows.Controls.Gridview
References:
GridViewColumn MSDN
Namespace: System.Windows.Controls
Assembly: PresentationFramework (in PresentationFramework.dll)
MIGHT NEED TO SCROLL IN ON IMAGE

Regarding adding namespace in common area

we always add namespace at the top of the every form in win apps
like
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Business;
using System.Data.SqlClient;
using Business;
and most of namespace are common in most form but in asp.net there is a provision to add namespace only once in web.config file. so we dont have to add it in all web form and it save time. so i just need to know is there any same sort of provision for our win apps. how to achieve it. thanks
No, there isn't any sort of provision for your WinForm applications as there is for ASP.NET applications using the <namespaces> section in web.config. Also note that this applies only to .aspx pages and not code behind C#. In C# you have to add proper using statements in order to bring the types you want to use into scope.
One method is to add the standard using directives into the common templates.
You don't mention which version of visual studio you are using but in VS2010 you can find the templates in:
C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class.zip
Change the Class.cs file in the zip to include the usings you want by default.
The only downside to this is that it is per machine - so you will need to do it on each developers computer - although I daresay you could roll it out with Active Directory (that's a question for serverfault.com).
I believe it also possible to set up team templates - but it's not something I have tried. More information available here:
http://msdn.microsoft.com/en-us/magazine/cc188697.aspx

namespace or class could not be found (ASP.NET WebSite "project")

I am currently trying to cleanup a bit of a corporate website that I inherited here. I managed to clean up most of the errors in the website but something is still up here.
I have one masterpage that have this code :
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.ComponentModel;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class MasterPage : System.Web.UI.MasterPage {
public lists m_listsClass = new lists();
(no it's not a typo the S in lists).
Now in App_code I have one class lists.cs
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
/// <summary>
/// Summary description for lists
/// </summary>
public class lists
{
public lists()
{
When I try to build the website in visual studio 2008 I have this error :
Error 3 The type or namespace name 'lists' could not be found (are you missing a using directive or an assembly reference?) C:\Users\egirard\Documents\Visual Studio 2008\Projects\iFuzioncorp\iFuzioncorp\Masters\MasterPage.master.cs 23 12 iFuzioncorp
Am I missing something ?
Also I saw some strange behaviour on the server. Apparently according to IIS7 it is compiling using .net 2.0 (the pool is configured with .net 2) but there are some "using" statements that include Linq ... how is it possible to compile the page if Linq is not part of the .net 2 itself ?
Just edited with news details on the code itself. No namespace at all everywhere.
Hi There – i had a similar problem; all my namespaces and inheritance was in place. Then i then noticed that the class file’s build action was set to “Content” not “Compile” (in the properties window.
For whatever worth might there be for an answer (possibly not the right one) after many months, i think i should contribute this:
There is a case that this happens, when you place a web site inside another (ie in a subfolder).
In that case, the only App_Code folder that is legitimate is the App_code folder of the outer web site. That is, the App_Code folder right under the root of the master web site.
Maybe (say maybe) there should be no need to transform your web site to a web application, if you place the class file inside the App_code folder of the ROOT web site.
include the namespace under which lists calss is defined
or
define both the master page and lists class under the same namespace
Finally I understood quite lately that it was a website and not a web application I had to question the guys here to get it... So it's quite normal all the error I had. I haven't had the occasion to convert it first.
Make sure that in your masterpage, you have an #include statement for the namespace that the lists class is a part of (if they're in seperate namespaces, the masterpage isn't going to automatically pick up on it).
As for the strange server side behavior, .NET 2.0, 3.0, and 3.5 all run inside of .NET 2.0 app pools in IIS. It looks strange at first, but you get used to it. Here's a link with a little more in-depth explination:
The Way I See It: Where is ASP.NET 3.5 on IIS?
In order to use a type, you must reference the assembly which defines it and include the appropriate namespace.
Using only includes namespaces, if you don't use any types from said namespaces it has no effect.
is lists.cs wrapped in a namespace? if it is the case then you need to add the namespace (yournamespace.lists) or include it in masterpage. Check Also if your MasterPage is in a Namespace
Modify the Build Action of the App_Code Class to Compile.
Clean and Build the Project
This worked for me.
I had this problem myself
It wasn't working because the project I was referencing was set as a console application in its properties instead of a class library

Categories

Resources