Crystal Reports doesn't allow me to select datasource - c#

I'm working on windows forms application. I want to give crystal reports a .net object as datasource, my "product" class.
it worked for the first report and its working fine.
the problem is when i want to create another report, on "Standard Report Creation Wizard" when i navigate to project data > .net objects > [my class name] and try to include in to my report, this window pops up :|
what this window is asking me for?
I created another project and created a class and report and again it worked fine! so how can i make this work?

Ok, don't go through this avenue. It's much too complicated to set the datasource like this! Instead, go ahead and create the .rpt file, and from the designer in Visual Studio, you can view the database expert. From there, you can add any of your .NET objects.
I've set up a class for you to test as well. I just plugged this into my Reporting project and it works.
public class DummyReportClass
{
public string FieldOne { get; set; }
public string FieldTwo { get; set; }
public string FieldThree { get; set; }
}

Related

Why are there no data objects in data sources? (Data Source Configuration Wizard)

My application is based on Windows Forms. I am creating a report using RDLC (version 15.3.1). This report should have a table that is filled with the data I take from DataGridView.
Transferring data from DataGridView to the report is as follows.
List<OriginalPredicted> op = new List<OriginalPredicted>();
op.Clear();
for (int i = 0 ; i < mp.predResultsGridView.Rows.Count; i++)
{
op.Add(new OriginalPredicted { Original = (double)mp.predResultsGridView.Rows[i].Cells[0].Value, Predicted = (double)mp.predResultsGridView.Rows[i].Cells[1].Value });
}
ReportDataSource rds = new ReportDataSource("Dataset_Orig_Pred", op);
reportViewer.LocalReport.DataSources.Clear();
reportViewer.LocalReport.DataSources.Add(rds);
reportViewer.LocalReport.Refresh();
Before that I create a list consisting of class instances. Class is implemented as follows:
public class OriginalPredicted
{
public double Original { get; set; }
public double Predicted { get; set; }
}
The problem is that when I want to add a data set and select an object as a data source, I cannot find any class (business object) to use in "Select the data objects" window. There is only "Properties" item under the project tree but I expect to see also the classes which I created. Image of "Select the data objects" window
What have I tried:
Changing compiling options to x86. I guess RDLC works well in the x86 environment, so there are problems with x64 dependencies. It didnt work. Solution is provided here: Class (Business Object) not appearing in Report Data toolbox for RDLC
Rebuilding the project solution. Nothing changed.
Restarting Visual Studio. Still no luck.
Can the presence of dependencies in a project strictly for the x64 architecture affect the behavior of the Data Source Configuration Wizard?
My project uses a version control system. Could it also have an impact?
Also, I tried to reproduce the issue on clean project. In this case, everything works. Unfortunately, I can't redo the project elsewhere as it's very time consuming. Image of "Select the Data Objects" window after reproducing issue
Thanks.
The first solution I have tried isnt what just it look like. I was just messing around with Configuration Manager which is not right. The answer was hiding very well. So its more related to RDLC's bitness. In general the real solution is to set in Project Properties "Target Platform" to "Any CPU" or "x86" if its set to "x64" and check that "Prefer 32-bit" is checked. Image of "Project Properties"

VS 2015 C# AsyncExtension.cs not found

I haven't been able to find any information on this online. I'm debugging an console application, trying to step through some code. When I go to step over I get a source not found error. It says "AsyncExtension.cs not found" and then gives me some details. It says "You need to find AsyncExtension.cs to view the source for the current call stack frame". I'm working in VS2015. I'm assuming something async is happening behind the scenes, its erroring at some point but can't give me the specific details because it can't find the assembly containing AsyncExtension. But I don't know what this is, where to get it, etc. The code in particular I'm trying to step over is below. But I seem to get this at various points, and even when debugging other projects under the same solution.
Line of code:
var newObject = JsonConvert.DeserializeObject<HIDPMessage>(message.ToString());
HIDPMessage:
public class HIDPMessage
{
public string version { get; set; }
[Newtonsoft.Json.JsonProperty]
public string header { get; set; }
[Newtonsoft.Json.JsonProperty]
private Data Data { get; set; }
}
Not sure what you are trying to do but the code you have provided would not normally have any references to anything called AsyncExtension.cs. However your attempt to deserialize message could cause a JsonReaderException.
I'm guessing that "message" is some object that contains properties in common with HIDPMessage type and that you are trying to extract those into a new object, if so message.ToString(), unless overridden will just return the name of the type.
You need to serialize the object to a json string and use the json string instead of message.ToString();
Thanks for the input guys, you were right my code for deserializing was a little off. It turns out this app was built using VS2017 and some components from the Azure SDK were missing. I tried a manual install of the SDK but it wouldn't work - upgrading to 2017 fixed it, but I'm kinda surprised I had to upgrade just to get it to work.
I appreciate the feedback on the serialization stuff as well. This is a new-ish area for me and I'm still learning.

SQLite; "Cannot add a PRIMARY KEY column"-Exception

today I have started coping with databases. I've installed SQLite and SQLite-net. I am Programming a Windows 8.1 App using C#.
All I have is the following:
A Model:
public class Subject
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public string Name { get; set; }
}
And the OnLaunched-Event in App.Xaml.cs contains:
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
[...]
// Get a reference to the SQLite database
DBPath = Path.Combine(
Windows.Storage.ApplicationData.Current.LocalFolder.Path, "Subjects.s3db");
// Initialize the database if necessary
using (var db = new SQLite.SQLiteConnection(DBPath))
{
// Create the tables if they don't exist
db.CreateTable<Subject>();
}
[...]
}
When I launch this I get the following error after db.CreateTable(); is executed:
Cannot add a PRIMARY KEY column.
What is going wrong here? I really would appreciate your help.
Thank you very much.
Greetings, FunkyPeanut
I believe this is happening because you've changed the schema of the DB table by adding or removing a field from your Subject class. I.e. you've added the Id property after having already run the application to create the Subject table.
This is why it works with a new DB file. You'll either need to modify the schema (which in SQLite involves creating a new table, copy data from the existing table, deleting existing table and then renaming the new table), or simply delete your old DB file and create a new one.
I had the same issue ... this is so stupid but it was because when I copied / pasted code from another table I forgot to change its name ......
Before
[Table("CopiedTable")]
After
[Table("MyNewTable")]
I had the same issue.
Doing Build/Clean sorted the problem for me.
I had the same problem in a Xamarin.Forms app on Android. This was caused by a not very obvious fact that the Model class can have fewer properties when it is build in the Release mode compared to the Debug mode. This is because of the linker. It removes the properties that are not directly referenced in the code but only in the Release version. The Debug version still contains all the properties. So when you run the Release version of the app and then its debug version, it crashes with this confusing error.
I have fixed it by adding [Preserve(AllMembers = true)] attribute to the class to make sure it is the same in both the Release and the Debug mode.

C# Plugin Implementation Query

I am trying to write a plug-in for an application. The only thing I am provided with is a dll resource file which defines an interface; here's the code:
using System;
using System.Drawing;
namespace App.Plugin.Resources.Interface
{
public interface IAppPlugin
{
string Name { get; set; }
string Description { get; set; }
string Author { get; set; }
string Version { get; set; }
Icon MenuIcon { get; set; }
EventHandler PluginEventHandler { get; set; }
}
}
I then created a class that implemented this interface, made it display a message box, compiled the dll, placed it in the Plugins folder of the application and when the application executed and launched the plugin, it did display the message.
It seems to me that the software offers the means to execute external code (through the plugin system), but doesn't actually give access to any of the application's properties or methods.
Considering the above, my question is: Am I able to interact with the host process in any other way (e.g. get informed when a menu item is selected or even add a menu item myself to the main GUI) with the given resources or does this plugin system just act as an application launcher (by executing the code in the dll I'm providing)?
This seems just an application launcher, not a real plugin, unless there is some strategy implemented by convention: maybe the app looks at the plugin constructor with reflection, and pass some interfaces to the host system, or it looks for some properties marked with some custom attributes to pass some entry points.Another possible vehichle to pass the main application entry points is the PluginEventHandler, try to see in debug what you receive when the plugin is invoked. In addition, try to look with some tools as ILspy to see if there is something more in the plugin instantiation.

Getting CS1061 error on compile even though the property exists

I have come across the most curious problem ever as .Net dev. I am compiling a library which has a newly added property DeviceID in the class of UserInfo. The library internally uses the type and it's new property just fine, but when I try and reference it from another library, the compiler kicks back a compiler error stating
'library.UserInfo' does not contain a definition for 'DeviceID' and no extension
method 'DeviceID' accepting a first argument of type 'library.UserInfo' could
be found
Even though my class definition looks like:
public class UserInfo
{
public static UserInfo Current
{
get
{
if (UserInfoPrincipal.Current != null)
{
return UserInfoPrincipal.Current.UserData;
}
else
{
return null;
}
}
}
public string UserID { get; set; }
public string DeviceID { get; set; }
public string MikeLiUserID { get; set; }
public string TransactionServer { get; set; }
public string ApplicationKey { get; set; }
public string IpAddress { get; set; }
}
The offending code reads as such:
internal LogDetail BuildLogDetail(LogType entryType, string message)
{
return new LogDetail
{
ActingUserID = UserInfo.Current.UserID,
ActingDeviceID = UserInfo.Current.DeviceID,
ApplicationKey = UserInfo.Current.ApplicationKey,
IpAddress = UserInfo.Current.IpAddress,
EntryType = entryType,
OwnerID = UserInfo.Current.UserID,
LogData = message
};
}
I'd like to note that all of the other members of the UserInfo class go through the compiler correctly and it is just the DeviceID, which was added today, is causing the issue. I've tried Clean All, I've tried refreshing everything from TFS, manually deleting the obj and bin directories of both projects... nothing yet has worked.
UPDATE: This code, which is part of the library, works correctly:
public class UserInfoPrincipal : IPrincipal
{
public static UserInfoPrincipal Current
{
get
{
if (Thread.CurrentPrincipal is UserInfoPrincipal)
return (UserInfoPrincipal)Thread.CurrentPrincipal;
else
return null;
}
}
...
internal UserInfo UserData
{
get { return _userInfo; }
}
public string DeviceID
{
get { return _userInfo.DeviceID; }
}
...
}
So my hail mary pass was to remove the project reference and then add it again. Then it compiled. Have no clue why that worked, but figured I'd post it here for other who might run into the same problem.
Is the other library using a project reference or a binary reference? If its a binary reference, are you sure its using the latest build?
Check the reference path of the project that's generating the error; make sure you're either referencing the library project (if it's part of your solution) or the most recent build of the library (if it's not.)
I've gotten stuck in a few situations like this before. Here's what worked for me:
Are those two samples of code in separate projects? If so, I would say to try rebuilding the first project (containing the UserInfo class), then take out the line that fails the compilation out and try rebuilding the second project. Then do a rebuild all. Then add the offending line back in and do a rebuild all.
May not work for you, but worth a shot. I know that situation is frustrating.
for me -- try to recreate the line that shows an issue. Write the name of the object period (.) and wait for VS to show you the list of available properi
I encountered a very similar problem.
In my case I have a piece of code that I only need to run a couple times a year. When I attempted to use it there was an error accessing a Member. Nothing should have changed since the last time I used the code. Intellisense was detecting the member when using the '.' in Visual Studio. I restarted Visual Studio and the computer but the problem stayed.
In the end to fix my problem, I created a new file, copied the code from the original to the new file, and that was it. No code modifications. I used Ctrl-C, Ctrl-V so the content wasn't corrected by a manual touch. This isn't the first time copy and paste has fixed a bug so it's worth keeping the idea in the tool chest. Sometimes a mysterious problem demands an equally mysterious solution.
In my case, it was a problem with the web application's project properties. To fix it, I did the following:
Right-click the project > click Properties.
On the Build tab, change the Output path value for all configurations to: bin\
Previously, my output path had been bin\Debug or bin\Release depending on which configuration I was looking at. I don't know why this screwed with my markup page's ability to see methods in my codebehind, but it did. Once I changed this, the error disappeared.
This was in VS2012 w/ update 2.
My solution: I was create another name method what set property. My problem was on VS2015 + Silverlight 5

Categories

Resources