error CS1704: DLL loaded twice ? -razormachine - asp.net-mvc

I want to use RazorMachine on my VS2012 MVC 4 .NET webapp, called "Haas2013".
Everything is working, until I hit a line where I actually call RazorMachine.
I keep getting this error:
error CS1704: An assembly with the same simple name 'haas2013, 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.
Line 25: RazorMachine rm = new RazorMachine();
-->Error here: Line 26: ITemplate template = rm.ExecuteContent(res.Body);
When looking into Debug/Windows/Symbols, I can see the DLL of my project "haas2013.dll" loaded twice.
haas2013.dll C:\Users\Reinhard\AppData\Local\Temp\Temporary ASP.NET Files\root\6224be98\f18ecea8\assembly\dl3\43249f4b\692c79c0_cd2ace01\haas2013.dll No Yes Symbols loaded. C:\Users\Reinhard\AppData\Local\Temp\Temporary ASP.NET Files\root\6224be98\f18ecea8\assembly\dl3\43249f4b\692c79c0_cd2ace01\haas2013.pdb 29 1.0.0.0 27.03.2013 10:30 05740000-057A0000 [3820] iisexpress.exe: Managed (v4.0.30319)
haas2013.dll E:\Arbeiten\haas2013\haas2013\haas2013\obj\Debug\haas2013.dll No Yes Symbols loaded. E:\Arbeiten\haas2013\haas2013\haas2013\obj\Debug\haas2013.pdb 84 1.0.0.0 27.03.2013 10:30 08F90000-08FF0000 [3820] iisexpress.exe: Managed (v4.0.30319)
Is this the source of the error, or is this the expected behaviour?
I am using IIS-Express.

Related

"Consider app.config remapping" warnings in brand new project

I've created a brand new ASP.NET Framework MVC project (using the built in project template in Visual Studio 2019). This project was converted to use PackageReference using the answer provided here.
When I do a "Rebuild Solution", everything is fine.
I then add a new ASP.NET Framework Class Library (using the build in project templte in Visual Studio 2019) to the solution.
I do another "Rebuild Solution" and everything is still fine.
Now, when I add a reference to the class library project in the web project I get the following warnings when rebuilding the solution:
Consider app.config remapping of assembly "System.Buffers, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" from Version "4.0.2.0" [] to Version "4.0.3.0" [C:\Users\Me\.nuget\packages\system.buffers\4.5.0\ref\net45\System.Buffers.dll] to solve conflict and get rid of warning.
3> Consider app.config remapping of assembly "System.Memory, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" from Version "4.0.1.0" [] to Version "4.0.1.1" [C:\Users\Me\.nuget\packages\system.memory\4.5.3\lib\netstandard2.0\System.Memory.dll] to solve conflict and get rid of warning.
3> Consider app.config remapping of assembly "System.Numerics.Vectors, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" from Version "4.1.3.0" [] to Version "4.1.4.0" [C:\Users\Me\.nuget\packages\system.numerics.vectors\4.5.0\ref\net46\System.Numerics.Vectors.dll] to solve conflict and get rid of warning.
3> Consider app.config remapping of assembly "System.Runtime.CompilerServices.Unsafe, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" from Version "4.0.4.1" [] to Version "4.0.5.0" [C:\Users\Me\.nuget\packages\system.runtime.compilerservices.unsafe\4.6.0\ref\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll] to solve conflict and get rid of warning.
3> Consider app.config remapping of assembly "System.ValueTuple, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" from Version "4.0.2.0" [C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\Facades\System.ValueTuple.dll] to Version "4.0.3.0" [C:\Users\Me\.nuget\packages\system.valuetuple\4.5.0\ref\net47\System.ValueTuple.dll] to solve conflict and get rid of warning.
Here's a selection from the detailed build output:
1> Encountered conflict between 'Reference:C:\Users\Me\.nuget\packages\system.valuetuple\4.5.0\ref\net47\System.ValueTuple.dll' and 'Platform:System.ValueTuple.dll'. Choosing 'Reference:C:\Users\Me\.nuget\packages\system.valuetuple\4.5.0\ref\net47\System.ValueTuple.dll' because AssemblyVersion '4.0.3.0' is greater than '4.0.2.0'.
1> Encountered conflict between 'Platform:System.ValueTuple.dll' and 'CopyLocal:C:\Users\Me\.nuget\packages\system.valuetuple\4.5.0\lib\net47\System.ValueTuple.dll'. Choosing 'CopyLocal:C:\Users\Me\.nuget\packages\system.valuetuple\4.5.0\lib\net47\System.ValueTuple.dll' because AssemblyVersion '4.0.3.0' is greater than '4.0.2.0'.
1> Unified primary reference "System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51".
1> Using this version instead of original version "4.0.2.0" in "C:\Users\Me\.nuget\packages\system.text.json\4.6.0\lib\net461\System.Text.Json.dll" because AutoUnify is 'true'.
1> Resolved file path is "C:\Users\Me\.nuget\packages\system.valuetuple\4.5.0\ref\net47\System.ValueTuple.dll".
1> Reference found at search path location "{RawFileName}".
1> This reference is not "CopyLocal" because at least one source item had "Private" set to "false" and no source items had "Private" set to "true".
1> The ImageRuntimeVersion for this reference is "v4.0.30319".
I haven't done anything other than creating a project, converting to PackageReference, adding a class library, and adding a reference to that library. I haven't made any other changes at all. I haven't even added any new NuGet packages, so everything should be as clean as it can be. Yet I get these warnings!
If I create an identical solution without converting to PackageReference the warnings are never displayed, so it obviously has something to do with PackageReference, but what/why/how?
So why do these warnings appear in a "clean" solution? Is there anything I can do to make them disappear without having to add remappings in the web.config file?
Download a demo solution with the issue

Updating to last version of the monodroid and now the solution not builds

Today I update my monodroid to the its last version. Before this my solution works fine but no I got this errors:
MyProjectPath\Classes\Presentation Layer\Class Override\ImageLoaderListener.cs(15,15): Error CS0012: The type 'Java.Lang.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=c4c4237547e4b6cd'. (CS0012) (RPLAndroidApp)
and also this:
MyProjectPath\Class Override\ImageLoaderListener.cs(15,15): Error CS0012: The type 'Android.Runtime.IJavaObject' is defined in an assembly that is not referenced. You must add a reference to assembly 'Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=c4c4237547e4b6cd'. (CS0012) (RPLAndroidApp)
I tried to recompile my java library that I build by 'JavaBindingLibraryProject' and add them again to project but When I build them I get many errors.
I'm confused what should I do?
Rebuild all your projects with the new version of Mono for Android. You have to do this because of the changes in Assembly strongnames.

F# compile code at runtime ends in missing assemblies

I have a question related to the code provided in an answer to this question.
The problem I have is that the three referenced assmeblies (System.dll, FSharp.Core.dll, FSharp.Powerpack.dll) that are passed to CompilerParameters are not found at runtime. The error I get is:
unknown-file(0,0) : error 0: error FS0218: Unable to read assembly
'c:\user s\utente\documents\visual studio
2010\Projects\TrashSolution\TrashSolution\bin\D ebug\FSharp.Core.dll'
How do I tell the compiler to search for these assemblies in the GAC, instead of the project's bin directory? If I open a namespace in the code provided as a string, how do I know which assemblies to add? Where can I get this information?
In the code from the answer you linked, there's a line towards the bottom:
let asm = Reflection.Assembly.LoadFrom(fileinfo.Value.FullName)
If you call Reflection.Load instead and pass it the fully-qualified assembly name, it'll try to load the assembly from the GAC (and a few other places, if the assembly isn't in the GAC).
let asm =
Assembly.Load "SampleAssembly, Version=1.0.2004.0, Culture=neutral, PublicKeyToken=8744b20f8da049e3"
If you don't know the fully-qualified assembly name you have to create an AssemblyName with the simple name of the assembly, then call the Reflection.Load overload which takes an AssemblyName instead of a string.
let asmName = AssemblyName "Your.Assembly.Name"
let asm = Assembly.Load asmName
As far as knowing which assemblies to load -- I don't think there's a simple way to determine that programmatically. The only two solutions I can think of right now:
If you have some knowledge about the code you're being given (as a string), you could parse it with the FSharpCodeProvider and look at which namespaces/modules are opened and which types are used. If you're looking to see if some particular namespace or type is used (i.e., that you would need to include an assembly reference for when compiling the code), you could create a Map (in your .fsx which is doing the compilation) of namespaces and/or type names to assembly names and use it to reference the appropriate assemblies.
You could "brute-force" search the GAC, by using the semi-documented Fusion API to enumerate all of the assemblies installed in the GAC, then using Reflection to examine each assembly and determine if it's one you require. This is likely to be extremely slow, so I'd avoid it at all costs. If you do decide to go this route, you must also use the Assembly.ReflectionOnlyLoad method to load the assemblies! This allows the assemblies to be unloaded after you finish examining them -- if you use normal Reflection the assemblies can't be unloaded and your program will likely crash with an OutOfMemoryException or similar.
EDIT: Turns out that loading the assembly by its simple name succeeds in fsi and not in normal F# code because fsi automatically installs a handler for the AppDomain.AssemblyResolve event. This event is triggered by the CLR when you try to load an assembly and it can't be resolved; the event provides a way for you to "manually" resolve the assembly and/or generate an assembly dynamically and return it.
If you look at the FileNotFoundException raised when you try to run the code in an F# project, you'll see something like this in the Fusion Log property of the exception:
=== Pre-bind state information ===
LOG: User = Jack-Laptop\Jack
LOG: DisplayName = System
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: System | Domain ID: 1
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Users/Jack/Documents/Visual Studio 2010/Projects/StackOverflow1/StackOverflow1/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : StackOverflow1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Users/Jack/Documents/Visual Studio 2010/Projects/StackOverflow1/StackOverflow1/bin/Debug/System.DLL.
LOG: Attempting download of new URL file:///C:/Users/Jack/Documents/Visual Studio 2010/Projects/StackOverflow1/StackOverflow1/bin/Debug/System/System.DLL.
LOG: Attempting download of new URL file:///C:/Users/Jack/Documents/Visual Studio 2010/Projects/StackOverflow1/StackOverflow1/bin/Debug/System.EXE.
LOG: Attempting download of new URL file:///C:/Users/Jack/Documents/Visual Studio 2010/Projects/StackOverflow1/StackOverflow1/bin/Debug/System/System.EXE.
Looking towards the bottom of that log, you'll see where the CLR searched for the assembly before it gave up.
Here's a simple handler to give you an idea of how to use the AppDomain.AssemblyResolve handler to manually resolve the assembly. (NOTE: The handler needs to be added before the code that attempts to load the assembly!)
System.AppDomain.CurrentDomain.add_AssemblyResolve (
System.ResolveEventHandler (fun _ args ->
let resolvedAssembly =
System.AppDomain.CurrentDomain.GetAssemblies ()
|> Array.tryFind (fun loadedAssembly ->
// If this assembly has the same name as the one we're looking for,
// assume it's correct and load it. NOTE : It may not be the _exact_
// assembly we're looking for -- then you'll need to adjust the critera below.
args.Name = loadedAssembly.FullName
|| args.Name = loadedAssembly.GetName().Name)
// Return null if the assembly couldn't be resolved.
defaultArg resolvedAssembly null))
If you add that code to a new F# console project, followed by the code which uses AssemblyName with Assembly.Load, you should be able to load the System assembly because it's referenced by default in an F# project and it'll be loaded when you run the project. If you try to resolve System.Drawing, it'll fail because our custom event handler can't find the assembly. Obviously, if you need some more complicated assembly-resolving logic, you should build that into the event handler in whatever way makes sense for your application.
Finally, here's a link to the MSDN whitepaper mentioned in the exception message: Best Practices for Assembly Loading. It's worth a read if you get stuck and can't figure out how to resolve the assemblies you need.

"A type load exception has occurred." using DbContext with MySql connector with Mono

I am trying to use the MySQL Database with the Entity Framework Version 4.1.0.0 and Mono 2.11.4 in a ASP.NET MVC 3 Project.
On my Local Windows system everything works great but when I publish it to my Ubuntu 12.04 LTS System I get a lot of errors.
First I get:
Could not load type 'System.Data.Entity.Infrastructure.DbUpdateException' from assembly 'EntityFramework, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
when I press F5 I get different errors every time the page refreshes:
Could not load type 'System.Data.Entity.Infrastructure.DbUpdateConcurrencyException' from assembly 'EntityFramework, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Could not load type 'System.Data.Entity.Infrastructure.DbCompiledModel' from assembly 'EntityFramework, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Could not load type 'System.Data.Entity.Infrastructure.ReplacementDbQueryWrapper`1[TElement]' from assembly 'EntityFramework, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Could not load type 'MySql.Data.VisualStudio.Editors.SqlEditor' from assembly 'MySql.VisualStudio, Version=6.6.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d'.
Could not load type 'MySql.Data.VisualStudio.WebConfig.WebConfigDlg' from assembly 'MySql.VisualStudio, Version=6.6.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d'.
A type load exception has occurred.
The last error occurred when I try to use the database with this code:
using (var db = new DefaultContext())
{
db.Persons.Add(new Person() { Name = "hallo", Address = "bllaaa" });
db.SaveChanges();
var persons = db.Persons.ToList();
return View(persons);
}
Did anybody have a similar problem and solved it? I do not know what to do.
P.S.: I use Code First Migration
From my understanding, Mono is bundling the open source version of Entity Framework, which is essentially yet-to-be-released v6.
http://weblogs.asp.net/scottgu/archive/2012/07/19/entity-framework-and-open-source.aspx
So it would seem you can't target EF v4.x, since the code has likely undergone major changes. Although, if you discover that the seemingly missing types are still there, you could attempt to work around the issue with an assembly redirect (just search for bindingRedirect).
I know why this happend.
I installed the mono-fastcgi-server4 through apt-get after i installed mono from source. So i had 2 mono versions installed and the older one was active. (2.10.8)
And the Entity Framework seems totally useless to me because only the new EF6 works with a database but there arent any provider who suppot EF6 and work with mono.

MvcContrib.FluentHtml.ModelWebViewPage and ASP.NET MVC4

Just trying to get work mvc4 with mvccontrib
I set base page in web.config (the same way i did in my mvc3 projects)
<pages pageBaseType="MvcContrib.FluentHtml.ModelWebViewPage">
But in run time i get an error:
Server Error in '/' Application.
--------------------------------------------------------------------------------
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0305: Using the generic type 'MvcContrib.FluentHtml.ModelWebViewPage<T>' requires 1 type arguments
Source Error:
Line 32:
Line 33:
Line 34: public class _Page_Views_Home_Index_cshtml : MvcContrib.FluentHtml.ModelWebViewPage {
Line 35:
Line 36: #line hidden
Source File: c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\17698293\b6166ab6\App_Web_index.cshtml.a8d08dba.e7moq-gi.0.cs Line: 34
May be some one may help with that? Any thoughts?
UPDATE:
Looks like the problem is:
If i set custom base class <pages pageBaseType="MvcContrib.FluentHtml.ModelWebViewPage"> and if view does not have any custom model on it in such case i am getting that error. So in such case i just need to set model in the view to #model dynamic and it would work and than failed again, so i just change basePageType to its default and use MvcContrib.FluentHtml.ModelWebViewPage<dynamic> and MvcContrib.FluentHtml.ModelWebViewPage<MyModel> until it will be fixed in the next MvcContrib/MVC 4 versions.
The issue is MvcContrib.FluentHtml.ModelWebViewPage does not exist, there is only MvcContrib.FluentHtml.ModelWebViewPage<T>. If you don't have a model class, you could do MvcContrib.FluentHtml.ModelWebViewPage<dynamic>.
All that said, I have no idea of MVC Contrib will work with MVC4, typically one needs to at least recompile things against the new MVC version . . . .

Resources