I am trying out the Spark view engine with ASP MVC but get the error below when displaying a view. The view references model objects that are in a different assembly to the main web application (MyApp.Model.dll). I am stuck on the cause or resolution to this.
Dynamic view compilation failed.
0,0): error CS1704: An assembly with the same simple name
'MyApp.Model, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null has already been imported. Try removing one of the
references or sign them to enable side-by-side.
It sounds like you're referencing the same assembly multiple times in your view. Instead of using the <use assembly=""> element you might want to use the <use namesace=""> element
Craig I got the same problem, if I modify some class in assembly X and do a build, I got this error at runtime for the assembly X.
But after a "rebuild" (not "build") it's working.
For me it has been in the middle of a project. It comes maybe from an update ?
Matthieu
Related
Looking at core code examples of say... Edit Action for SpecificationAttribute. I am looking to replicate this delete function in the same manner in my plugin, however, getting an error.
Getting this error
'IHtmlHelper' does not contain a definition for 'DeleteConfirmation' and no extension method 'DeleteConfirmation' accepting a first argument of type 'IHtmlHelper' could be found (are you missing a using directive or an assembly reference?)
I have used in 3.90 but it getting error in 4.0 asp.net core Has anyone used #Html.DeleteConfirmation in a plugin (on administration side) that could give me a clues
I have a span element in the html like the following;
<span id="myattribute-delete" class="k-button">#T("Admin.Common.Delete")</span>
And trying to use #Html.DeleteConfirmation("myattribute-delete")
I know I probably need to double check my route, by the error is leading me to think the issue is not a routing issue.
As #Stephen stated it's not part of MVC, and it's custom helper by nopCommerce.
#Html.DeleteConfirmation is helper till/in nopCommerce 3.90, but in 4.0 it has been changed to
<nop-delete-confirmation asp-model-id="#Model.Id" asp-button-id="myattribute-delete" />
And that helper located at Nop.Web.Framework.TagHelpers.Adminso you have to add reference of it to your view file.
Every time I try to add a new type to my nesper engine, I get the following exception thrown in the nesper engine.
Could not load type 'K2Common.Order' from assembly 'NEsper, Version=4.8.0.0, Culture=neutral, PublicKeyToken=null'.
The engine eats the exception and then finds the proper type in my assembly as it iterates over each loaded assembly.
Is there a way to prevent nesper from searchign for a type in the nesper.dll first?
Among the configuration settings, there is a "import" list that you could try to clear out.
You can also define the SearchPath (assemblies in this case) that NEsper will use to find its assemblies. Though in practice, the best answer is to use the AssemblyQualifiedName. Using the typed functions i.e. AddEventType() will automatically use the AssemblyQualifiedName.
In the end I resolved the problem by using the Qualified assembly name
configuration.AddEventType("OrderEvent", typeof(Order).AssemblyQualifiedName);
instead of the below:
configuration.AddEventType("OrderEvent", typeof(Order).FullName);
I have the following line of code in my NinjectModule:
Bind<IValidatorFactory>().To<NinjectValidatorFactory>().InSingletonScope();
This used to work fine, but after doing a bunch of updates with Nuget, I'm getting the following errors:
Error 3 The type 'Ninject.Web.Mvc.FluentValidation.NinjectValidatorFactory' cannot be used as type parameter 'TImplementation' in the generic type or method 'Ninject.Syntax.IBindingToSyntax.To()'. There is no implicit reference conversion from 'Ninject.Web.Mvc.FluentValidation.NinjectValidatorFactory' to 'FluentValidation.IValidatorFactory'. D:\Projects\Current...\Configuration\MainModule.cs 19 13
Error 4 The type 'FluentValidation.ValidatorFactoryBase' is defined in an assembly that is not referenced. You must add a reference to assembly 'FluentValidation, Version=2.0.0.0, Culture=neutral, PublicKeyToken=a82054b837897c66'. D:\Projects\Current...\Configuration\MainModule.cs 19 13
It's true that I don't have a reference to FluentValidation Version=2.0.0.0, but I do have a reference to FluentValidation Version=3.4.0.0.
According to the metadata...
IValidatorFactory and ValidatorFactoryBase are defined in Assembly FluentValidation.dll.
NinjectValidatorFactory is defined in Assembly Ninject.Web.Mvc.FluentValidation.dll.
In my References folder, I have FluentValidation v3.4.0.0 and Ninject.Web.Mvc.FluentValidation v3.0.0.0.
I don't get why the compiler thinks I need FluentValidation Version=2.0.0.0.
Am I doing something wrong, or is this an issue with the Nuget package?
It looks as if the problem is that FluentValidation used to be a signed assembly but is now an unsigned assembly. Ninject.Web.Mvc.FluentValidation, however, still thinks FluentValidation is signed.
If you look at these two assemblies in ILSpy, you will notice the following:
Ninject.Web.Mvc.FluentValidation references FluentValidation with the following attributes: FluentValidation, Version=2.0.0.0, Culture=neutral, PublicKeyToken=a82054b837897c66
The latest version of FluentValidation, however, has different attributes: FluentValidation, Version=3.4.0.0, Culture=neutral, PublicKeyToken=null
Note that PublicKeyToken has changed to null (unsigned).
Hopefully, there will be a fix to this soon. Meanwhile, the options are to roll back to the previous FluentValidation or fix the reference via a new fork.
Update
Just posted a bug report to Ninject.Web.Mvc.FluentValidation. Hopefully, this will ensure that the issue is resolved quickly.
Update 2
Just in case anyone missed it, the comment from #dismissile below contains a good solution. I gave it a try and it pretty much works. Here's a slight variation with more detail:
Remove all Nuget packages that contain "FluentValidation".
Use Nuget to install FluentValidation-Signed.
Use Nuget to install FluentValidation.MVC3-Signed (or MVC4-Signed)
Using Package Manager Console, enter the following:
Install-Package Ninject.Web.Mvc.FluentValidation -IgnoreDependencies
Note: I didn't need to manually add a binding redirect to my Web.config (although the Nuget package added one automatically).
The problem is correctly identified by DanM. Here is the comment from the project coordinator
"Going forward the primary nuget package will no longer be strongly named.
A separate package, FluentValidation-signed can be used if you absoloutely need strong naming, but it is recommended that you use the unsigned version." Jeremy Skinner
#Html.RenderPartial(MVC.Shared.Views._Sorter);
throws error =>
There is no build provider registered for the extension '.spark'. You can register one in the section in machine.config or web.config. Make sure is has a BuildProviderAppliesToAttribute attribute which includes the value 'Web' or 'All'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: There is no build provider registered for the extension '.spark'. You can register one in the section in machine.config or web.config. Make sure is has a BuildProviderAppliesToAttribute attribute which includes the value 'Web' or 'All'.
Any ideas what might be wrong?
Adding this to web.config=>system.web=>compilation
<buildProviders>
<add extension=".spark" type="System.Web.Compilation.PageBuildProvider" />
</buildProviders>
Forces app to build spark view as webforms view and produces ${Something.something} all around. So - what's an equivalent for spark viewengine?
Can you please try to make the following change to T4MVT.tt. In the method ViewsFolderInfo.AddView, change the line:
Views[viewFieldName] = GetVirtualPath(item);
to
Views[viewFieldName] = viewFieldName;
If that works well, we can just add a switch to the settings file that makes it do this instead of the default full path.
Let me know how that goes!
Note that MVC.Shared.Views._Sorter is just a constant with the path to the view. If you were to write this code without T4MVC, what exact string would you pass in there?
Maybe Spark has different requirements in the type of view paths it accepts here? If needed, we can tweak T4MVC to make this work, but I'd like to fully understand the Spark behavior outside of T4MVC first.
I decided to use ASP.NET MVC, S#arp Architectur and the Spark View Engine for my new project.
First i created a new project with the help of S#arp.
I tried to update the view of the S#arp Architectur to .spark files.
That works fine except for one exception left. The ActionLinkForAreas Method used in the Application.spark is not found in the HTMLHelper class:
error CS1061: 'System.Web.Mvc.HtmlHelper' does not contain a definition for 'ActionLinkForAreas' and no extension method 'ActionLinkForAreas' accepting a first argument of type 'System.Web.Mvc.HtmlHelper' could be found (are you missing a using directive or an assembly reference?)
Call in Application.spark:
${Html.ActionLinkForAreas(c => c.Index(), "Home")}
The strange thing is it worked before i added the Spark View Engine
I would really appreciate your help
Just a guess, but I think you need to import the SharpArch.Web.Areas namespace so that it can be used in the Spark files.
In your Spark configuration do something like this:
var settings = new SparkSettings();
settings.AddNamespace("SharpArch.Web.Areas");
engines.Add(new SparkViewFactory(settings));
You can also do it in the specific .spark file at the top:
<use namespace="SharpArch.Web.Areas" />