-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FileNotFoundException (System.Runtime, Version=4.2.1.0) when reflecting in T4 template #2000
Comments
@karelz - this looks like an issue with running the VS Text Templating Engine (T4), not specific to ASP.NET Core. It could be that reporting this issue through VS's built-in "Report a Problem" tool is the best avenue for this issue. |
Thanks @Eilon, I incorrectly thought it was part of ASP.NET (I just saw the name T4 once before). |
@BasPaap Have you found any work around for this issue? |
@richimori I haven't found a workaround, unfortunately. I reported the problem via the Visual Studio feedback tool where it has been Triaged, but no further updates. You can vote on it here if you like: https://developercommunity.visualstudio.com/content/problem/358905/filenotfoundexception-systemruntime-version4210-wh.html |
Having the same issue. Using T4 Templates in a Netcore 2.1 Unit Tests project. Getting the following error: Severity Code Description Project File Line Suppression State WRN: Assembly binding logging is turned OFF. |
Also having this issue |
Just a reminder that this is closed issue, not monitored or used for +1 votes. The main issue is tracked on VS Developer Community - see link above. |
Maybe it's because we have a .net core assembly calling a .net framework assembly. The assembly
|
Maybe some |
It works!!! Just put this bindingRedirect inside the
|
Why, exactly, does this work? From the redirect, it looks like it's telling the runtime to use System.Runtime 4.0.0.0 instead of 4.2.1.0, but why can it find 4.0.0.0 and not 4.2.1.0? |
This solution isn't working for me, but it's probably because I'm using .NET Core 3.0? |
As of VS 16.3.9, you have to edit the file in this folder (16.0_6b4c9109):
and then restart VS. This did the trick for me 🤩 I'm also on .NET Core 3.0. |
For me the problem was that T4 model generator uses Framework 4.8.4075.0.
I was trying to add a reference to a .Net Core library and I got the error. |
I'm using .NET Core 3.1 and had this same issue. The binding redirect worked at first, but then the assembly I was referencing added a reference to another .NET Core assembly and it stopped working. I decided to develop an alternative T4 tool that uses a hybrid of Visual Studio's .NET Framework T4 capabilities for preprocessing and a .NET Core executable to execute the template code. I'm not sure how well it works with 3.0, but it works well for my 3.1 project and hopefully it can help some others too. It's available on GitHub. |
Hi @filippobottega, can you please provide your changed code. I am running into the same issue, and cannot figure out the fix. Thank you very much. |
Hi @pvchandu , I don't have any code, I have only changed the project type of the library that I need to reference in T4 model. If you have the source code of the library, you have to create a new project in Visual Studio using Standard Library and you have to copy your code into this new project. Than you can reference this new project into your T4 template. |
I had the same error. However, my projects are setup as dual build (i.e. both net471 and .netcore20). This is a common library, so referencing a project is problematic in two ways: 1. it is a common project used across multiple applications 2. if you create a branch to make changes, you now have to update the projects that reference this project in a completely different location just test. Resolution: Made sure that my .net471 references referenced the .net471 common library and the .netcore20, referenced the library built as .netcore20. I had them mixed. |
Doesn't work with net8, I tried everything but it doesn't. |
General
I have a .NET Core 2.1 ASP.NET MVC application in which I have a design time T4 template which I want to use to generate some code. Currently, it looks like this:
This works: the .txt file generated by this template contains "String".
However, now I have a class Foo in Foo.cs in the same folder as my template:
Now I want to use Foo instead of string, so I just change the line
var myType = typeof(string);
to
var myType = typeof(Foo);
and save the template. Now I get an error:
With the following stack trace:
Why does it throw this error? Why does reflection work for the built-in string type, but somehow depend on .NET Framework 4.2.1 for my own .NET Core 2.1 type?
The text was updated successfully, but these errors were encountered: