Nancy doesn't find system.xml - razor

I have a Nancy view with a using statement:
#using System.Xml
#{ //code
}
<!-- rest of page -->
System.Xml is referenced in my project.
When I try to run the app I get a Razor Compilation Error:
Error compiling template: Views/index.cshtml
Errors:
[CS0234] Line: 1 Column: 18 - The type or namespace name 'Xml' does not exist in the namespace 'System' (are you missing an assembly reference?) (show)
Details:
#using System.Xml
Other namespaces, e.g. System.Web also fail in the same way, even though they are included in the project.
Ideas?

This looks like a classic case of not configuring razor.
https://github.com/NancyFx/Nancy/wiki/Razor-View-Engine#configuring-razor

Related

VS 2022 c# 'type or namespace name 'DllExport' could not be found'

This is from a c# dll from GitHub that is in use by many people so it should compile but this line
[DllExport(CallingConvention.StdCall)]
gives these errors
Error CS0246 The type or namespace name 'DllExport' could not be found (are you missing a using directive or an assembly reference?)
Error CS0246 The type or namespace name 'DllExportAttribute' could not be found (are you missing a using directive or an assembly reference?)
That is the only line in the code with an error.
using System;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Windows.Services.Store;
...
[DllExport(CallingConvention.StdCall)]
...
From what I have gathered with your specific line of code there
[DllExport(CallingConvention.StdCall)]
DllExport is a function from the UnmanagedExports library, so you just need to add:
using RGiesecke.DllExport;

TagHelpers not working when assembly is dynamically loaded in ASP.NET core 2.1

I'm using ASP.NET core 2.1. I load all the assemblies that have the Views dynamically from a plugins folder. I use the following code for that. The Views get loaded correctly.
services.AddMvc().
AddRazorPagesOptions(o => o.AllowAreas = true).
SetCompatibilityVersion(CompatibilityVersion.Version_2_1).
ConfigureApplicationPartManager(ConfigureApplicationParts);
private void ConfigureApplicationParts(ApplicationPartManager apm)
{
var pluginsPath = Path.Combine(_env.WebRootPath, "Plugins");
var assemblyFiles = Directory.GetFiles(pluginsPath, "*.dll", SearchOption.AllDirectories);
foreach (var assemblyFile in assemblyFiles)
{
var assembly = Assembly.LoadFile(assemblyFile);
if (assemblyFile.EndsWith(".Views.dll"))
{
apm.ApplicationParts.Add(new CompiledRazorAssemblyPart(assembly));
}
else
{
apm.ApplicationParts.Add(new AssemblyPart(assembly));
}
}
}
The views have some custom taghelpers.
The _ViewImports.cshtml file looks like
#addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
#addTagHelper *, MyTagHelpers
The problem is that the custom tag helpers don't get loaded and gives an error:
Error: Could not load file or assembly MyTagHelpers
The reason I get the error may be the Razor View Engine may be looking for the DLL in the bin folder of the main app and it can't find the DLL and gives this error.
What should I do in the startup to say the taghelpers are available in a DLL and can be loaded from there? Should I use TagHelperFeatureProvider to do it?
UPDATE: I moved the tag helpers to a separate DLL called MyTagHelpers.Common and dropped in the plugins folder. I'm not getting any assembly not found error anymore, but the tag helpers are not working.
After 2 days trying to resolve this - please note - the 'assembly name' is the compiled (assembled?) .DLL name which would normally match the project name which may not match the namespace name/prefix!
So if your project name is not the same as the namespace as mine was, then the #addTagHelper reference is the project name which is being used to create the compiled .DLL - see your build output to check.
And therefore, this is also usually the same as the prefix for your .csproj file which is why the official documentation says to create a new app.

Error CS0234 in VS 2015 with build+intelliSense selected

When I open my mvc project (mvc5) with razor helper file in app_code folder, the compile was successful but in error list I have the error below:
Severity Code Description Project File Line Suppression State
Error CS0234 The type or namespace name 'global_asax' does not exist in the namespace 'ASP' (are you missing an assembly reference?)
The error only appear when the option "Build + IntelliSense" was selected, if I select "Build Only" the error won't show.
Can someone explain why this error occurs and how to eliminate this error? is this a bug in VS2015 since this issue does not occur in vs2013? should I be concerned with this error?
bty the error points to the code below
public RazorHelper() {
}
protected static ASP.global_asax ApplicationInstance {
get {
return ((ASP.global_asax)(Context.ApplicationInstance));
}
}

Changing namespace name of C++ component in Windows Phone causes exception

I have a C++ runtime component in a WP8 application, and if I change the namespace name, I get a "TargetInvocation" exception thrown whenever I try to instantiate a class in that namespace.
As an example, if I create the default C++ Windows Runtime Component, the header looks like this:
#pragma once
namespace CppComponent1
{
public ref class WindowsPhoneRuntimeComponent sealed
{
public:
WindowsPhoneRuntimeComponent();
};
}
If I change CppComponent1 to CppComponent2 in the .h and the .cpp, and then try to instantiate a WindowsPhoneRuntimeComponent object in my C# code, I get the following error:
A first chance exception of type 'System.TypeLoadException' occurred in Unknown Module.
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.ni.dll
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in Microsoft.Phone.ni.dll
How can I change the namespace of a native module in a WP8 app? Thanks!
The name of the Windows Metadata (WinMD) file that declares the component must be a prefix of the namespace in which the public types are declared. (I provided a slightly more detailed explanation of the namespace rules in an answer to another question.)
If you rename the namespace from CppComponent1 to CppComponent2, you also need to rename the WinMD file produced by the build from CppComponent1.winmd to CppComponent2.winmd.

method in Report Builder custom assembly not found

I'm trying to use a custom assembly in Report Builder 2.0. I have added the assembly to the report via Report Properties > References. When I try to call a public static method in the assembly, I get this message:
'ExtractTag' is not a member of 'ReportsClassLibrary.ReportsClassLibraryTools'.
The expression I'm trying to use to call the method is:
=ReportsClassLibrary.ReportsClassLibraryTools.ExtractTag("ID", "ID:incorrect", false)
And the method signature in the assembly is:
public static string ExtractTag(string tagToFind, string tags, bool caseSensitive)
That method is within the ReportsClassLibrary namespace and in the ReportsClassLibraryTools class.
I don't know if for some reason my report is looking an older version of the assembly that did not have this method, or if the problem is something else. I've tried removing the assembly from the report, rebuilding the assembly, and re-adding it to the report.
Edit: looks like a deeper problem. My assembly compiles, but when running a test case that calls that method, the test fails with a System.MissingMethodException. Guess I'm having an assembly problem, not a Report Builder problem...
Turned out it was a problem with the Global Assembly Cache in Vista. The old version of my assembly was cached, so the new method ExtractTag wasn't part of the assembly. I had to run:
"C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\gacutil.exe" /i bin\Debug\ReportsClassLibrary.dll