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

No metadata has been registered for class

4 Answers 646 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.
Brian
Top achievements
Rank 1
Brian asked on 03 Feb 2013, 01:38 AM
Alright, I've been pulling my hair out over this for nearly 3 days, and I'm about to scrap everything and abandon OpenAccess unless someone can point me in the right direction.

I've got an OpenAccess library that is connected to a SQL Azure database, and the compiled assembly is referenced in an MVC4 website. Pretty straightforward. But regardless how I create the OA entities, I always end up with this error:

No metadata has been registered for class 'DummyProject.Data.Models.DummyModel, DummyProject.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. (This usually indicates, that either this class is not declared persistent or it is declared persistent but not enhanced.)

I've tried creating the classes several ways:

  1. OpenAccess Class Library, XML Mapping
  2. OpenAccess Class Library, Attribute Mapping
  3. OpenAccess Class Library, Fluent Mapping
  4. OpenAccess Fluent Library (Code Only)

Using the first 3 methods, I generated classes from an existing Azure DB schema. When I wasted enough time, I ignored the database and attempted the 4th method as code-first. They all eventually failed with this error. For each attempt, I completely deleted the old class library and created a new project, to avoid any "leftovers" causing problems.

I've tried just about every solution I could find, but nothing has worked:

<Import Condition="Exists('$(MSBuildExtensionsPath)\OpenAccess.targets')" Project="$(MSBuildExtensionsPath)\OpenAccess.targets" />

Yes, that has been automatically added to my project. I tried every configuration/tweak from this thread:

http://www.sitefinity.com/developer-network/forums/developing-with-sitefinity-/no-metadata-has-been-registered-for-class-locationsmodule-model-locationitem

I've gone about as basic as I can get and still receive the error. Here's my dummy model:

public class DummyModel
{
    public int DummyId { get; set; }
    public string DummyText { get; set; }
}

My DataContext:

public partial class DummyDataContext : OpenAccessContext
    {
        static MetadataContainer metadataContainer = new DummyMetadataSource().GetModel();
        static BackendConfiguration backendConfiguration = new BackendConfiguration()
        {
            Backend = "Azure",
            ProviderName = "System.Data.SqlClient"
        };
 
        private const string DbConnection = "DefaultConnection";
 
        public DummyDataContext ()
            : base(DbConnection, backendConfiguration, metadataContainer)
        {
 
        }
 
        public IQueryable<DummyModel> Dummies
        {
            get
            {
                return this.GetAll<DummyModel>();
            }
        }
 
        public void UpdateSchema()
        {
            var handler = this.GetSchemaHandler();
            string script = null;
            try
            {
                script = handler.CreateUpdateDDLScript(null);
            }
            catch
            {
                bool throwException = false;
                try
                {
                    handler.CreateDatabase();
                    script = handler.CreateDDLScript();
                }
                catch
                {
                    throwException = true;
                }
                if (throwException)
                    throw;
            }
 
            if (string.IsNullOrEmpty(script) == false)
            {
                handler.ExecuteDDLScript(script);
            }
        }
    }

And lastly, my MetadataSource:

public class DummyDataMetadataSource : FluentMetadataSource
    {
        protected override IList<MappingConfiguration> PrepareMapping()
        {
            List<MappingConfiguration> configurations = new List<MappingConfiguration>();
 
            MappingConfiguration<DummyModel> dummyConfiguration = new MappingConfiguration<DummyModel>();
            dummyConfiguration .MapType().ToTable("Dummies");
            dummyConfiguration .HasProperty(x => x.DummyId).IsIdentity();
 
            configurations.Add(dummyConfiguration );
 
            return configurations;
        }
    }

All that compiles fine, but runtime throws the error. I'm developing locally on the Azure SDK, so this is all running on the Azure Fabric Compute/Storage emulators, but the Azure DB connection is pointed to a live Azure DB.

Can anybody help? God help me, I don't want to revert to Entity Framework, but I'm running out of time an options.

4 Answers, 1 is accepted

Sort by
0
Brian
Top achievements
Rank 1
answered on 03 Feb 2013, 09:01 AM
Solved. For anyone else who has seemingly tried everything else, uninstalling and reinstalling OpenAccess seemed to fix the problem.

That old "IT Crowd" adage holds true: Have you tried turning it off and on again?
0
Trevor
Top achievements
Rank 1
answered on 30 Mar 2016, 07:27 PM
Unbelievable.  After all the time I spent on this problem, this was the fix for mine as well....
0
Trevor
Top achievements
Rank 1
answered on 13 Mar 2017, 07:34 PM

A year later, still fighting this every once in awhile.  

 

This time, I had to do this (from the Telerik help): 

1) In Solution Explorer right-click the project containing the model and select Unload Project.
2) Right-click on the unloaded project and select Edit ProjectName.csproj (vbproj).
3) In your project file, find a line like this one:
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Or if you have VB.NET project, then look for:     
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
And import the following code after it:
<Import Condition="Exists('$(MSBuildExtensionsPath)\OpenAccess.targets')"Project="$(MSBuildExtensionsPath)\OpenAccess.targets" />
4) Reload your project and build the solution.

 

And, then I also had a newer reference to enhancer.exe that also had stuck into my .csproj file.

 

0
Trevor
Top achievements
Rank 1
answered on 08 May 2017, 08:31 PM

Had this problem again.  This time, I had to copy the OpenAccess.targets from a working machine to this machine in the directory:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild

Tags
General Discussions
Asked by
Brian
Top achievements
Rank 1
Answers by
Brian
Top achievements
Rank 1
Trevor
Top achievements
Rank 1
Share this question
or