In the last few days, I tried to access regedit using c#.
The class RegistryKey is not defined after I added using Microsoft.Win32.
Can you help me?
Code:
using System;
using Microsoft.Win32;
using System.Security.Permissions;
namespace TMREAddons
{
public class RegEdit
{
RegistryKey key = Registry.LocalMachine.OpenSubKey("Software\\Wow6432Node\\MySQL AB\\MySQL Connector\\Net")
}
}
This is a basic class library, nothing more than that.
The targetFramework is:
<TargetFramework>netstandard2.1</TargetFramework>
You're targeting netstandard2.1 - which basically means "I want this to be able to run on any platform that's compatible with .NET Standard 2.1". Given that the Windows Registry doesn't exist on every .NET Standard 2.1 compatible platform, I'm not surprised at the error you're getting. (In general, I wouldn't expect anything from Microsoft.Win32 to be supported in .NET Standard.)
You can add the Microsoft.Win32.Registry NuGet package as a dependency, and that should solve the compilation issue - although it will still fail if you run on a non-Windows platform, of course.
Related
I just got C# working on Ubutnu. It's all good. But now I want MySql too. I installed the gacutil, and downloaded the connector, and I ran the gacutil, which it seemed like it worked.
I'm using Geany as my ide for now. It's free and already installed, and it worked great; until I tried to add using MySql.Data; I've read through all the stackoverflow posts for MySql.Data: they all state that I need to add an entry to my reference list in the VS project. Well, I don't have a reference list, nor a project. My 'project' directory only contains two(2) files: Test.cs, and Test.exe. MySql.Data is registered in the gac! Arg! Please, how do I get this working?!?!?
Running the gacutil:
dysmondad#Julep:/etc/mono/mysql/v4.5$ sudo gacutil -i MySql.Data.dll
Installed MySql.Data.dll into the gac (/usr/lib/mono/gac)
Complete source code for testing Mono install.
using System;
using System.Collections;
using System.Collections.Generic;
using MySql.Data; // <- this isn't recognized.
public class Test
{
static public void Main ()
{
List<int> integers = new List<int>();
integers.Add(7);
integers.Add(14);
integers.Add(21);
foreach( int i in integers )
{
Console.WriteLine(i);
}
}
}
UPDATE-1: Just found this on the MySql support page._______
You are now ready to compile your application. You must ensure that when you compile your application you include the Connector/Net component using the -r: command-line option. For example:
shell> gmcs -r:System.dll -r:System.Data.dll -r:MySql.Data.dll HelloWorld.cs
But...these don't work
-r:MySql.Data.dll
--nor--
-r:MySql.Data
UPDATE-2: I just discovered that if I use the -r option, and include the full path and name of the dll (even though it was registered with the gacutil) that seems to satisfy the compiler. So now my question is: how to get it to work with just the package name and not have to specify the full path?
Running Xamarin Studio (Community) 6.1 (build 4963) on OS X El Capitan 10.11.5, I am trying to use RNGCryptoService in my solution (targets iOS and Android) for which I need to use the namespace System.Security.Cryptography. However, it seems like using System.Security.Cryptography; and then calling RNGCryptoServiceProvider random = new RNGCryptoServiceProvider(); somewhere in my code gives me the error.
Error CS0234: The type or namespace name 'Cryptography' does not exist in the namespace 'System.Security'. Are you missing an assembly reference? (CS0234)
I tried to look for the System.Security.Cryptography package in the NuGet repositories (including the pre-release versions) but I did not find anything.
What am I missing? Where can I find the assembly reference?
You need the System.Security.Cryptography.Algorithms package to use RNGCryptoServiceProvider. Install that with NuGet v 3.4 or later:
> PM Install-Package System.Security.Cryptography.Algorithms
You may also need to modify your project.json file to make this package a dependency of dotnet5.4 and not a global dependency to stop the compiler from complaining about duplicate class declarations.
Follow up: It looks like System.Security.dll is not supported on Xamarin.iOS or Android. As an alternative, you might have some luck with Jeffrey Stedfast's fork of the Bouncy Castle cryptography library bc-csharp for use with Xamarin.Android and Xamarin.iOS.
Another option might be to use the PCLCrypto library with this helper class and workaround for NuGet.
I'm trying to use XDocument class inside a Unity3D project on Windows 7.
I did the following:
added the reference System.Xml.Linq to the Mono project.
included the namespace:
using System.Xml.Linq;
set the target framework to: Mono/.NET 3.5
clean and rebuild the project
But still Unity3D complains about it. Here's the error output in the console:
Assets/Scripts/Editor/RoadManager/RoadManager.cs(3,18): error CS0234:
The type or namespace name `Linq' does not exist in the namespace
`System.Xml'. Are you missing an assembly reference?
Any idea?
This has been discussed many times before, but few of these answers are complete.
As has been said before, Unity3d only supports up to .NET version 2.0, and it seems System.Xml.Linq was introduced in .NET 3.5, besides the fact that it is not listed on the Unity3d compatibility list anywhere.
The only things to try are to set the Mono API compatibility level to 2.0 (Menu: Edit > Project Settings > Player and look in the Other Settings panel), but it seems that that was a mistaken solution for Linq2SQL.
Another possible solution is to add the DLL yourself into the Unity Editor as shown:
Try dragging the C:\Program Files
(x86)\Unity\Editor\Data\Mono\lib\mono\2.0\System.Xml.Linq.dll file
into the unity project window like you would a texture or other game
asset.
If none of these yield ANY luck for you, then I'm afraid you are out of luck.
Unity3D supports .Net 2.0 only, so setting compatibility to .net 3.5 in MonoDevelop/Visual Studio will not work. You will have to make do without the class. This shows what library classes are available:
http://docs.unity3d.com/Documentation/ScriptReference/MonoCompatibility.html
See also this post in UnityAnswers: http://answers.unity3d.com/questions/46039/can-not-reference-systemxmllinq.html
Im refurbishing some old code that used to work on .NET Framework 3.5 to make it work on .NET Framework 4 using C#.
The following Regex used to work fine with version 3.5 but doesn't work anymore for some strange reason.
public static readonly Regex ChatColorRegex = new Regex("\\|c[A-Za-z0-9]{6,8}"),
ChatLinkRegex = new Regex("\\|H.*?\\|h");
I have added the 'using System.Text.RegularExpressions' at the top of my file, but the following error rises: 'The type or namespace RegularExpressions does not exist in the namespace System.Text.
I've googled about that and read that you have to add a Reference to System.Text.RegularExpressions in Visual Studio. However, when i did, i couldn't find System.Text.RegularExpressions in the list of References i could add.
I'm using Visual Studio 2012.
Could anyone tell me what im doing wrong, or forget to read?
The Regex class is still in the System.Text.RegularExpression namespace. The class is in the System assembly.
If you check your project references in Solution Explorer, you should see a reference to the System assembly. Check the properties of that reference to see what .NET Framework version is being used for the System assembly reference. It should match the .NET Framework version you selected for the "Target framework" in the project properties (Application tab).
Edit: The Regex class is in the System.Text.RegularExpressions namespace, not System.Text.
I'm doing some exercises with C# in the trial version of VS 2012. I want to execute a cmd command from a CS file. For this, I've tried Process.Start as well as System.Diagnostics.Process that are mentioned in these posts:
Run Command Prompt Commands
Execute CMD command from code
However, despite I added "using System.Diagnostics" and "using System.ComponentModel", I'm still getting "The type or namespace name 'Process' does not exist in the namespace 'System.Diagnostics', missing assembly reference" error. ¿Any suggestion so I can i get rid of this error? Thanks in advance.
This usually happens when you have Target framework = .NET Framework Client Profile, but DLL you reference is from .NET Framework (full). Make sure you have System.dll in your references from valid framework.
I just did the same - created empty console application with the following code:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.ComponentModel;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var prc = Process.Start("explorer.exe");
}
}
}
Works perfectly fine for me.
Additional thing to check is Intellisense - when you start typing "System.Diagnostics.Proc"... - does it show you dropdown with "Process" there?
UPDATE:
Windows Store projects are based on different version of target .NET Framework - .NET for Windows Store apps, which does not support functionality you need.
For more details do web search:".NET for Windows Store apps". Helpful links:
http://msdn.microsoft.com/en-us/library/windows/apps/br230302.aspx
http://msdn.microsoft.com/en-us/library/windows/apps/br230232.aspx