Assembly not found error - c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WebcamControl;
using System.Drawing.Imaging;
using Microsoft.Expression.Encoder;
using System.Reflection;
namespace SMS
{
/// <summary>
/// Interaction logic for camphoto.xaml
/// </summary>
public partial class camphoto : Window
{
public camphoto()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
try
{
Binding bndg_1 = new Binding("SelectedValue");
bndg_1.Source = comboBox1;
webcam1.SetBinding(WebcamControl.Webcam.VideoDeviceProperty, bndg_1);
//set properties
webcam1.PictureFormat = ImageFormat.Jpeg;
webcam1.FrameRate = 30;
webcam1.FrameSize = new System.Drawing.Size(320, 240);
comboBox1.SelectedIndex = 0;
string str = Microsoft.Expression.Encoder.Devices.EncoderDeviceType.Video.ToString();
FindDevice();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void FindDevice()
{
var vidDevice = Microsoft.Expression.Encoder.Devices.EncoderDevices.FindDevices(Microsoft.Expression.Encoder.Devices.EncoderDeviceType.Video);
foreach (var data in vidDevice)
{
comboBox1.Items.Add(data.Name);
}
}
}
}
Hi Friends, This is my code what it is preview to webcam. But one error is coming when I'm debugging this.
"File Not found Exception was cought : Could not load file or assembly
'Microsoft.Expression.Encoder, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The
system cannot find the file specified."
I'm already added Microsoft.Expression.Encoder reference to project references. But I don't understand why it is coming. please help me.

Go to Project Properties -> Build section and change Platform target to x86

Did you check if your project profile is NOT ".Net Framework 4.0 Client Profile". If so please change to ".Net Framework 4.0".
Also ensure that the references section has the dll reference. Try to clean the solution and then rebuild and also cross verify the dll in the bin directory once.

Related

How to handle the unit-test assembly load issue in C#

While loading assemblies from both x64/x86, I have got exception message as System.BadImageFormatException in my unit-test project.
Below is the code and screen shot of the exception I have got while debugging the test.
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Example_Addin;
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using Microsoft.Office.Interop.Visio;
using Visio = Microsoft.Office.Interop.Visio;
namespace exampleProject
{
[TestClass]
public class exampleUnitTest1
{
[TestMethod]
public void Test_example()
{
try
{
Example exm_obj = new Example();
string file_path = "test.json";
string template_file = "template.vssx";
double height = 0.5;
double width = 0.5;
db_obj.read_data_shape_creation(#file_path, 0.5, 0.5, "F06", #template_file, "testing");
}
catch (Exception)
{
System.Diagnostics.Debug.WriteLine("Exception occour");
}
}
}
Here, I want to unit test my code with assembly dependencies, but after setting the assembly, I get the above snapped exception and code execution is halted. 
This issue happen due to my target framework for unit-test and my core-project are not matching. When I have correct both case it is working.

Title: Problem connecting to LDAP server with Xamarin.Forms project c#

I have a problem with connecting to our LDAP server, using the NuGet package “Novell.Directory.Ldap.NETStandard2_0”.
My application is a Xamarin.Forms, with the Andoid & UWP part, based on NetStandard 2.0, using Visual Studio 2019, updated.
I could not find any built-in functionality in Netcore2.0 for using LDAP,
That is why I used the Nuget Package (Novell.Directory.Ldap.NETStandard2_0 by Novell, dsbenghe, mkostreba).
I have also used an LDAP query tool for Windows to test the connection, and that works.
But when I try to establish a connection in my app, I get an error with error code 91.
I have tried it with the full hostname, and with the direct ip address of the domain server, but I get the same error result. I have tried this with debugging UWP, not android.
I haven't started on making a correct credentials query yet, because the connection itself should first be ok.
This is my code: (under a simple button clicked)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Novell.Directory.Ldap;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using System.ComponentModel;
namespace App1.view
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Page2 : ContentPage
{
public Page2()
{
InitializeComponent();
}
private void button2_Clicked(object sender, EventArgs e)
{
try
{
LdapConnection conn = new LdapConnection();
conn.Connect("ldapserverhostname", 389);
conn.Bind("username query", "some password");
DisplayAlert("Error", "succesvol", "ok");
conn.Disconnect();
}
catch (LdapException f)
{
DisplayAlert("Error", f.ResultCode.ToString(), "ok");
return;
}
catch (Exception f)
{
DisplayAlert("Error", f.Message, "ok");
return;
}
}
}
}
Who could help me with this?
update 16 apr 2020:
I have established a connection + successful bind with our LDAP server using WPF NetCore console application, and also with a WPF NetCore desktop application, using the same serverinfo and user query info.
But I cannot get this working under Xamarin.Forms UWP or with a dedicated UWP app. Firewall of the computer is out of the question (I believe), because I am able to communicate with the LDAP server in multiple ways.
I have tried it with sideloading my Xamarin.Forms UWP app, but no result. >> Jumps to the first catch, every time.
Besides using the Novell Ldap Nuget, I have also tried the Windows Compatibility Pack for NetCore app in my UWP and Xamarin.Forms UWP app, but that will result in an "not supported platform" error.
here is my working code from the WPF NetCore desktop app:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Novell.Directory.Ldap;
using Novell.Directory;
namespace WpfApp3
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
string ldapHost = "fullyhostname.com";
String loginDN = "CN=MyUserName,OU=HK,something=Users,DC=ourdomainname,DC=com";
String password = "mypassword";
LdapConnection conn = new LdapConnection();
try
{
conn.Connect(ldapHost, 389);
if (conn.Connected)
{
MessageBoxResult r = MessageBox.Show("connection succeeded");
}
conn.Bind(loginDN, password);
MessageBoxResult t = MessageBox.Show("bind succeeded");
}
catch (LdapException f)
{
Console.WriteLine("Error1:" + "code= " + f.ResultCode.ToString());
Console.WriteLine("Error1:" + "code= " + f.LdapErrorMessage);
return;
}
catch (Exception f)
{
Console.WriteLine("Error:" + f.Message);
return;
}
conn.Disconnect();
}
}
}

Windows.Storage error: the type of namespace Storage does not exist in namespace windows

I am very new to C#, visual studio, and related Microsoft work. So it is very likely that I messed something up and I hope some one can help me a bit on this.
I create an Console application and I am trying to run some tutorial C# code. There is a red line under when I try to load Windos.Storage.Pickers and all namespaces after it. I attempt to add the references, but I can't find what I need there.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows;
using Windows.Storage.Pickers;
using Windows.Storage.Streams;
using Windows.Graphics.Imaging;
using Windows.Media.FaceAnalysis;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Shapes;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
FaceDetector faceDetector;
IList<DetectedFace> detectedFaces;
FileOpenPicker photoPicker = new FileOpenPicker();
photoPicker.ViewMode = PickerViewMode.Thumbnail;
photoPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
photoPicker.FileTypeFilter.Add(".jpg");
photoPicker.FileTypeFilter.Add(".jpeg");
photoPicker.FileTypeFilter.Add(".png");
photoPicker.FileTypeFilter.Add(".bmp");
StorageFile photoFile = await photoPicker.PickSingleFileAsync();
if (photoFile == null)
{
return;
}
}
}
}
the namespace you are tying to use is use for UWP development.
The problem is that you are trying to use it in Console Development.
Read about it here

EmguCV "The type initializer for 'Emgu.CV.CvInvoke' threw an exception"

I have got a problem when using EmguCV. Everytime I try to create SIFT or SURF detector I get exception "The type initializer for 'Emgu.CV.CvInvoke' threw an exception".
I've already: installed MSVCRT, copied OpenCV and Emgu dlls to the execution directory, added to solution OpenCV and Emgu dlls, added to solution Emgu.CV, Emgu.CV.GPU, Emgu.CV.ML, Emgu.CV.UI, Emgu.Util references.
Unfortunately I still got exception. I've tried to build SURFFeature example and it worked perfectly. It actually means that I make some mistake, but I can't find it... Please help...
Here's the code:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Features2D;
using Emgu.CV.Structure;
using Emgu.CV.UI;
using Emgu.CV.Util;
using Emgu.CV.GPU;
namespace blablabla
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
Bitmap waveform_to_file = new Bitmap(2, 2);
//Emgu.CV.Features2D.SIFTDetector detector = new Emgu.CV.Features2D.SIFTDetector();//(0, 3, 0.04, 10, 1.6);//(400, true, 3, 4);//
SURFDetector surfCPU = new SURFDetector(500, false);//I got exception on these lines
Emgu.CV.Util.VectorOfKeyPoint keypoints = new Emgu.CV.Util.VectorOfKeyPoint();
Emgu.CV.Image<Emgu.CV.Structure.Gray, Byte> waveform_to_file_gray = new Emgu.CV.Image<Emgu.CV.Structure.Gray, byte>(waveform_to_file);
Emgu.CV.Features2D.ImageFeature<float>[] modKeyPointsArray = surfCPU/*detector*/.DetectFeatures(waveform_to_file_gray, null);
List<Emgu.CV.Features2D.ImageFeature<float>> modKeyPointsList = new List<Emgu.CV.Features2D.ImageFeature<float>>();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message + ex.StackTrace);
}
}
}
}
Solution explorer:
http://ifotos.pl/zobacz/4JPG_wwaerwh.jpg
bin/debug:
http://ifotos.pl/zobacz/3JPG_wwaereh.jpg

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.

Categories

Resources