Dapper 'Query' not recognised - c#

The 'connection.Query' does not prompt for Dapper using statement. Dapper has been installed several times. I've tried entering the using statement 'using Dapper' but it's underlined in red saying:
Dapper namespace could not be found
Why is it happening?
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
namespace DataAccessLibrary
{
public class SQLDataAccess
{
public List<T> LoadData<T, U>(string sqlStatement, U parameters, string connectionString)
{
using (IDbConnection connection = new SqlConnection(connectionString))
{
List<T> rows = connection.Query<T>(sqlStatement, parameters).ToList();
}
}
}
}

I'm embarrassed to say i installed Dapper into the wrong project in my application. I assumed (never assume, always check) wrongly that the installation would be seen throughout my app.
Problem solved.

Related

Select IFC Physical Simple Quantity of Wall

I'm using XBim IFC libraries in order to get some info of a Building model elements.
Specifically, of IfcWall entities.
I have to acces Wall Base Quantities (lenght, height, width, etc.) but I cant reach those properties from IfcWall class.
I have this class:
using Dapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xbim.Ifc;
using Xbim.Ifc4.ActorResource;
using Xbim.Ifc4.DateTimeResource;
using Xbim.Ifc4.ExternalReferenceResource;
using Xbim.Ifc4.PresentationOrganizationResource;
using Xbim.Ifc4.GeometricConstraintResource;
using Xbim.Ifc4.GeometricModelResource;
using Xbim.Ifc4.GeometryResource;
using Xbim.Ifc4.Interfaces;
using Xbim.Ifc4.Kernel;
using Xbim.Ifc4.MaterialResource;
using Xbim.Ifc4.MeasureResource;
using Xbim.Ifc4.ProductExtension;
using Xbim.Ifc4.ProfileResource;
using Xbim.Ifc4.PropertyResource;
using Xbim.Ifc4.QuantityResource;
using Xbim.Ifc4.RepresentationResource;
using Xbim.Ifc4.SharedBldgElements;
namespace ProcesadorPremoldeado.IFC
{
public class IFCCalculos
{
public void CalculoPlacas(string fileName, XbimEditorCredentials editor)
{
using (var model = IfcStore.Open(fileName, editor))
{
using (var transaction = model.BeginTransaction("Quick start transaction"))
{
//get all Walls in the model
var ifcWallsList = model.Instances.OfType<IfcWall>();
foreach (var wall in ifcWallsList)
{
var prop = wall.PhysicalSimpleQuantities.Where(x=>x.Name=="Height");
}
transaction.Commit();
}
}
}
}
}
That lambda expression return me a row, correctly filtered by Name parameter, as this property is accessible.
But I cant access the property call "LengthValue", the strange thing is that the property is visible during debbugin if I put a breakpoint, under "prop" list in the foreach loop.
Anyone could give me an idea of what could be happening?
Thanks in advance!
This is because LengthValue is a property of IfcQuantityLength, but PhysicalSimpleQuantities are of supertype IfcPhysicalQuantity. You just need to select quantities of the right type
var height = wall.PhysicalSimpleQuantities
.OfType<IfcQuantityLength>()
.Where(x=>x.Name=="Height")?
.LengthValue;

System.InvalidProgramException Error C# when creating CIMSession

Trying to remotly connect to another PC's WMI but when creating the CimSession I get the following error
System.InvalidProgramException:'Common Launguage Runtime detexted an invalid program'
The code I am running is as follows
using System;
using System.Text;
using System.Threading;
using Microsoft.Management.Infrastructure;
using Microsoft.Management.Infrastructure.Options;
using System.Security;
namespace SMAPIQuery
{
class Program
{
static void Main()
{
string computer = "ComputerB";
DComSessionOptions DComOptions = new DComSessionOptions();
DComOptions.Impersonation = ImpersonationType.Impersonate;
CimSession Session = CimSession.Create(computer, DComOptions);
}
}
}
Unsure as to what throws this error or how to get around it
The issue was I was using .Net Core and not .Net Framework

Something wrong with my connection C# - Microsoft Access 2010

Ok, so, I created a connection between Visual Studio's C# (2012) and Access. That means, I've done it the manual way (with no code). However, this method can't help me do exactly what I want, so I've done the coding way as well.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Configuration;
using System.Xml.Serialization;
namespace WindowsFormsApplication1
{
public partial class horaireForm : Form
{
DateTime semSess;
int numSemaine;
int jourSem;
int periode;
string theoOuLabo;
string lesCours;
string cours;
string lesProfs;
string unprof;
string lesLocaux;
string lesGroupes;
string laComm;
string conn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\Stanley\\Desktop\\stuff\\Hiver 2013\\Horaires_EcranA2013.accdb";
(Sorry if it's long). Anyways, after this, I have this code here that gets info from a combobox (each case is the date of the weeks of a college semester). Since apparently I can't select the primary key if it's the values in the combobox, I've decided to use the dates as the values to select in the combobox and then use it to select the actual primary key in the database.
semSess = Convert.ToDateTime(comboSemSess.Text);
OleDbConnection laConn = new OleDbConnection(conn);
try
{
laConn.Open();
laComm = "SELECT NumeroSemaine FROM SemainDelaSession WHERE DebutSemaine = " + semSess;
OleDbCommand myAccessCommand = new OleDbCommand(laComm, laConn);
OleDbDataReader reader = myAccessCommand.ExecuteReader();
while (reader.Read())
{
numSemaine = Convert.ToInt32(reader["NumeroSemaine"]);
}
}
catch
{
MessageBox.Show("Une erreur s'est produite en accédant à la base de données");
}
finally
{
laConn.Close();
}
However, I still can't connect. It still gets the MessageBox. Does it have to do with the fact that I've done another connection before it, or the way I typed the connectionString, because I have no idea.
I can see a few issues... in the While (reader.Read()) block, you're overwriting numSemaine each time so you'll only ever get the last result in the datareader.
Also the date in the SELECT statement should have quotes around it (treat it like a string in SQL) and really it should be parameterised rather than concantenated (hard to SQL Inject from a combo box but not impossible and it's good practise anyway).
Also, a path just needs one \ between directories, not two.

Im getting exception Typeload what the exception can be?

I added as reference 3 dll's: Google.Apis , Google.Apis.Translate.v2 , System.Runtime.Serialization
In Form1 i have one line:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Translator.translate(new TranslateInput());
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
Now the error the exception is on the first line in the class Translator:
The line that throw the error is: var service = new TranslateService { Key = GetApiKey() };
The class code is:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Web;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using Google.Apis.Util;
using Google.Apis.Translate.v2;
using Google.Apis.Translate.v2.Data;
using TranslationsResource = Google.Apis.Translate.v2.Data.TranslationsResource;
public class Translator
{
public static string translate(TranslateInput input)
{
// Create the service.
var service = new TranslateService { Key = GetApiKey() };
string translationResult = "";
// Execute the first translation request.
Console.WriteLine("Translating to '" + input.TargetLanguage + "' ...");
TranslationsListResponse response = service.Translations.List(input.SourceText, input.TargetLanguage).Fetch();
var translations = new List<string>();
foreach (TranslationsResource translation in response.Translations)
{
translationResult = translation.TranslatedText;
}
return translationResult;
}
private static string GetApiKey()
{
return "AIzaSyCjxMe6RKHZzd7xSfSh2pEsBqUdXYm5tA8"; // Enter Your Key
}
}
/// <summary>
/// User input for this example.
/// </summary>
[Description("input")]
public class TranslateInput
{
[Description("text to translate")]
public string SourceText = "Who ate my candy?";
[Description("target language")]
public string TargetLanguage = "fr";
}
The error is:
Could not load type 'Google.Apis.Discovery.FactoryParameterV1_0' from assembly 'Google.Apis, Version=1.1.4497.35846, Culture=neutral, PublicKeyToken=null'.
Tried to google for help and also tried to change the project type to x64 platform but it didnt help. So i put it back on x86
I have windows 7 64bit visual studio c# 2010 pro .net 4.0 profile client.
Cant figure out what is the error ?
This error as reported in the above-posted messages is due to a local copy in the bin\Debug folder of your solution or project. Even though you attempt to clean your solution, such copies will persist to exist.
In order to avoid this to happen, you have to force Visual Studio to refer to the correct DLL by adding reference paths within a project properties. Unfortunately, if you got several projects within your solutions, you will have to set the reference paths for the projects one after another until completed.
Should you wish to know how to setup reference paths follow these simple instructions:
1.Select your project, right-click, then click "Properties";
2.In the project properties, click "Reference Paths";
3.Folder, type or browse to the right location of your DLL, click [Add Folder].
You will need to perform these steps for as many different locations you may have for each of your DLLs. Consider setting an output path under the Build tab of the same project properties, so that you may output your DLLs in the same directory for each of them, thus assuring you to find all the latest builds under the same location, simplifying forward your referencing.
Note this can only be one reason for this error. But it is sure that is has to do something with a wrong copy of the mentioned assembly.

Problem with interface in XNA game project

Here is a part mof my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
.
.
.
public virtual bool CheckCollision(ICollidable i_Source)
{
bool collided = false;
ICollidable2D source = i_Source as 2DICollidable;
if (source != null)
{
collided = source.Bounds.Intersects(this.Bounds);
}
return collided;
}
For some reason, there is an error about using ICollided2D.
Why does it don't recognize this kind of variable? Do I miss any "using" statment?
Either this is a typing mistake:
ICollidable2D source = i_Source as 2DICollidable;
Or you a missing an _ before 2DICollidable, so it becomes _2DICollidable as you can't start an identifier with a number.
2DICollidable
What is this? I dont think normal identifiers can start with number. Heck even SO code-highlighter shows it in red.

Categories

Resources