Could not load assembly MVCSiteMapProvider creating View

Jun 13, 2011 at 2:56 PM

I am getting an error from Visual Studio 2010 using MVC 3 saying:

 Could not load file or assembly 'file:///c:\mvcSiteMapProvider 3.1.0 RC\new40\MvcSiteMapProvider.dll' or one of its dependencies.  Operation is not supported. (Exception from HResult: 0x80131515). 

This is occuring creating a View with read/write actions and views, using Entity Framework and using the Razor engine.  I already have controllers with SiteMap attributes in the project that are working fine and I can create an empty view or a view with empty read/write actions but creating the view with a model and data context gets the above error.

I did not see a discussion on this topic.

hotsdogs.

 

 

 

Coordinator
Jun 14, 2011 at 9:15 AM

Any stacktraces?

Jun 14, 2011 at 1:39 PM

No Stacktrace. It is Visual Studio throwing up the error. I sent it in an email and I think you can reproduce easily.

I found it is not a problem with the Site Map provider directly. It is more a VS2010 issue when you try and add a View with read/write methods using the entity framework but the Model Class is not a type within the Data Context you choose for the View. If you have a reference to the MVCSiteMapProvider you get the error. If you remove the reference to the MVCSiteMapProvider you get a different error telling you the Model your are selecting for the View is not part of the DataContext.  Not sure why the site map provider is getting involved in that process or why VS 2010 is pulling it in.  Not sure if the MvcSiteMapProvider can changed to not be part of this error chain.

Craig

Jun 14, 2011 at 1:39 PM

No Stacktrace. Only this from Visual Studio.

But I found it is not a problem with the Site Map provider I do not think. It is more a VS2010 issue when you try and add a View with read/write methods using the entity framework but the Model Class is not a type within the Data Context you choose for the View. If you have a reference to the MVCSiteMapProvider you get the error above. If you remove the reference to the MVCSiteMapProvider you get a different error telling you the Model your are using is not part of the DataContext. So I think that could be a little painful in that the error is not really leading you to the correct solution and it would be hard to figure out the issue. Not sure if the MvcSiteMapProvider can changed to not be part of this error chain.

Craig Stricker

Applications Development

J-W Energy Company

Addison, TX.

cstricker@jwenergy.com

(972)661-4773 - Office

(214)236-5153 - Mobile

From: maartenba [email removed]
Sent: Tuesday, June 14, 2011 3:15 AM
To: Craig Stricker
Subject: Re: Could not load assembly MVCSiteMapProvider creating View [mvcsitemap:261184]

From: maartenba

Any stacktraces?


The information in this email may be confidential and/or privileged. This email
is intended to be reviewed only by the individual to whom it is addressed. If
you are not the intended recipient or an authorized representative of the
intended recipient, please be aware that any review, dissemination or copying of
the information contained within this email and its attachments, if any, is
prohibited. If you have received this email in error, please immediately notify
the sender by return email and delete this email from your system. Thank you.
Coordinator
Jun 14, 2011 at 2:45 PM

Is there an option to create small project reproducing this behaviour?

Jun 14, 2011 at 3:09 PM

To reproduce the behavior you can create a new MVC 3 application. Can be empty.

Create an Entity Framework data context. I built one based on the Sports Store sample application database but any Entity data context will do.

Then create a Model. Can be anything really. I created a class with one string property called TestData:

Public class TestData

{

Public string Tests {get;set;}

}

Then create an MVC controller and specify to create the read/write properties based on an Entity Framework data context. Specify the model, in my case above the TestData, and specify the Data Context as above, in my case the Sports Store Entities data context.

Here is the dialog for the Controller/Views I am creating.

Clicking Add gives the following message when you have a reference to the MVCSiteMapProviderDLL.

If you remove the reference to theMVCSiteMapProvider DLL you get the following message clicking Add.

Obviously I should not be creating the controller/Views this way but the error message was throwing me off the real problem.

Craig Stricker

Applications Development

J-W Energy Company

Addison, TX.

cstricker@jwenergy.com

(972)661-4773 - Office

(214)236-5153 - Mobile

From: maartenba [email removed]
Sent: Tuesday, June 14, 2011 8:46 AM
To: Craig Stricker
Subject: Re: Could not load assembly MVCSiteMapProvider creating View [mvcsitemap:261184]

From: maartenba

Is there an option to create small project reproducing this behaviour?


The information in this email may be confidential and/or privileged. This email
is intended to be reviewed only by the individual to whom it is addressed. If
you are not the intended recipient or an authorized representative of the
intended recipient, please be aware that any review, dissemination or copying of
the information contained within this email and its attachments, if any, is
prohibited. If you have received this email in error, please immediately notify
the sender by return email and delete this email from your system. Thank you.
Feb 11, 2012 at 3:05 PM

Discovered this happening with my project when I was trying to create a new Controller with EF Data Context.

I found the solution in this blog http://blogs.msdn.com/b/brada/archive/2009/12/11/visual-studio-project-sample-loading-error-assembly-could-not-be-loaded-and-will-be-ignored-could-not-load-file-or-assembly-or-one-of-its-dependencies-operation-is-not-supported-exception-from-hresult-0x80131515.aspx

Basically, because we downloaded MVCSiteMapProvider and immediately unzipped it and added it as a reference to our projects...it was flagged as untrusted and VS2010 doesn't like untrusted things lurking in it's projects...go figure!  :)

Go to the zip file (or redownload if you lost it) and right click -> properties and check the Unblock box in the lower right corner.  Unzip back into the same directory you have the first fiiles and overwrite them.  No need to remove from your project References. 

Retry creating your View or add your Controller - Tada!  :)