the namespace "system" could not be added to the project - c#

I am working on a C# PCL. The targets include Windows Phone, iOS, and Android (all via Xamarin). Whenever I add a new class, I get a popup starting with "The namespace system could not be added to the project." It then proceeds me to warn me that things might not work. Well, they do work, but the popup is annoying. Can I stop it?

I guess this is a problem with the Framework version of the namespace systemand your project.
Confirm they both match the same framework.
I recommend you take a look over this link, which addresses a similar kind of issue. Usually when the references are not proper, you may get this kind of issue.

Related

Migrate Xamarin Forms Effect to .NET MAUI

For a Xamarin Forms application, I have been using a solution to track touch using code from an example out of Microsoft's Xamarin Forms Sample Project, specifically the Touch Tracking Effect sample.
I took that sample and simplified it down to just directly starting up with the BoxViewDraggingPage.xaml from App.xaml.cs and removing all other XAML files. That compiled and ran fine.
I then created a .NET Maui App with the same BoxViewDraggingPage (and the same TouchActionEventArgs.cs, TouchActionEventHandler.cs, TouchActionType.cs, and TouchEffect.cs) as was in the Xamarin Forms version.
I added the same TouchEffect.cs files that were in the sample for the specific platforms (iOS also has a TouchRecognizer.cs file)
When running it at that point I got the following:
So then I tried following the instructions for Migrating Xamarin.Forms Effects. The explanation for how Xamarin.Forms effects were set up matched perfectly, but it was unclear to me from that page what class the section titled "Effects in .NET MAUI" was replacing since it had a different class name than the previous code snippets earlier in the article. It seemed like it is replacing the FocusEvent class in the shared platform code and then specifies the platform specific code within #if platform sections (#if WINDOWS, #if __ ANDROID __, etc.) and so I am guessing that means the TouchEffect.cs files are no longer needed in the platform specific folders.
I didn't have a chance to find out if that was the case or if it works, because when I try to compile, I get:
I don't find any missing Nuget packages or assemblies when I tried searching. If I click the dot after Platform, I get the following choices, with instructions to use the navigation bar to switch contexts:
But I am already targeting net6.0-windows10.0.19041.0:
so I'm not sure why it says Not Available for that.
So, I am stuck trying to get this to work.
I am looking either for a solution to get the sample code working as it is in the Xamarin.Forms project, but for .NET MAUI (whether that be set up how the sample originally had it or how it is described in the Migrating Xamarin.Forms Effects link) - it could be that I am missing something simple in how to get that Microsoft.Maui.Controls.Compatibility.Platform.UWP piece to compile.
Or, the other possibility is that same link says that .NET MAUI Handlers can also handle this type of scenario. So if someone can show all the pieces that would need to be modified in order to do the same solution but using .NET MAUI Handlers, I am open to that. But it seems that the easiest path, though, should be to get the Effects working in .NET MAUI since everything is already written that way. I am just leaving both options open in looking for a solution.
EDIT:
OK, I figured out why the UWP portion had red squiggles under it. I figured out what "using the navigation bar to switch contexts" in the above screenshot meant. It meant I needed to select the context in the dropdown pictured below:
However, this just moves the squiggles to PlatformEffect and I cannot figure out what to do with the context or anything else to resolve that:
OK, I found out that PlatformEffect now inherits from Microsoft.Maui.Controls.PlatformEffect instead of the separate Platform inheritances shown in the Migrating Xamarin.Forms Effects example. That example is out of date and I didn't realize that and so it was confusing me.

Windows 10 PhoneCallOriginManager extension

I'm trying to build an app for Windows 10 Mobile that would act as the default phone call origin manager application. For this to be possible, the user must pick this application in the settings, as there can be only one (source).
I've checked the sample made exactly for this scenario (sample on Github).
The problem is, that in the .appxmanifest file, an extension must be declared for our application to show up in the settings dialog, when selecting the default phone call origin manager app, specifically line 39.
The error message I get is:
The element 'Extensions' in namespace 'http://schemas.microsoft.com/appx/manifest/foundation/windows10' has invalid child element 'Extension' in namespace 'http://schemas.microsoft.com/appx/manifest/mobile/windows10'. List of possible elements expected: 'ApplicationExtensionChoice' in namespace 'http://schemas.microsoft.com/appx/manifest/foundation/windows10' as well as 'Extension' in namespace 'http://schemas.microsoft.com/appx/manifest/uap/windows10' as well as 'Extension' in namespace 'http://schemas.microsoft.com/appx/manifest/foundation/windows10'.
I've been looking for the cause of this, and even came across this posted issue but I do not believe that answer is correct.
Am I missing something obvious here or is this a problem with the framework itself?
I can reproduce this issue in Visual Studio 2015 update 1, but the sample works well without any problem.
In my mind it may be the incompatibility issue between the manifest file and designer. And I have reported this issue to Microsoft using the internal channel.
Because this is only a visual studio designer issue and the app itself will not be impacted, I think we can simply ignore this issue until a fix is available.
Thanks.
A addition for the answer of Fang Peng, in order to ignore this issue, in your appxmanifest xml file, you need add this information:
IgnorableNamespaces="your_ignore_name_space" in the tag, for example:
<Package ... xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"IgnorableNamespaces="mp">

When compiling solution, previously working assembly reference / using no longer works [duplicate]

My C# WinForms solution has two projects.
A DLL which is the main project I'm working on, and an executable WinForms I call "Sandbox" so that I can compile/run/debug the DLL easily in one go.
I'm working in .Net 4.0 for both projects.
Everything was working fine until I added some seemingly innocent code, and a reference to System.Web in the DLL.
Now my Sandbox project can't see the namespace of the DLL project. I didn't change anything which I believe should have affected this.
If I delete the project reference to the DLL from the Sandbox references and re-add it, then the red underlines all disappear and the colour coding comes back for all my classes etc; but as as soon as I try to build the solution, the whole thing falls apart again.
When I right-click the DLL project in the Sandbox's references and view in object browser, I can see the namespace and all the stuff in there.
I have a feeling this might be some sort of bug?
Is this some sort of VS2010 bug? I had this same issue a few months ago and I could only fix it at the time by making a whole new project and re-importing my files. This time, however, I have a bajillion files and will only do that as a last resort!
Edit:
After panickedly going through and undoing all my changes, trying to find what caused the problems, it seems to be this line:
string url = "http://maps.google.com?q=" + HttpUtility.UrlEncode(address);
If I comment out this line, then I get no namespace errors and the project builds fine. I can't see anything wrong with this line though.
I'm ready to declare this a bug in VS2010, this has bitten way too many programmers already. The fix is easy: Project + Properties, Application tab, change Target Framework to ".NET Framework 4" instead of the Client Profile that is selected by default.
System.Web is not included in the client profile. Having this option in the first place is quite silly, the client profile is only 15% smaller than the full version of .NET 4.0. Having it selected by default is even sillier. But I digress.
UPDATE: mercifully this all got fixed in VS2012. Which no longer makes the client profile the default for a new project. And the client profile got retired completely in .NET 4.5, good riddance.
Check to make sure that both projects are using the non-client profile for their target framework (go to each project's properties to do this).
One possibility is that the target .NET Framework version of the class library is higher than that of the project.
I faced this problem, and I solved it by closing visual studio, reopening visual studio, cleaning and rebuilding the solution. This worked for me. On some other posts, I have read the replies and most of users solved the problem by following this way.
Try building only the project with the Sandbox dll first independently.
Then point your executable project to the required dll and ensure copy local is set to true. in reference settings.
Tthen build the executable project.
Changing the target framework from the ".NET Framweork 4 Client Profile" to ".NET Framework 4" worked for me with a similar problem. I agree that the client profile doesn't seem to have much of an advantage to using it. I seem to get nailed with weird errors that I hunt for until I remember that Visual Studio defaults to the client profile. I guess the moral of the story when getting an error is: if "Rebuild Solution" doesn't work, check the Target framework...
If you tried already doing the Framework change, and still not worked, I hope this works for you (as it did for me): Simply add the necessary references from within your projects. Very obvious but I was doing it wrong until I found what was the issue.
I just had this issue and it turned out to be I had multiple namespaces being used that had the same object name (i.e. business objects had the same names as mvc models);
Fully qualifying the names fixed the issue for me.

Weird: C# Type or Namespace name could not be found - Builds successfully

I have a weird error showing up in my project when it is open in the VS2012 IDE. Everywhere where I make use of another referenced project it suddenly says "Type or Namespace name could not be found". And by "says", I mean it has the text underlined in red with the error when I hover over it. The intellisense doesn't work for that code. BUT (and here's the weird part), the errors do not show up in the error console and the project builds and runs fine.
I can even debug and step through the code and it works perfectly fine. So at runtime the project is referenced fine but at design time the IDE can't find it. This worked for the past 2 weeks, and only then suddenly went a little bonkers. It's really annoying because I am rubbish at coding without intellisense!
Has anybody ever seen anything like this or have any suggestions?
I had this. I referenced assemblies whose "Target Framework" were set to ".Net Framework 4" in the "Application" secion of the projects properties. I changed this to ".Net Framework 4.5" not just in the referenced assembly's project but also the project I was building and it worked. Give this a try.
I have found this is a known problem with VS2012. Check to see how you are building, 64 bit or 32 bit. It won't work with 64 bit but it will with 32 bit. It will say things are missing and design will not work, however the program will run fine. I have heard the new VS update that hasn't been released yet will fix it.
Manually delete all the references to the libraries of the other projects and re-add. Intellisense rebuilds whatever it needs at that point and doing this has helped me in the past.
Another source of this problem is a solution with multiple projects containing code for the same namespace. The compiler can handle this. Intellisense won’t.
Related to a couple other answers here, I had a "Data" project using a "Data" namespace. Built fine, but just started recently showing errors from intellisense (even though it continued building fine.) (VS 2015.)
I fixed this by changing my "Data" project and namespace to "MyCompany.Data".
Oddly, the problem didn't seem to show up until recently, but making the change did fix it. Presumably there was a conflict in namespace with another project or reference, which can build fine, but intellisense can't handle.
You can change this in the Application tab of Project properties. You can also open up an EDMX diagram, right click, choose model browser, choose the second collapsable item in the model browser tab, hit properties, and there you'll find the Namespace option for generated Entity Framework entities and contexts. (Similiarly, if you modify an Entity Framework Model's namespace, you might also need to change the related connection to match [in Web.Config for ASP.Net and MVC.])
Make sure that there is no class with the name same as Project default namespace.
make sure that you don't reference .net framework 4.5 projects in .net 4 projects!
Examine your .proj files in a text editor and make sure the paths to your references are correct.
This can also happen if you set the Build Action to "None" on the referenced file and forget about it.
I had the same problem, where it would build and run fine, it just would always show that error and I couldn't use intellisense with the class.
I actually used the automatic method of creating the class in a new file to resolve the issue, then just copied the code over from the real class. I deleted the old file, renamed the new file, and now it works.

Are there any known compatibility issues with Microsoft Media Platform: Player Framework (formerly SMF) and Silverlight 5?

I'm trying to get the default template (adaptive streaming) for the MMPPF framework to work.
Currently I'm not getting any error, but the player does not play any videos. I've tried adding other sources besides the default, I can see them added in the playlist, but they won't play either.
Using Fiddler I can see that the player does not even attempt to retrieve the manifest (or anything else).
The online example here works fine, I've even tried using that manifest as a source, but it still won't play when I run it in Visual studio.
So my question, could this have anything to do with having Silverlight 5 toolkit installed? I would assume that the MMPPF/SMF template is supposed to work out of the box (which is also stated on the Codeplex site). Or is there something else I'm missing?
You may need to add some references to your project. MMPPF is using MEF to resolve plugins at run-time, and it can fail silently if it doesn't find a suitable plugin.
For Smooth Streaming, you need both Microsoft.SilverlightMediaFramework.Plugins.SmoothStreaming and Microsoft.Web.Media.SmoothStreaming for it to work for instance.
Update:
I've encountered another reference issue when migrating a project. I had to remove and re-add System.ComponentModel.Composition, then add System.ComponentModel.Composition.Initialization.
I tried to uninstall the Smooth Streaming Client that the MMPPF client installed and installed the newest from here, added a reference to the new dll (Microsoft.Web.Media.SmoothStreaming.dll) and everything worked.

Categories