'StaticClass' does not contain a definition for 'Property' - c#

Edit 2, I'll Rephrase the whole post:
I have the static class Project.Shared.Constants and it has some constants and public getter properties:
using System;
using System.IO;
using Microsoft.Win32;
namespace Project.Shared
{
public static class Constants
{
public const RegistryHive HIVE = RegistryHive.LocalMachine;
/*
... more constants
*/
public static RegistryView RegistryView
{
get
{
return Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32;
}
}
}
}
Then I had a Project.Infrastructure.RegistryReader. It exists in the code for quite some time and uses the static class.
using System;
using System.IO;
using Microsoft.Win32;
using Project.Shared;
namespace Project.Infrastructure
{
public class RegistryReader
{
public string Read(string keyName)
{
using var baseKey = RegistryKey.OpenBaseKey(Constants.HIVE, Constants.RegistryView);
using var subRegistryKey = baseKey.OpenSubKey(keyName);
/*
Actual access, read, parse
*/
return resultValue;
}
}
}
Now I want to add a Project.Infrastructure.RegistryWriter in the same project and same namespace and use the same statics:
using System;
using System.IO;
using Microsoft.Win32;
using Project.Shared;
namespace Project.Infrastructure
{
public class RegistryWriter
{
public void WriteEthernetChannelInRegistry(string keyName, string value)
{
using var baseKey = RegistryKey.OpenBaseKey(Constants.HIVE, Constants.RegistryView);
using var subRegistryKey = baseKey.OpenSubKey(keyName, writable: true);
/*
Actual writing of the registry key
*/
}
}
}
Locally it works, so it can't be totally wrong. On the build system it fails, but only with the Writer. If I declare the same property locally, then the build finishes and has no issues with the Reader.
It might be something between VS using msbuild and the build system using dotnet build --Release but I couldn't make it fail locally yet.
Edit 3, the error I receive is:
Error: RegistryWriter.cs(72,99): error CS0117: 'Constants' does not contain a definition for 'RegistryView' [c:\source\...\Project.Infrastructure.csproj]

Related

SolrNet in C# example

I am trying to write a simple c# program to just connect to my Solr instance. I have downloaded the SolrNet library and made reference to SolrNet.dll in my project. I am following some of the examples online but have been getting the error "ServiceLocationProvider must be set" when the last line of my code is executed. Following is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using CommonServiceLocator;
using SolrNet;
using SolrNet.Attributes;
using SolrNet.Impl;
using SolrNet.Impl.DocumentPropertyVisitors;
using SolrNet.Impl.FacetQuerySerializers;
using SolrNet.Impl.FieldParsers;
using SolrNet.Impl.FieldSerializers;
using SolrNet.Impl.QuerySerializers;
using SolrNet.Impl.ResponseParsers;
using SolrNet.Mapping;
using SolrNet.Mapping.Validation;
using SolrNet.Mapping.Validation.Rules;
using SolrNet.Schema;
using SolrNet.Utils;
namespace WebApplication1
{
public class Post
{
[SolrField("id")]
public string id { get; set; }
}
public class Program
{
public static void Main(string[] args)
{
var connection = new SolrConnection("http://localhost:8983/solr/test");
Startup.Init<Post>(connection.ServerURL);
var solr = ServiceLocator.Current.GetInstance<ISolrOperations<Post>>();
}
}
}
Can someone tell me what am I missing?
Thank You

C# dll System.Reflection.TargetInvocationException error

I'm new on vs C#. I want to create dll file too use meta trader 5. my dll correct working in visual studio. But not working in meta trader.
Problem is Newtonsoft.Json packages.
Code
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace Analiz
{
public class anlz
{
public static void metot()
{
var myDetails = JsonConvert.DeserializeObject<List<MyDetail>>(File.ReadAllText(#"C:\Users\Durak\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\Files\json\deneme.json"));
}
}
public class MyDetail
{
public string emirtipi{get;set;}
public string miktar{get;set;}
public string takip{ get; set;}
}
}
Error :
enter image description here
When creating a DLL for an external program which does not support Newtonsoft.Json, you cannot build it this way.
Remove the reference to Newtonsoft.Json from your program.
Add a reference to System.Runtime.Serialization
After that you can refactor your code to:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace Analiz
{
public class anlz
{
public static void metot()
{
System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(List<Test>));
List<MyDetail> myDetails = (List<Test>)serializer.ReadObject(new FileStream(#"C:\Users\Durak\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\Files\json\deneme.json", FileMode.Open, FileAccess.Read));
}
}
public class MyDetail
{
public string emirtipi{get;set;}
public string miktar{get;set;}
public string takip{ get; set;}
}
}

cannot get Item in NameValueCollection to be recognized

I am trying to set my config from code according to this post Changing .net Membership ConnectionString
In this post, it has this code:
public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
{
// Get your new connnection string name and then overwrite the base here:
config.Item["connectionStringName"] = "MyNewConnectionStringName";
base.Initilize(name, config);
}
I made my class as such:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Web.Security;
using System.Collections.Specialized;
namespace WebUsers
{
internal class MembershipOverride : SqlMembershipProvider
{
public override void Initialize(string name, NameValueCollection configx)
{
// Get your new connnection string name and then overwrite the base here:
configx.Item["connectionStringName"] = "MyNewConnectionStringName";
base.Initilize(name, config);
}
}
}
I cannot get Item or Initialize to be recognized.
It is doing this:
Anyone see what I am doing wrong?
I cannot get Item or Initialize to be recognized.
There is a typo. You call base.Initilize instead of base.InitiAlize.
To access the collection element, try just
configx["connectionStringName"] = "MyNewConnectionStringName";

Custom Class Inside a WCF Service Object

A bit rusty here with regards to WCF Services.
I have a custom class named cSecurity.cs which does some custom functions.
I want to use this custom class inside my Service:
This is the App.svc.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace AppServices
{
public class App : IApp
{
public cSecurity _csec;
public string GetItems(int agentID, string agentName)
{
// Need to use some functions from the cSecurity class here???
return _csec.getItems();
}
}
}
This is the cSecurity.cs class:
using System.Collections;
using System.Configuration;
using System.Net;
namespace AppServices
{
public class cSecurity
{
// Some functions defined here....
public string getItems(){
return string.Empty;
}
}
}
But I am getting an error on the line:
public cSecurity _csec;
"The type or namespace name 'cSecurity' could not be found."
This seems pretty trivial but I seem to be lost here.
Appreciate any insight. Thanks.
For some reason, the solution for this was for me to close and restart VS. Not sure what caused the class for it to be not referenced by VS.

Unable to Compile with ImportMany attribute

As to total MEF newbie, I'm having a problem with my first test of MEF. My problem code is below-
using System;
using GlobalInterfaces;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
namespace GlobalInterfacesUnitTest
{
[TestClass]
public class GlobalInterfacesUnitTest
{
[TestMethod]
public void TestMethod1()
{
[ImportMany(AllowRecomposition = true)]
Lazy<IComponentGui, IImportComponentGuiCapabilites>[] Senders {get;set;}
}
}
}
The problem that I cannot get the compiler to find "ImportMany" attribute. I've checked the references against several demos and copied their references and still have the same problem. I cannot see what I'm overlooking. I am using VS2010 / Net4.0.
You can't define properties inside method. Move it out to class. Try:
[TestClass]
public class GlobalInterfacesUnitTest
{
[ImportMany(AllowRecomposition = true)]
Lazy<IComponentGui, IImportComponentGuiCapabilites>[] Senders {get;set;}
[TestMethod]
public void TestMethod1()
{
}
}

Categories