Ошибка could not load type

Rebuilding/re-publishing my project/solution to the server did nothing to help me, and I doubt that will help that many out of this predicament. For me, I did a few things to troubleshoot this that eventually got me out of this «hole».

I had been trying to use a binding on the web site, but this wasn’t working. I tried calling the site with http://localhost/Report.aspx (this was my homepage, which I opted to not call Default.aspx — I was going to update the «Default Documents» section with the name later) when I got the Parser Error the OP saw. So I tried some things:

I stopped the old project’s website and built another, simple web project, that had «hello» and a label on the page and nothing else. I had a line in the Page_Load to populate the label’s Text property with «world!», just to make sure that part was working. I created a new website on port 80 and transferred the published contents of my site to the server. So even though I had .NET 4.5 installed on the server (and had ran the aspnet_regiis -i command from the 4.0 directory) and the App Pool in IIS that I was using for this new project was set to 4.0, the browser complained about the web.config having a targetFramework=4.5.2 in it, which is Visual Studio 2015’s default framework. So I installed .NET 4.6 (NDP46-KB3045557-x86-x64-AllOS-ENU.exe), restarted the server, and then my simple site worked. So then I deleted this site — all I wanted to do was prove my installation steps were accurate and the server could run a site.

So then I went back to my original project/site — I deleted and re-created the web site. I put the Application Pool to the one I had originally created for this, which I ensured was running .NET 4.0. Once I did this, I navigated to my site and everything worked when using http://localhost/Report.aspx. So it seems to me what causes this is what version of the .NET Framework you are using.

User-1793215261 posted

Hello

I have now managed to install the following NuGet packages the absence of which may have been causing a problem with the Salt/Hash code I have:

«Microsoft.AspNet.Providers.LocalDB» version=»2.0.0″
«System.Web.Helpers.Crypto» version=»3.2.3″
«WebHelpers» version=»4.0.2″
«MarkdownSharp» version=»1.13.0.0″

The name of my Default project in the Package Manager Console is that of my project in Solution Explorer as, I understand, it should be.

When I click to load the page in my browser, I get a parser error: Parser Error: Could not load type ‘Dima.Index’.

The error refers to this line at the top of my home page:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="index.aspx.vb" Inherits="Dima.Index" %>

This is a line VS 2017 has inserted, not me, at the top of my page. My index.aspx.vb file, has this at the top:

Partial Class index
    Inherits System.Web.UI.Page

My other pages, such as register.aspx has this:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="register.aspx.vb" Inherits="Dima.register" %>

and this at the top of register.aspx.vb:

Partial Class register

Inherits System.Web.UI.Page

(‘register is green underlined because VS tells me I need a capital R).

How should this line

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="index.aspx.vb" Inherits="Dima.Index" %>

read, please?

Check that the codebehind class is

public partial class TestCert:Page
{

}

Also try changing CodeBehind=»TestCert.aspx.cs» to CodeFile=»TestCert.aspx.cs». This change is required when you change project type from website to webapplication or vice versa.

Since you are saying that the project does not contain the project file or solution file, I think the problem is here. The IIS is not able to understand the project type.

Since you are FTPing to IIS, are you sure that you are using the .NET 2.0 AppPool ?

I’m attempting to load types from a 4.72 framework project using the dotnet-typegen cli tool.

So, I guess my first question right off the bat is, can I do that? It worked for the first few .dlls I threw at it. And it was preferable to the older legacy package manager console tool, because then I could run it in my npm scripts.

Assuming I can use the dotnet-typegen tool for 4.72 projects, here’s my situation:

First, I had this in my tgconfig.json:

{
    "assemblies": [
        "./Res.Proposals.Api/bin/Local/net472/RES.Proposals.Api.dll",
        "./Res.Proposals.Api/bin/Local/net472/RES.Proposals.Domain.dll",
    ],
    "externalAssemblyPaths": [
        "./RES/bin/net472/RES.dll"
    ],
    "enumStringInitializers": true,
    "outputPath": "./RES.Web/frontend/src/types",
    "singleQuotes": true,
    "propertyNameConverters": [],
    "filenameConverters": [],
    "clearOutputDirectory": true
}

I run dotnet-typegen generate and everything worked great, I got this output:

Generated [x].ts
Generated [y].ts
Generated [z].ts
...yada yada and then...
Files for project "." generated successfully.

Boom, everything was great. But then I actually wanted to add an enum from our core library, so I added a single TSExportEnum attribute and I moved the dll from externalAssemblyPath to my assemblies list, like so:

{
    "assemblies": [
        "./Res.Proposals.Api/bin/Local/net472/RES.Proposals.Api.dll",
        "./Res.Proposals.Api/bin/Local/net472/RES.Proposals.Domain.dll",
        "./RES/bin/net472/RES.dll"
    ],
    "enumStringInitializers": true,
    "outputPath": "./RES.Web/frontend/src/types",
    "singleQuotes": true,
    "propertyNameConverters": [],
    "filenameConverters": [],
    "clearOutputDirectory": true
}

And suddenly we got problems.

Could not resolve assembly: System.Configuration.ConfigurationManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 in any of the searched directories: C:Usersapv.nugetpackages; C:Program Filesdotnetsdk/NuGetFallbackFolder; C:Program Filesdotnetshared
Could not resolve assembly: System.Configuration.ConfigurationManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 in any of the searched directories: C:Usersapv.nugetpackages; C:Program Filesdotnetsdk/NuGetFallbackFolder; C:Program Filesdotnetshared
Could not resolve assembly: System.Configuration.ConfigurationManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 in any of the searched directories: C:Usersapv.nugetpackages; C:Program Filesdotnetsdk/NuGetFallbackFolder; C:Program Filesdotnetshared
Could not resolve assembly: System.Configuration.ConfigurationManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 in any of the searched directories: C:Usersapv.nugetpackages; C:Program Filesdotnetsdk/NuGetFallbackFolder; C:Program Filesdotnetshared
Could not resolve assembly: System.Configuration.ConfigurationManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 in any of the searched directories: C:Usersapv.nugetpackages; C:Program Filesdotnetsdk/NuGetFallbackFolder; C:Program Filesdotnetshared
Could not resolve assembly: System.Data.SqlClient, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a in any of the searched directories: C:Usersapv.nugetpackages; C:Program Filesdotnetsdk/NuGetFallbackFolder; C:Program Filesdotnetshared
Could not resolve assembly: System.Data.SqlClient, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a in any of the searched directories: C:Usersapv.nugetpackages; C:Program Filesdotnetsdk/NuGetFallbackFolder; C:Program Filesdotnetshared
Could not resolve assembly: System.Data.SqlClient, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a in any of the searched directories: C:Usersapv.nugetpackages; C:Program Filesdotnetsdk/NuGetFallbackFolder; C:Program Filesdotnetshared
Could not resolve assembly: System.Configuration.ConfigurationManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 in any of the searched directories: C:Usersapv.nugetpackages; C:Program Filesdotnetsdk/NuGetFallbackFolder; C:Program Filesdotnetshared
Could not resolve assembly: System.Configuration.ConfigurationManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 in any of the searched directories: C:Usersapv.nugetpackages; C:Program Filesdotnetsdk/NuGetFallbackFolder; C:Program Filesdotnetshared
GENERIC ERROR: Could not load type 'System.ServiceModel.ServiceContractAttribute' from assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
   at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
   at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
   at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
   at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType
attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes)
   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit)
   at System.Attribute.GetCustomAttributes(MemberInfo element, Type type, Boolean inherit)
   at System.Attribute.GetCustomAttribute(MemberInfo element, Type attributeType, Boolean inherit)
   at System.Reflection.CustomAttributeExtensions.GetCustomAttribute[T](MemberInfo element)
   at TypeGen.Core.Extensions.TypeExtensions.HasExportAttribute(Type type, IMetadataReader reader) in D:Google DriveProjectstype-gensrcTypeGenTypeGen.CoreExtensionsTypeExtensions.cs:line 26
   at System.Linq.Utilities.<>c__DisplayClass1_0`1.<CombinePredicates>b__0(TSource x)
   at System.Linq.Enumerable.WhereArrayIterator`1.MoveNext()
   at TypeGen.Core.Generator.Services.GenerationSpecProvider.GetGenerationSpec(IEnumerable`1 assemblies) in D:Google DriveProjectstype-gensrcTypeGenTypeGen.CoreGeneratorServicesGenerationSpecProvider.cs:line 28
   at TypeGen.Core.Generator.Generator.Generate(IEnumerable`1 assemblies) in D:Google DriveProjectstype-gensrcTypeGenTypeGen.CoreGeneratorGenerator.cs:line 305
   at TypeGen.Cli.Program.Generate(String projectFolder, String configPath) in D:Google DriveProjectstype-gensrcTypeGenTypeGen.CliProgram.cs:line 137
   at TypeGen.Cli.Program.Main(String[] args) in D:Google DriveProjectstype-gensrcTypeGenTypeGen.CliProgram.cs:line 70

I don’t know why it’s trying to resolve all of those Version=0.0.0.0 packages, first of all. I searched my solution for them, and I can’t find any such dependency. I even have the following reference in my .csproj

<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" />

The biggest problem is the final error, which totally kills the script though. could not load type. That System.ServiceModel.ServiceContract is building just fine, so I don’t know why the typegen script is choking on it 🤷‍♂

Error Description:

Parser Error Description: An error occurred during the parsing of a resource required to service this request.

  • Parser Error Message: Could not load type ‘TestMvcApplication.MvcApplication’.
  • Source Error:
    1. Line 1: <%@ Application Codebehind=»Global.asax.cs» Inherits=»TestMvcApplication.MvcApplication» Language=»C#» %>
    2. Source File: /global.asax Line: 1

Solution 1:

  • Running the project from Visual Studio works fine. This is the source code from Global.asax:
namespace WebApplication5
{
    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
    }
}

click below button to copy the code. By — .Net tutorial — team
  • This leads us to believe that we might not have something install or some configuration is not correct that IIS sets globally.Here is what steps we followed for a new web application in Visual Studio 2015:
  1. File -> New Project -> ASP.NET Web Application -7gt; MVC
  2. Runed the project on visual studio it works with the default templates
  3. On IIS we created a new website and in that website we created a new web application which is mapped to the folder of the project.
  • we created an application pool for the newly created project inside the website that has the following configuration.
    • .NET CLR versions is set to .NET CLR Version v4.0.30319
    • Managed Pipeline is set to integrated

After doing all this we tried the following to fix the issue:

  • Clean and Rebuild for Visual Studio
  • Restart Visual Studio Clean Rebuild an PC Reset Clean rebuild
  • we made sure that the project adds its assemblies in the bin folder
  • we made sure that in Solution ->Properties -> Configuration Properties the proejct is set to debug
  • we made sure that the namspace in Global.asax xml file points to the correct type in Global.asax.cs

Solution 2:

  • We had this a couple of times and the error message holds no clue as to what might be the issue.
  • To fix this, right click our project title, in this case «TestMvcApplication» and click build.
  • This forces the code to compile before we run it. this has been the solution 100% of the time for all.

Solution 3:

Here’s another one:

  • We had been working on a web api project that was using localhost:12345.
  • We checked out a different branch from source control containing the same project.
  • We ran the project on the branch and got the error.
  • we went to «Properties > Web > Project Url» and clicked «Create Virtual Directory»
  • A dialog came up telling me that the url was mapped to a different directory (the directory for the original project).
  • we clicked Okay and the virtual directory was remapped.
  • The error went away.

Solution 4:

  • We need to read the Python Unicode HOWTO. This error is the very first example.
  • Basically, stop using str to convert from unicode to encoded text / bytes.
  • Instead, properly use .encode() to encode the string:
p.agent_info = u' '.join((agent_contact, agent_telno)).encode('utf-8').strip()
click below button to copy the code. By — .Net tutorial — team

or work entirely in unicode.

Solution 5:

This is a classic python unicode pain point! Consider the following:

a = u'batsu00E0'
print a
 => batsà
click below button to copy the code. By — .Net tutorial — team

All good so far, but if we call str(a), let’s see what happens:

str(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'xe0' in position 4: ordinal not in range(128)
click below button to copy the code. By — .Net tutorial — team

To fix the error, encode the bytes explicitly with .encode and tell python what codec to use:

a.encode('utf-8')
 => 'batsxc3xa0'
print a.encode('utf-8')
 => batsà
click below button to copy the code. By — .Net tutorial — team
  • The issue is that when we call str(), python uses the default character encoding to try and encode the bytes we gave it, which in our case are sometimes representations of unicode characters.
  • To fix the problem, we have to tell python how to deal with the string we give it by using .encode(‘whatever_unicode’).
  • Most of the time, we should be fine using utf-8.

 server error in app

Learn dotnet — dotnet tutorial — server error in app — dotnet examples — dotnet programs

Возможно, вам также будет интересно:

  • Ошибка could not open disk
  • Ошибка could not load tls libraries
  • Ошибка could not load plugin
  • Ошибка could not load module
  • Ошибка could not load library что это

  • Понравилась статья? Поделить с друзьями:
    0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии