This is a migrated thread and some comments may be shown as answers.

Cannot create an Instance of...

16 Answers 558 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Alan
Top achievements
Rank 1
Iron
Alan asked on 15 Nov 2011, 04:58 AM
Hi Guys,

Just using the ORM trial. Downloaded and successfully ran the ORM SDK WPF C# solution. Works great. Also, changed the DBConnection to point to my SQL Server, updated the Field names in the classes - again wonderful. My data gets shown.

I wanted to bring in a DateTime field from my DB so firstly I made a copy of this solution as a backup (just in case).

But, I had a few problems that hopefully you might be able to help me with:

1. Noticed that the Entity diagram showed the DateTime field as VarChar so I had to manually update the mapping. Is this going to be fixed in Q3?

2. Once I added the field to the c# classes in ViewModel project and included the field in the Datagrid I kept getting a message saying that 'Cannot create an instance of ViewModel'. I commented out all of the new code I placed into the solution in case it was me, but still the message appeared. I loaded up the backup solution copy I made, which Built and ran fine, but now it comes up with the same error message. This leaves me to believe that there must be something a miss with the OpenAccess install because the backup should be fine, it was fine.

Opening the error message for more details showed that there may be a connection problem in my app.config file, which didn't changed after I made the backup. The connection string is fine.

Has this happened before? Do you have any ideas that could help me out?

Ta. Al.

16 Answers, 1 is accepted

Sort by
0
PetarP
Telerik team
answered on 18 Nov 2011, 09:18 AM
Hi Webal,

 We are happy that you have decided to give OpenAccess a try.
1. Basically this should not happen. We have tested it on our side and it appears to work fine. Can you please share with me the backend version your are using and also the sql type of your column?
2.If I understand your problem correctly you have fields in your model that are not maped to any columns (or are mapped to an unexciting column). If you add additional fields in your classes in order for everything to work out fine your new fields would need to have a representation in your database. OpenAccess can update your database for you however that does not happen automatically. The easiest way to perform this update is to run our forward mapping wizard and execute the generated script.
I believe that will fix your problem.

Best wishes,
Petar
the Telerik team

NEW and UPDATED OpenAccess ORM Resources. Check them out!

0
Alan
Top achievements
Rank 1
Iron
answered on 18 Nov 2011, 10:06 AM
Hi Petar,

The columns being mapped were from a View, not a Table. I only imported one View into my solution.After reading your ideas I decided to try to import the table that contained the 'StartDate' field I was after. OpenAccess mapped this field with a datetime type, not varchar. I have attached a screenshot. It seems OpenAccess doesn't correctly mapped the DateTime fields for the View, however, other datatypes (string, boolean, GUID) were mapped correctly. Do I need to import the tables that are contained within the View (as well as the View) for the mapping of the DateTime to work ok?
Al.
0
Alan
Top achievements
Rank 1
Iron
answered on 18 Nov 2011, 03:32 PM
Petar,

The StartDate field in the View is output as:  CONVERT(varchar(10),
                      tblSupportDoc_1.StartDate, 103) AS StartDate

-this is probably why varchar for this field is being displayed in the mapping.... see attached image.

Just working through the error message in my original message. At least I can rule out the DateTime/varchar problem.

Stay tuned...

Al.
0
Alan
Top achievements
Rank 1
Iron
answered on 18 Nov 2011, 04:13 PM
I still can't find the source of the problem for the error. If it is possible for you to take a look I have included the some coding below. Hopefully you may be able to identify the problem for me. You will notice that is it very similar to the working example given in the ORM SDK, except pointing to my db, and my fields.

If it is quicker for you, would you be able to provide an update version of the ORM SDK solution that includes a DateTime field in the RadDataGrid.

I have also upgraded to Q3 2011. Well done on the installer package, very nice.

Ta. Al.
<Window x:Class="View.MainWindow"
    xmlns:data="clr-namespace:Telerik.Windows.Data;assembly=Telerik.Windows.Data"
    Title="Test" Height="610" Width="1268" WindowStartupLocation="CenterScreen"
    xmlns:controls="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"
    xmlns:Navigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"
    xmlns:vm="clr-namespace:ViewModel;assembly=ViewModel"
    xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
        Closed="OnWindowClosed">
    <Window.DataContext>
        <vm:SupDocViewModel/>
    </Window.DataContext>
    <Grid>
        <TabControl Height="392" HorizontalAlignment="Left" Margin="12,12,0,0" Name="tabControl1" VerticalAlignment="Top" Width="1177">
            <TabItem Header="Support Docs" Name="tabSD">
                <Grid>
                    <telerik:RadGridView AutoGenerateColumns="False" CanUserFreezeColumns="False" IsReadOnly="True" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding Path=SupDocList}" Margin="6,10,6,6" Name="radGridView1" SelectedItem="{Binding Path=CurrentVCategory, Mode=TwoWay}" SelectionMode="Single" ShowGroupPanel="False" FontSize="10" RowHeight="20">
                        <telerik:RadGridView.Columns>
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding SupDocID}" HeaderTextAlignment="Center" Header="Sup Doc ID" IsReadOnly="True" Width="70" />
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding DocCode}" HeaderTextAlignment="Center" Header="Doc List Code" IsReadOnly="True" Width="70" />
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding DocName}" Header="Doc List Name" IsReadOnly="True" Width="200" />
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding StartDate}" HeaderTextAlignment="Center" DataFormatString="{}{0;d}" Header="Start Date" Width="70" />
                        </telerik:RadGridView.Columns>
                        <Navigation:RadContextMenu.ContextMenu>
                            <Navigation:RadContextMenu Opened="OnContextMenuOpened">
                                <Navigation:RadMenuItem Command="{Binding AddCommand}" Header="Add a category" />
                                <Navigation:RadMenuItem Command="{Binding EditCommand}" Header="Edit a category" />
                                <Navigation:RadMenuItem Command="{Binding DeleteCommand}" Header="Delete a category" />
                            </Navigation:RadContextMenu>
                        </Navigation:RadContextMenu.ContextMenu>
                    </telerik:RadGridView>
                </Grid>
            </TabItem>
            <TabItem Header="Handover Docs" Name="tabHO">
            </TabItem>
        </TabControl>
    </Grid>
</Window>


using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using Model;
using ViewModel.Commands;
using ViewModel.Repository;
 
namespace ViewModel.BusinessObjects
{
    public class SupDocBO : INotifyPropertyChanged
    {
        private int supDocID;
        private string docCode;
        private string docName;
        private DateTime startDate;
 
        private ObservableCollection<SupDocBO> products = new ObservableCollection<SupDocBO>();
 
        public SupDocBO()
        {
        }
 
        public SupDocBO(View_SupportDoc Vcategory)
        {
            this.supDocID = Vcategory.SupDocID;
            this.docCode = Vcategory.DocCode;
            this.docName = Vcategory.DocName;
           // this.startDate = Vcategory.StartDate;
            DateTime? dateOrNull = Vcategory.StartDate;
            if (dateOrNull != null)
            {
                DateTime startDate = dateOrNull.Value;
            }
             
        }
 
        public int SupDocID
        {
            get { return this.supDocID; }
            set { this.supDocID = value; }
        }
 
        public string DocCode
        {
            get { return this.docCode; }
            set { this.docCode = value; }
        }
 
        public string DocName
        {
            get { return this.docName; }
            set { this.docName = value; }
        }
 
        public DateTime StartDate
        {
            get { return this.startDate; }
            set { this.startDate = value; }
        }
 
        public static implicit operator SupDocBO(View_SupportDoc Vcategory)
        {
            return new SupDocBO(Vcategory);
        }
 
        public static implicit operator View_SupportDoc(SupDocBO Vcategory)
        {
            View_SupportDoc resultVCategory = new View_SupportDoc();
            resultVCategory.SupDocID = Vcategory.SupDocID;
            resultVCategory.DocCode= Vcategory.DocCode;
            resultVCategory.DocName = Vcategory.DocName;
            resultVCategory.StartDate = Vcategory.StartDate;
 
            return resultVCategory;
        }
        #region INotifyPropertyChanged Members
 
        public event PropertyChangedEventHandler PropertyChanged;
 
        private void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
 
        #endregion
    }
}
View - MainWindow.xaml.cs
using System;
using System.Windows;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.GridView;
 
namespace View
{
    public partial class MainWindow : Window
    {
        private void OnContextMenuOpened(object sender, RoutedEventArgs e)
        {
            RadContextMenu menu = (RadContextMenu)sender;
            GridViewRow row = menu.GetClickedElement<GridViewRow>();
 
            if (row != null)
            {
                row.IsSelected = row.IsCurrent = true;
                GridViewCell cell = menu.GetClickedElement<GridViewCell>();
                if (cell != null)
                {
                    cell.IsCurrent = true;
                }
            }
            else
            {
                menu.IsOpen = false;
            }
        }
 
        private void OnWindowClosed(object sender, System.EventArgs e)
        {
            IDisposable context = this.DataContext as IDisposable;
            if (context != null)
            {
                context.Dispose();
            }
        }
    }
}
0
Alan
Top achievements
Rank 1
Iron
answered on 21 Nov 2011, 12:59 PM
Not too sure why this post was Posted a couple of times... (could admin please delete the duplicate Posts - thanks)

Anyway, went back to ORM SDK and reopened the Sample WFP C# MVVM solution. I got the same error message. Reinstalled OpenAccess (Telerik-OpenAccess-SDK-2011.2.713.3) in repair mode and tried the sample again, still with the same error message. Completely uninstalled OpenAccess, rebooted pc (Windows 7) and reinstalled. Still same message -  (I attached a screenshot). Please help.

Al.
0
PetarP
Telerik team
answered on 22 Nov 2011, 10:45 AM
Hi Webal,

 That can only be caused if you have removed or modified the connection string that is located in the App.Config file in your View project. Please check your configuration file and reassure that you have a connection string named NorthiwndConnection. If such connection string is not present you will need to add it. That will fix your problem. Here is how the connection string should look like:

<connectionStrings>
    <add name="NorthwindConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=NorthwindOA;Integrated Security=True;Connect Timeout=2;User Instance=False" providerName="System.Data.SqlClient" />
  </connectionStrings>

All the best,
Petar
the Telerik team

NEW and UPDATED OpenAccess ORM Resources. Check them out!

0
Alan
Top achievements
Rank 1
Iron
answered on 22 Nov 2011, 04:22 PM
Hi Petar,

The connection string is fine. ORM Q3 wasn't available when I re-installed it yesterday so I have upgraded now to Q3 ORM and SDK. Running the sample WPF C# MVVM sample works well, however, when I open it in VS2010 the error (as seen in screenshot) displays as the solution opens.  As you can see from the attached screenshot the Northwind diagram displays ok.

Here is the complete error message (and connection string below - which tests successfully):
----------------------------

A connection string was referenced by name 'NorthwindConnection' but could not be resolved through the web.config or the executables app.config file.

at Telerik.OpenAccess.RT.Adonet2Generic.Impl.DBDriver.connect(ConnectionString connectionString, IDictionary driverProps, ConnectionPoolType poolType, LogEventStore pes) at OpenAccessRuntime.Relational.sql.SqlDriver.InitializeFor(ConnectionString connectionString, Boolean noConnect, PropertySet props, DBDriver& driver, Connection& conn, ConnectionPoolType poolType) at OpenAccessRuntime.Relational.RelationalStorageManagerFactory..ctor(StorageManagerFactoryBuilder b) at OpenAccessRuntime.storagemanager.StorageManagerFactoryBuilder.createSmfForURL()
-----------------------------

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <add name="NorthwindConnection" connectionString="Data Source=PCS-PC\SQLEXPRESS;Initial Catalog=NorthwindOA;Integrated Security=True;Connect Timeout=2;User Instance=False" providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>

Question: are there some files I can delete to make sure a full restore/repair of OpenAccess gets re-installed? I am not too sure what else it can be. As I said before when I initially started the solution built ok and I did not have this error message until I started playing around with the StartDate field....Will there be a Q3 version of this sample?

Thanks. Sorry for the lengthy discussion.

Al.


0
Ivailo
Telerik team
answered on 23 Nov 2011, 02:30 PM
Hello Alan,

This exception means that the connection string of your database connection is not configured in the app.config of some of the projects directly referring the data access project. Here you can find some useful information about how to do that in your projects.

Usually, this configuration is done automatically by our SDK, when you open the SDK Browser, locate your example application and click on the link button "Open in Visual Studio". Can you confirm that you have opened the sample this way, so that we can investigate for a possible bug in this automation? If you have opened it directly using Windows Explorer, using the SDK Browser for the same should resolve your issue.

In order to clear the files between re-installations of the SDK, you can delete the contents of the folder selected as cache folder. Go to the samples tab of the SDK Browser application, find the link button Sample cache settings under the samples list and change it or just clear it's contents.

I am looking forward to your feedback.
 

Greetings,
Ivailo
the Telerik team

Q3’11 of Telerik OpenAccess ORM is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

0
Alan
Top achievements
Rank 1
Iron
answered on 23 Nov 2011, 03:27 PM
Hi Ivailo,

Yes, it runs now... but strange thing is if I select MainWindow.xaml the error gets displayed at design runtime, i.e. VS2010 design view - see attached. I set View to be startup project.
Image a: shows error
Image b: runs ok, but you can see error displayed in background, however, no errors are displayed in the VS error list.

Thanks again for your assistance. Al.
0
Ivailo
Telerik team
answered on 23 Nov 2011, 04:10 PM
Hello Webal,

The problem still looks like there is something wrong with the application configuration. Try the following:

1) Clear the cache folder as described in my previous post
2) Reset the sample through the "Reset sample" link button
3) Click again on "Open in Visual Studio" button. As a result, a popup window should appear asking you to configure your connection.
4) Make your selection as per your preferences
5) Test the connection and click OK.
6) You should be able to execute the sample without exceptions

If you still have the exception, let us know and we will change the ticket type so that you can send us the solution attached. We will need to analyze it and validate that the SDK logic for auto-configuring the connections strings works properly.

Greetings,
Ivailo
the Telerik team

Q3’11 of Telerik OpenAccess ORM is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

0
Alan
Top achievements
Rank 1
Iron
answered on 28 Nov 2011, 02:18 PM
Hi Ivailo,

I did as you ask and have recorded some screenshots as I went. Also, after clearing the cache (Step 1) the 'Reset sample' link was disabled.

5a - WPF C# MVVM solution open from SDK and upgrade carried out to Q3.
5b - Opened MainWindow.xaml
5c - rebuild carried out
5d - clicked 'Reload the Designer' link in the VS2010 Design view

I hope this helps you. You can see the cache path has been changed to .....TelerikNew\

Thanks again for your support. Al.
0
Ivailo
Telerik team
answered on 28 Nov 2011, 04:28 PM
Hi Webal,

The exception on screenshot 5b seems like a ViewModel.dll aseembly is marked as blocked by your system and cannot be accessed. Can you find that DLL, check it's properties in windows explorer and click Unblock if such a button is active? 

I am looking forward to your feedback.

Best wishes,
Ivailo
the Telerik team

Q3’11 of Telerik OpenAccess ORM is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

0
Alan
Top achievements
Rank 1
Iron
answered on 29 Nov 2011, 02:55 PM
Hi Vailo,

Found the .dll, however, there were no file restrictions placed on it (Windows 7 32bit).
Opened up SDK again. Created a new cache ...\TelerikNew2\....

1. Instance_error5b_cont: this is a screenshot of Explorer showing the .dlls not present - same message in VS as Instance_error5b.
2. Instance_error5b_cont_AfterBuild : dll's now appear.
3. Instance_error5b_cont_afterBuild_ok: run View and everything was ok (you can see VS Design displaying 'Click to load Design view')
4. Instance_error5b_cont_afterBuild_ok_Design: clicked to load Design view (MainWindow.xaml) and the error is displayed.
5. Instance_error5b_cont_afterBuild_ok_Design_error: If I run the project (View as startup) it works ok. You can see the error being displayed, but not in the Error List.

Again thanks for assisting.

Al.
0
Damyan Bogoev
Telerik team
answered on 30 Nov 2011, 01:45 PM
Hi Webal,

I have slightly modified the initializing of the MainView.DataContext. You could find the changes attached.
Hope that helps.

Best wishes,
Damyan Bogoev
the Telerik team

Q3’11 of Telerik OpenAccess ORM is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

0
Alan
Top achievements
Rank 1
Iron
answered on 30 Nov 2011, 03:06 PM
Hi Damyan,

I guess there's more than one way to skin a cat! Nice work mate.

No errors being displayed now. I will keep this piece of code in my Toolkit.

Thanks again for Telerik support. I wish other companies would follow how well Telerik support their Users.

I really have appreciated the efforts made.

Al.
0
Damyan Bogoev
Telerik team
answered on 01 Dec 2011, 06:00 PM
Hello Webal,

I am glad to see that you managed to resolve the problems on your side.
If any other questions arise, do not hesitate to contact us back.

Greetings,
Damyan Bogoev
the Telerik team

Q3’11 of Telerik OpenAccess ORM is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

Tags
General Discussions
Asked by
Alan
Top achievements
Rank 1
Iron
Answers by
PetarP
Telerik team
Alan
Top achievements
Rank 1
Iron
Ivailo
Telerik team
Damyan Bogoev
Telerik team
Share this question
or