Use Google Calendar API in User Control : System.IO.FileNotFoundException - c#

I fail when trying to use the Google API v3 in a user control.
Steps:
Create a new project in Visual Studio Express 2013 Update 4. Target framework: .NET 4.5 (tried 4.0 too)
Install NuGet package "Google.Apis.Calendar.v3 Client Library" and all and all dependencies
Add new User Control "MyControl"
In MyCalendar_Load add the following line: CalendarService service = new ServiceCalendar();
Add using Google.Apis.Calendar.v3;
So the code of my control looks like:
using System;
using System.Windows.Forms;
using Google.Apis.Calendar.v3;
namespace Google_Calendar_Test
{
public partial class MyCalendar : UserControl
{
public MyCalendar()
{
InitializeComponent();
}
private void MyCalendar_Load(object sender, EventArgs e)
{
CalendarService service = new CalendarService();
}
}
}
Then I compile my solution so I get my newly created MyControl. When I try to put the control on the form the following error message appears:
System.IO.FileNotFoundException / Could not load file or assembly Google.Apis,
In the form I can add the CalendarService and start it without any problems. I'm puzzled.
Update
The version in the error message (V 1.0.0.23042) doesn't match to the version NuGet installed (V 1.0.0.26011). But this doesn't make any sense to me.

Related

Custom addon not displayed in the addons menu in G1ANT studio

I am trying to create a new addon but the addon is not being displayed in the addons menu in G1ANT Studio. Even other addons installed from the marketplace are also not displayed. I am using the latest version. I have tried running G1ANT studio as administrator. Yet it makes no difference.
Here is the Addon.cs file of my addon:
using System.Collections.Generic;
using System.Linq;
using System.Text;
using G1ANT.Language;
// Please remember to refresh G1ANT.Language.dll in references
namespace G1ANT.Addon.LibreOffice
{
[Addon(Name = "libreoffice", Tooltip = "Provides commands to automate LibreOffice")]
[Copyright(Author = "G1ANT LTD", Copyright = "G1ANT LTD", Email = "support#g1ant.com", Website = "www.g1ant.com")]
[License(Type = "LGPL", ResourceName = "License.txt")]
[CommandGroup(Name = "calc", Tooltip = "Commands connected with creating editing and generally working on calc")]
public class LibreOfficeAddon : Language.Addon
{
public override void Check()
{
base.Check();
// Check integrity of your Addon
// Throw exception if this Addon needs something that doesn't exists
}
public override void LoadDlls()
{
base.LoadDlls();
// All dlls embeded in resources will be loaded automatically,
// but you can load here some additional dlls:
// Assembly.Load("...")
}
public override void Initialize()
{
base.Initialize();
// Insert some code here to initialize Addon's objects
}
public override void Dispose()
{
base.Dispose();
// Insert some code here which will dispose all unnecessary objects when this Addon will be unloaded
}
}
}
The addon also references some other DLLs as dependencies.
There are no errors in your code. Have you ever compiled the HelloWorld example from this tutorial? https://github.com/G1ANT-Robot/G1ANT.Addon.Tutorials/tree/master/G1ANT.Addon.Command.HelloWorld
Remember
1. All dlls in the solution should be marked as "Resource" and will be embeded into your addon
2. The target .NET Framework of your project should be 4.6.1
I figured out what the issue was. The G1ANT.Language.dll was in the same directory as the addons, it seems to have been causing the issue.

Error when getting a UWP package info from a Winform App?

Using a WinForm App, I'm trying to mimic this sample from Microsoft's Github site that shows how to get package info by using the Windows Runtime packaging API.
I'm getting following error at line: Package package = Package.Current;, of the code below, when trying to get a UWP package info from a WinForm app:
The type or namespace name 'Package' could not be found (are you missing a using directive or an assembly reference?)
Question: Although the error is a famous C# error that has many online posts/solutions, but here the context is different. Compiler seems to be complaining that I'm missing required assembly for Package class. But I do have using Windows.ApplicationModel; using statement in my code below. So what may be a possible cause of the error; i.e. what I may be missing here?
NOTE: To ensure the inclusion of the required assemblies, I did install this UWPDesktop NuGet package in WinForm Project on VS2017-ver 15.9.5 on Windows 10 Pro - Ver 8109:
WinForm App: Relevant code that throws error at line: Package package = Package.Current;
using System;
using System.Windows.Forms;
using Windows.ApplicationModel; //I added from here
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using Windows.ApplicationModel.Background;
using Windows.Foundation.Collections;
using Windows.Storage;
using Windows.Storage.Search;
using Windows.UI.Xaml;
using Windows.Management.Deployment;
namespace WinForms_to_UWP
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Package package = Package.Current;
PackageId packageId = package.Id;
Console.WriteLine(packageId.FullName);
}
}
}
From the GitHub's UWP Sample project: The relevant Code from scenario1_identity.xaml.cs that WORKS fine:
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using SDKTemplate;
using System;
using Windows.ApplicationModel;
namespace SDKTemplate
{
void GetPackage_Click(Object sender, RoutedEventArgs e)
{
Package package = Package.Current;
PackageId packageId = package.Id;
String output = String.Format("Name: \"{0}\"\n" + packageId.FullName);
OutputTextBlock.Text = output;
}
UPDATE:
Also worth noticing that when adding Using Windows..... statements on the top, the VS intellisense recognized only Window.Foundation and Window.UI. statements. For other Using Windows..... statements I had to hardcode - for example, Windows.ApplicationModel;. However VS2017 did not complain when I hard coded them. Moreover, all Using statements starting with Windows. are grayed out as shown in image below. Not sure if it has anything to do with the error:
The Nuget package you are referencing is outdated I am afraid and may not be maintained anymore.
But the problem is easy to fix. Just add a reference to the windows.winmd file of the SDK version you are targeting. See this screenshot:

Xamarin - The type or namespace name 'App' could not be found

Currently getting this error trying to run my Xamarin app to my iPhone live player.
"AppDelegate.cs(1,1): error: The type or namespace name 'App' could not be found (are you missing a using directive or an assembly reference?)"
My solution builds without errors, so slightly stuck.
These errors did not occur until after I updated to the most recent update. Any help is greatly appreciated.
App.xaml.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using COCApp;
using Xamarin.Forms;
namespace COCApp
{
public partial class App : Application
{
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new MainPage());
}
protected override void OnStart()
{
// Handle when your app starts
}
protected override void OnSleep()
{
// Handle when your app sleeps
}
protected override void OnResume()
{
// Handle when your app resumes
}
}
}
AppDelegate.cs
using System;
using System.Collections.Generic;
using System.Linq;
using COCApp;
using Foundation;
using UIKit;
namespace COCApp.iOS
{
// The UIApplicationDelegate for the application. This class is responsible for launching the
// User Interface of the application, as well as listening (and optionally responding) to
// application events from iOS.
[Register("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
//
// This method is invoked when the application has loaded and is ready to run. In this
// method you should instantiate the window, load the UI into it and then make the window
// visible.
//
// You have 17 seconds to return from this method, or iOS will terminate your application.
//
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
LoadApplication(new App());
return base.FinishedLaunching(app, options);
}
}
}
I had a similar issue for Android and iOS but mine would build and run just fine except there was a red underline under App on both projects.
I fixed it by right clicking on Android References->Add Reference->Projects then unchecking the already included shared project clicking OK.
Then I re-added the shared project and that fixed the error.
Note that PCL is no longer a thing when starting a Xamarin.Forms project in newest Visual Studio version, its .Net Standard now.
Check your project to make sure it has a reference to the PCL.
It seems like it's because of how you name the project. Mine was called 'Project Name' but in References it was imported as 'Project_Name' which didn't exist so I just deleted that reference and added a correct one by going to Android References->Add Reference->Projects. Now when I create new file namespace is like 'Project Name' and has errors so I ended up recreating the project but this time without spaces in name

Is it possible to start exploring WCF using Visual Studio Express for Windows Desktop 2013?

Can you set up a bare bones WCF project in Visual Studio Express 2013 for Windows Desktop C#
The walkthrough described in the MS Getting Started tutorial (http://msdn.microsoft.com/en-us/library/ms734712(v=vs.110).aspx) refers to Visual Studio (NOT the express edition), which has templates that are not available in Visual Studio Express (WDExpress.exe), specifically WCF Service Library.
How do you start something similar in WDExpress.exe without the templates?
Incidentally, I've tried copying templates over from Visual Studio Express for Web 2013 (VWDExpress.exe), but without success.
Here's a possible workaround for http://msdn.microsoft.com/en-us/library/bb386386.aspx using Visual Studio Express 2013.
All the steps are carried out in VSE 2013 for Windows Desktop (WDExpress.exe)
Step 1 - Start a new project using the template for Class Library - it should generate a project with the default name ClassLibrary1
Step 2 - Go to References (in Solution Explorer) and add references to System.ServiceModel and System.Runtime.Serialization
Step 3 - Create a new class called WCFServiceLibrary1.cs with the following content
using System.ServiceModel;
namespace ClassLibrary1
{
public class WCFServiceLibrary1 : IWCFServiceLibrary1
{
public string GetData(string value)
{
return string.Format("You entered: {0}", value);
}
}
}
Step 4 - Create a new class called IWCFServiceLibrary1.cs with the following content
using System.ServiceModel;
namespace ClassLibrary1
{
[ServiceContract]
public interface IWCFServiceLibrary1
{
[OperationContract]
string GetData(string value);
}
}
Step 5 - You need a client to run the WCF, so create a Windows form, which will have the default name Form1.cs, and add three controls; a textBox, (textBox1), a label (label1), and a button (button1)
Step 6 - in [Design] mode, double click on button1 and edit the action so that Form1.cs looks like this
using System;
using System.Windows.Forms;
namespace ClassLibrary1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
ClassLibrary1.WCFServiceLibrary1 client = new ClassLibrary1.WCFServiceLibrary1();
label1.Text = client.GetData(textBox1.Text);
}
}
}
Step 7 - add a Main class called Program.cs with the following content
using System;
using System.Windows.Forms;
namespace ClassLibrary1
{
public class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form1 form = new Form1();
Application.Run(form);
}
}
}
Step 8 - Open the Application tab in project properties (PROJECT >> ClassLibrary1.properties) and set Output Type to Windows Application and Startup Object to ClassLibrary1.Program
Step 9 - F5 will launch the form, which will behave as described at the end of the walkthrough under To build a client application
So, what this method does NOT do is go through "Testing the Service" in the walkthrough. Also, it shortcuts a few steps and it bundles the WCF in the same project as the Windows form. Hopefully, it provides bare-bones working code that you can develop and adapt for your application.

C# reference to a dll file i created doesn't work as it should

i'm using microsoft visual C# 2010 express to write a form program to read and write to an access database.
i created a class that is designed to read/write to the database file, saved it under a namespace and created a dll from it.
it is set as ".net Framework 4"
in my main program i added the reference to the dll file but when i try to add it to the code with
using Database;
it won't work even that the Database is in the reference of the namespace.
am i doing something wrong? or is there another way to use the commands from Database in my main program other then copying it to it?
// update //
solved
added public to all database public and DataBase db = new DataBase();
DATABASE.cs is use it for dll
using System;
using System.Collections.Generic;
using System.Data.OleDb;
namespace Database
{
public class DataBase
{
public DataBase()
{
}
public void ItemInsert(string name,string creator,string publishing,string itemType,string genere, string year)
the main program
using System;
using System.Windows.Forms;
using Database;
namespace library
{
public partial class newItemForm : Form
{
private void btnConfirmNewItemClick(object sender, EventArgs e)
{
DataBase db = new DataBase(); //this solved it
db.ItemInsert(txtItemNameType.Text, txtEditorType.Text, txtCreatorType.Text, comboBoxType.Text, txtGenereType.Text, txtYearType.Text);
}
}
}
You also need to Add a Reference to said assembly in your current project. The using statement brings a referenced assembly into scope...
right click you project in visual studio, select add refrence then choose Browse tab, then find the poject folder and get in bin -> debug and then you will see the dll choose it. visual studio will add it to your refrences, now you need to add a using on top of the pages you want it like this:
using mydllName;
if you didnt find your dll:
Load the librery project agian and right click in visual studio and press Build it will generate the dll.
You must add a reference to the assembly you created. The point of creating an Assembly is not that you don't have to "copy it" to another project, but rather that you don't have to duplicate code.

Categories

Resources