code

'동적 표현식을 컴파일하는 데 필요한 하나 이상의 유형을 찾을 수 없습니다.'라는 메시지가 표시되는 이유는 무엇입니까?

codestyles 2020. 11. 29. 11:44
반응형

'동적 표현식을 컴파일하는 데 필요한 하나 이상의 유형을 찾을 수 없습니다.'라는 메시지가 표시되는 이유는 무엇입니까?


업데이트 한 프로젝트가 있습니다.

  • .NET 3.5 MVC v2 ~
  • .NET 4.0 MVC v3

컴파일 할 때 @ViewBag.Title속성 을 사용하거나 설정하려고하면 오류가 발생 합니다.

동적 표현식을 컴파일하는 데 필요한 하나 이상의 유형을 찾을 수 없습니다. Microsoft.CSharp.dll 및 System.Core.dll에 대한 참조가 누락 되었습니까?

나는 다음을했다

  1. 업그레이드 단계를 따랐습니다.
  2. Project / Properties / Application 탭에서 대상 프레임 워크를 .NET Framwework 4로 설정합니다.
  3. System.Core 프레임 워크를 수동으로 추가했습니다.
  4. Microsoft.CSharp 프레임 워크 추가
  5. System.Xml 프레임 워크 추가
  6. System.Xml.Linq 프레임 워크 추가
  7. Web.Config 가 올바른지 확인 했습니다 (Web.Debug.Config 등에 의해 덮어 쓰기 됨).
  8. 생성 된 모델 , 컨트롤러 와 면도기 보기
  9. __Layout.cshtml_ 만들기

다른 무엇을해야할지 모르겠습니다.

편집하다:

GAC Gui에는 System.Core 3.5.0.0이 있지만 System.Core 4.0.0.0은 없습니다. 이것은 혼란스러워지고 여전히 이전 버전을 사용하고 있음을 의미합니까? 아니면 GAC를 오해하고 있습니까?

편집하다:

내 web.config는 다음과 같습니다.

...
<compilation debug="true">
    <assemblies>
        <add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
    </assemblies>
</compilation>
....
<pages>
    <controls>
    <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</controls>
<namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.WebPages"/>
    <add namespace="System.Web.Mvc" />
    <add namespace="System.Web.Mvc.Ajax" />
    <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
    <add namespace="System.Linq" />
    <add namespace="System.Collections.Generic" />
</namespaces>
</pages>
....

가치있는 일이 발생했을 때 (MVC2에서 MVC3로 자동 변환되는 프로젝트에서) Microsoft.CSharp에 대한 프로젝트 참조를 추가하기 만하면되었습니다. 제 경우에는 web.config에 이미 여기에 언급 된 4.0 참조가 포함되어 있으므로 업그레이드 스크립트를 사용한다고 가정합니다.


좋습니다. 다음 단계로 작업했습니다.

  1. 구성 파일 에서 system.web 섹션에서 변경 <compilation debug="true">했습니다 <compilation debug="true" targetFramework="4.0">.
  2. 구성 파일 에서 컴파일러 섹션에서 변경 <providerOption name="CompilerVersion" value="v3.5" />했습니다 <providerOption name="CompilerVersion" value="v4.0" />.
  3. Global.asax.cs ViewEngines.Engines.Add(new RazorViewEngine());에서 Application_Start()메서드에 추가 했습니다.

그게 전부라고 생각합니다.


Microsoft.CSharp.dll 버전-v4.0.30319에 대한 참조를 프로젝트에 추가해야합니다. VS 2010을 설치 한 후 C : \ Program Files \ Reference Assemblies \ Microsoft \ Framework \ .NETFramework \ v4.0 \ Microsoft.CSharp.dll에서 사용할 수 있습니다.


나를 위해 해결책은 다음을 추가하는 것이 었습니다.

ViewEngines.Engines.Add(new RazorViewEngine());

받는 Application_Start()메소드 global.asax.cs.


web.config에서 System.Core 3.5를 가져 오는 것 같습니다. ViewBag에는 System.Dynamic 네임 스페이스가 필요하므로 4.0 프레임 워크에서 System.Core를 가져와야합니다.

내 컴퓨터에서는 System.Core v4.0.30319처럼 보입니다.


다음과 같은 방법으로 해결했습니다.

먼저 gacutil (Global Assembly Cache Utility)을 사용하여 System.Core에 대한 두 개의 참조, 즉 버전 4.0에 대한 참조와 버전 3.5에 대한 참조가 포함되어 있음을 확인했습니다. 분명히 면도기 뷰 내부에서 프로젝트에서 버전 4.0에 대한 올바른 참조가 있더라도 여전히 버전 3.5를 사용하고 있었기 때문에 동적 유형에 대한 오류가 발생했습니다. 이것이 귀하의 경우인지 확인하려면 관리자 Visual Studio 명령 프롬프트로 열고 실행하십시오.

gacutil -l System.Core

이전 버전의 System.Core에 대한 참조를 제거하려면 다음 단계를 수행했습니다.

- cd %systemroot%\assembly\

여기에서 "gac"디렉토리가 하나 이상있을 수 있으므로 구성 요소를 찾으려면 각 디렉토리를 검색해야합니다. 저에게는 "gac_MSIL"디렉토리에있었습니다.

- cd gac_msil
- cd System.Core
- cd <assembly version number>__<public key token>
- erase *.* Say "y" to are you sure.
- cd ..
- rd <assembly version number>__<public key token>
- cd ..
- rd System.Core

이제 Visual Studion에서 솔루션을 다시 열었고 오류가 사라지고 System.Core 4.0을 올바르게 참조하고 더 이상 동적 오류가 발생하지 않습니다. :)

도움이 되었으면 좋겠어요, Best, N.


이것이 내 결심이었습니다.

1) 프로젝트 참조로 이동

2) Microsoft.CSharp-> 속성을 ​​마우스 오른쪽 버튼으로 클릭하십시오.

3) True로 설정 한 경우 Copy Local을 False로 변경합니다.


MVC보기에 해당 메시지가 표시되면 다음과 같이 Views \ web.config에 참조를 추가해야합니다.

<system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        (... other references ...)
        <add namespace="Microsoft.CSharp" />  <-- Add this
        (...)
      </namespaces>
    </pages>
  </system.web.webPages.razor>

빌드하는 것을 잊지 마십시오. 그렇지 않으면 변경 사항이 적용되지 않습니다.


A default project in Visual Studio 2010 should have references to Microsoft.CSharp and System.Core.

If they are not referenced in your project you need to add them, and the errors will go away.


Woow!

I am almost a year late but still think I should answer based on my findings (on July 13, 2013 at 7:15p PST) related to the error message. This might be helpful for the guys who are looking for the answer to the error message:

"One or more types required to compile a dynamic expression cannot be found."

so please read on: I had the similar error message when I implemented System.Dynamic in my code. The Web application runs smoothly as I had the correct configuration in web.config (targetframework) but when I put the app_code in a separate dll then it started to throw errors at compile time. Please note that I did not have app.config in my dll so it may NOT be dependent on configuration when you have it in a separate dll project but the reference to the correct dll.

I figured correct Microsoft.CSharp.dll was in "C:\Windows\Microsoft.NET\Framework\v4.0.30319", and my dll compiled successfully.


For me non of the above worked, instead setting Copy Local = True solved the issue


I had this problem when I updated the MVC version in my project. The problem was the assemblyBinding directive, somehow Nuget forgot to update it.

I had to change

  <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
  </dependentAssembly>

to

  <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
  </dependentAssembly>

I received this error for a windows app while using Microsoft.Office.Interop.Excel;...... runtime versions do not seem to be compatible between one or more DLLs.

MY SOLUTION: I converted my entire solution from .NET 4.0 to .NET 3.5

for the hell of it I converted back to 4.0 and I started receiving the error again.

based on this for your error try converted your solution to an older .NET framework that could work.

========== EDIT =================

2 hours later I finish up some key things in my Excell interop class and it works like a charm...for some reason only on .NET 3.5 and not 4.0 my solution is valid to this extent


None of the above worked for me. With more searching and looking through the Web.Config settings, I found this answer worked for me.

How do I fix the "compilerVersion" IIS error?


I had something very similar happen to me, although in my case I had upgraded a number of things including from Visual Studio 2010 up to Visual Studio 2012. I'd followed everyone of the above suggestions and still was suffering. In the end I decided to re-create the entire project. It was only when I tried to re-add the membership provider aspects to my web.config file that it suddenly became obvious where the versioning clash was for me.

<sessionState mode="InProc" customProvider="DefaultSessionProvider">
  <providers>
    <clear/>
    <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/AppName"/>
  </providers>
</sessionState>

Although looking at it now, its obvious. The type for the provide has a specific version. I simple then removed the version and the appropriate type is found. The resolution therefore in my case was to replace the above with:

<sessionState mode="InProc" customProvider="DefaultSessionProvider">
  <providers>
    <clear/>
    <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers" connectionStringName="DefaultConnection" applicationName="/AppName"/>
  </providers>
</sessionState>

And then re-compile. It has taken me days to find this, as I was looking in all the wrong places!


I tried all the other suggestions in this file and none worked on my existing MVC 4 solution. So after updating my VS2012 to WebTools 2013.1 for VS 2012, I created a new MVC 5 project and using the new project's files as a base, removed all extraneous lines from all my web.config files.

After doing that all my compilation errors and warnings disappeared and Intellisense started working correctly. Completely removing the <system.web><pages> section in the main web.config file finally fixed the ViewBag.Title (and other) dynamic expression errors.


As I recently found out, some extensions can also cause this. In my case removing AutoHistory 1.0.1 extension fixed it for me (MVC5).


One common cause of this problem is that you've missed updating an Assembly version in your Views/web.config file. It's pretty easy for me to miss them in <system.web><pages> for instance:

<pages
    validateRequest="false"
    pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
    pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
    userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

I've been struggling with this issue also for a day or so. After I finally found this article here and tried all the suggestions here I came to another solution that solved the Problem for me:

It's just the opposite as Arman Bimatov has found:

1) Go to References of the project

2) Right click on the Microsoft.CSharp -> Properties

3) Change the Copy Local to True if you have it to False.

I think it must deal somehow with the assemblies registered in GAC and the way Visual Studio gets the "right" Version. I guess on my developer machine somehow the .NET Framework 3.5 was installed after the newer Frameworks (if this is possible at all), so Visual Studio gets the wrong Version from GAC. Or simpply it is unclear for VS to get which Version, so it takes the older one...

If you still have same error message you can also try to set the Copy Local to True for the System.Core Dll and have a look it works now.

Regards SkippingAdi


I've been struggling with this issue for days and finally figured it out.

All I did was remove the following from the web.config:

<dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31BF3856AD364E35" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Razor" publicKeyToken="31BF3856AD364E35" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
      </dependentAssembly>

I start getting the same error after I installed MVCSiteMapProvider package to make breadcrumbs for my site.

If you've installed MVCSiteMapProvider and you get this error you need to replace @ViewBag.Title by something else, for example, @Html.MvcSiteMap().SiteMapTitle()

참고URL : https://stackoverflow.com/questions/7115055/why-am-i-getting-one-or-more-types-required-to-compile-a-dynamic-expression-can

반응형